in taverna-perspective-myexperiment/src/main/java/org/apache/taverna/ui/perspectives/myexperiment/MyStuffContributionsPanel.java [199:360]
private void initialiseData() {
// Make call to myExperiment API in a different thread
// (then use SwingUtilities.invokeLater to update the UI when ready).
new Thread("Loading data about contributions of current user.") {
@SuppressWarnings("unchecked")
public void run() {
logger.debug("Loading contributions data for current user");
try {
final ArrayList<Workflow> alWorkflowInstances = new ArrayList<Workflow>();
if (alVisiblePanels.contains(jpMyWorkflows)) {
boolean anyMore = true;
for (int page = 1; anyMore; page++) {
// fetch all user workflows
Document doc = myExperimentClient.getUserContributions(myExperimentClient.getCurrentUser(), Resource.WORKFLOW, Resource.REQUEST_SHORT_LISTING, page);
if (doc != null) {
List<Element> foundElements = doc.getRootElement().getChildren();
anyMore = !foundElements.isEmpty();
for (Element e : foundElements) {
Workflow wfCurrent = Workflow.buildFromXML(e, logger);
alWorkflowInstances.add(wfCurrent);
}
}
}
}
final ArrayList<File> alFileInstances = new ArrayList<File>();
if (alVisiblePanels.contains(jpMyFiles)) {
boolean anyMore = true;
for (int page = 1; anyMore; page++) {
// fetch all user files
Document doc = myExperimentClient.getUserContributions(myExperimentClient.getCurrentUser(), Resource.FILE, Resource.REQUEST_SHORT_LISTING, page);
if (doc != null) {
List<Element> foundElements = doc.getRootElement().getChildren();
anyMore = !foundElements.isEmpty();
for (Element e : foundElements) {
File fCurrent = File.buildFromXML(e, logger);
alFileInstances.add(fCurrent);
}
}
}
}
final ArrayList<Pack> alPackInstances = new ArrayList<Pack>();
if (alVisiblePanels.contains(jpMyPacks)) {
boolean anyMore = true;
for (int page = 1; anyMore; page++) {
// fetch all user packs
Document doc = myExperimentClient.getUserContributions(myExperimentClient.getCurrentUser(), Resource.PACK, Resource.REQUEST_SHORT_LISTING, page);
if (doc != null) {
List<Element> foundElements = doc.getRootElement().getChildren();
anyMore = !foundElements.isEmpty();
for (Element e : foundElements) {
Pack pCurrent = Pack.buildFromXML(e, myExperimentClient, logger);
alPackInstances.add(pCurrent);
}
}
}
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// now create views for all user contributions
if (alVisiblePanels.contains(jpMyWorkflows)) {
// .. workflows ..
jpMyWorkflowsContent = new ResourceListPanel(pluginMainComponent, myExperimentClient, logger);
jpMyWorkflowsContent.setFullSizeItemsList(false);
jpMyWorkflowsContent.setListItems(new ArrayList<Resource>(alWorkflowInstances));
spMyWorkflowsContent = new JScrollPane(jpMyWorkflowsContent);
spMyWorkflowsContent.getVerticalScrollBar().setUnitIncrement(ResourcePreviewBrowser.PREFERRED_SCROLL);
jpMyWorkflows.removeAll();
jpMyWorkflows.setBackground(null); // return background to default colour
jpMyWorkflows.setBorder(BorderFactory.createEmptyBorder()); // remove border that was added prior to loading
jpMyWorkflows.add(spMyWorkflowsContent);
alVisiblePanelsWithHelperElements.add(new JComponent[] { jpMyWorkflows, spMyWorkflowsContent, jpMyWorkflowsContent });
}
if (alVisiblePanels.contains(jpMyFiles)) {
// .. files ..
jpMyFilesContent = new ResourceListPanel(pluginMainComponent, myExperimentClient, logger);
jpMyFilesContent.setFullSizeItemsList(false);
jpMyFilesContent.setListItems(new ArrayList<Resource>(alFileInstances));
spMyFilesContent = new JScrollPane(jpMyFilesContent);
spMyFilesContent.getVerticalScrollBar().setUnitIncrement(ResourcePreviewBrowser.PREFERRED_SCROLL);
jpMyFiles.removeAll();
jpMyFiles.setBackground(null); // return background to default colour
jpMyFiles.setBorder(BorderFactory.createEmptyBorder()); // remove border that was added prior to loading
jpMyFiles.add(spMyFilesContent);
alVisiblePanelsWithHelperElements.add(new JComponent[] { jpMyFiles, spMyFilesContent, jpMyFilesContent });
}
if (alVisiblePanels.contains(jpMyPacks)) {
// .. packs ..
jpMyPacksContent = new ResourceListPanel(pluginMainComponent, myExperimentClient, logger);
jpMyPacksContent.setFullSizeItemsList(false);
jpMyPacksContent.setListItems(new ArrayList<Resource>(alPackInstances));
spMyPacksContent = new JScrollPane(jpMyPacksContent);
spMyPacksContent.getVerticalScrollBar().setUnitIncrement(ResourcePreviewBrowser.PREFERRED_SCROLL);
jpMyPacks.removeAll();
jpMyPacks.setBackground(null); // return background to default colour
jpMyPacks.setBorder(BorderFactory.createEmptyBorder()); // remove border that was added prior to loading
jpMyPacks.add(spMyPacksContent);
alVisiblePanelsWithHelperElements.add(new JComponent[] { jpMyPacks, spMyPacksContent, jpMyPacksContent });
}
// now work out correct sizes for each section - the goal is to maximize the usage of the space on the page
int iFullAvailableHeight = getSize().height;
ArrayList<Integer> alIndexesToScale = new ArrayList<Integer>();
for (int i = 0; i < alVisiblePanelsWithHelperElements.size(); i++) {
JScrollPane spContent = (JScrollPane) alVisiblePanelsWithHelperElements.get(i)[1];
JPanel jpContent = (JPanel) alVisiblePanelsWithHelperElements.get(i)[2];
if ((jpContent.getPreferredSize().height + TOTAL_SECTION_VSPACING) < (iFullAvailableHeight / alVisiblePanels.size())) {
Dimension d = jpContent.getPreferredSize();
d.height += SCROLL_PANE_PADDING;
spContent.setPreferredSize(d);
iFullAvailableHeight -= (jpContent.getPreferredSize().height)
+ TOTAL_SECTION_VSPACING;
} else
alIndexesToScale.add(i);
}
if (alIndexesToScale.size() > 0) {
Dimension d = new Dimension();
for (Integer i : alIndexesToScale) {
d.height = (iFullAvailableHeight / alIndexesToScale.size())
- TOTAL_SECTION_VSPACING;
if (d.height > ((JPanel) alVisiblePanelsWithHelperElements.get(i)[2]).getPreferredSize().height
+ SCROLL_PANE_PADDING)
d.height = ((JPanel) alVisiblePanelsWithHelperElements.get(i)[2]).getPreferredSize().height
+ SCROLL_PANE_PADDING;
JScrollPane spCurrent = (JScrollPane) alVisiblePanelsWithHelperElements.get(i)[1];
spCurrent.setPreferredSize(d);
}
}
// report that this component has been loaded
pluginMainComponent.getMyStuffTab().cdlComponentLoadingDone.countDown();
validate();
repaint();
}
});
} catch (Exception ex) {
logger.error("Failed to populate some panel in My Stuff tab (User's files, workflows or packs)", ex);
}
}
}.start();
}