public JPanel createListViewPanel()

in taverna-perspective-myexperiment/src/main/java/org/apache/taverna/ui/perspectives/myexperiment/model/Resource.java [405:603]


  public JPanel createListViewPanel(boolean bCreateFullSizeView, MainComponent pluginMainComponent, EventListener eventHandler, Logger logger) {
	try {
	  JPanel mainPanel = new JPanel(new BorderLayout());
	  mainPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));

	  JTextPane infoTextPane = new JTextPane();
	  infoTextPane.setBorder(BorderFactory.createEmptyBorder());
	  infoTextPane.setEditable(false);

	  StringBuffer content = new StringBuffer();
	  content.append("<div class='list_item_container'>");
	  content.append("<div class='list_item'>");

	  content.append("<p class='title'>");
	  content.append("<a href='preview:"
		  + this.getItemType()
		  + ":"
		  + this.getURI()
		  + "'>"
		  + this.getTitle()
		  + ((this.getItemType() == Resource.WORKFLOW) ? (" (version "
			  + ((Workflow) this).getVersion() + ")") : "") + "</a>");
	  content.append("</p>");

	  if (bCreateFullSizeView) {
		// Uploader / Creator / Administrator
		if (this.hasUploader()) {
		  content.append("<p class='uploader'>");
		  content.append("Uploader: <a href='preview:" + Resource.USER + ":"
			  + this.getUploader().getURI() + "'>"
			  + this.getUploader().getName() + "</a>");
		  content.append("</p>");
		} else if (this.hasCreator()) {
		  content.append("<p class='uploader'>");
		  content.append("Creator: <a href='preview:" + Resource.USER + ":"
			  + this.getCreator().getURI() + "'>" + this.getCreator().getName()
			  + "</a>");
		  content.append("</p>");
		} else if (this.hasAdmin()) {
		  content.append("<p class='uploader'>");
		  content.append("Administrator: <a href='preview:" + Resource.USER
			  + ":" + this.getAdmin().getURI() + "'>"
			  + this.getAdmin().getName() + "</a>");
		  content.append("</p>");
		}

		// Type
		if (this.hasVisibleType()) {
		  content.append("<p class='uploader'>");
		  content.append("Type: " + this.getVisibleType());
		  content.append("</p>");
		}
	  }

	  content.append("<div class='desc'>");
	  content.append("<table style='margin-top: 5px; margin-bottom: 5px;'>");
	  content.append("<tr>");

	  if (this.itemType == Resource.WORKFLOW || this.itemType == Resource.USER) {
		boolean bManualResizeNeeded = false; // manual resize will be needed for user avatars (these don't have auto thumbnails)
		URI previewURI = null;
		if (this.itemType == Resource.WORKFLOW)
		  previewURI = ((Workflow) this).getThumbnail();
		else if (this.itemType == Resource.USER
			&& ((User) this).getAvatarResource() != null) {
		  previewURI = new URI(((User) this).getAvatarResource());
		  bManualResizeNeeded = true;
		}

		// preview pictures are only shown for workflows
		content.append("<td valign='top'>");
		content.append("<a href='preview:" + this.itemType + ":"
			+ this.getURI() + "'>");

		if (bCreateFullSizeView) {
		  if (!bManualResizeNeeded)
			content.append("<img class='preview' src='" + previewURI
				+ "'></img>");
		  else {
			String resizedImageURL = Util.getResizedImageIconTempFileURL(previewURI.toURL(), ResourceListPanel.THUMBNAIL_WIDTH_FOR_FULL_LIST_VIEW, ResourceListPanel.THUMBNAIL_HEIGHT_FOR_FULL_LIST_VIEW);
			content.append("<img class='preview' src='" + resizedImageURL
				+ "'></img>");
		  }
		} else {
		  String resizedImageURL = Util.getResizedImageIconTempFileURL(previewURI.toURL(), ResourceListPanel.THUMBNAIL_WIDTH_FOR_SHORT_LIST_VIEW, ResourceListPanel.THUMBNAIL_HEIGHT_FOR_SHORT_LIST_VIEW);
		  content.append("<img class='preview' src='" + resizedImageURL
			  + "'></img>");
		}

		content.append("</a>");
		content.append("</td>");
	  }

	  content.append("<td>");
	  content.append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
	  content.append("</td>");
	  content.append("<td valign='top' style='margin-bottom: 10px;'>");

	  if (this.getDescription() != null && this.getDescription().length() > 0) {
		if (bCreateFullSizeView)
		  content.append(this.getDescription());
		else {
		  String strTruncatedDescription = this.getDescription();
		  if (strTruncatedDescription.length() > ResourceListPanel.DESCRIPTION_TRUNCATE_LENGTH_FOR_SHORT_LIST_VIEW) {
			strTruncatedDescription = strTruncatedDescription.substring(0, ResourceListPanel.DESCRIPTION_TRUNCATE_LENGTH_FOR_SHORT_LIST_VIEW);
			strTruncatedDescription += " ...";
		  }
		  content.append(strTruncatedDescription);
		}
	  } else {
		content.append("<span class='none_text'>No description</span>");
	  }

	  content.append("</td>");
	  content.append("</tr>");
	  content.append("</table>");
	  content.append("</div>");

	  if (bCreateFullSizeView) {
		content.append("<p style='text-align: left;'><b><a href='"
			+ this.getResource()
			+ "'>Open in myExperiment</a></b>"
			+ "&nbsp;<img style='border: 0px;' src='"
			+ MyExperimentPerspective.getLocalResourceURL("external_link_small_icon")
			+ "' /></p>");
	  }

	  content.append("</div>");
	  content.append("</div>");

	  HTMLEditorKit kit = new StyledHTMLEditorKit(pluginMainComponent.getStyleSheet());
	  HTMLDocument doc = (HTMLDocument) (kit.createDefaultDocument());

	  doc.insertAfterStart(doc.getRootElements()[0].getElement(0), content.toString());

	  infoTextPane.setEditorKit(kit);
	  infoTextPane.setDocument(doc);
	  infoTextPane.setContentType("text/html");
	  infoTextPane.addHyperlinkListener((HyperlinkListener) eventHandler);
	  infoTextPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0)); // little bit of padding below the HTML preview pane

	  mainPanel.add(infoTextPane, BorderLayout.CENTER);

	  if (bCreateFullSizeView) {
		JPanel jpButtonsPanel = new JPanel();
		jpButtonsPanel.setLayout(new BoxLayout(jpButtonsPanel, BoxLayout.LINE_AXIS));

		// "Preview" button
		JButton previewButton = new JButton();
		previewButton.setAction(pluginMainComponent.new PreviewResourceAction(this.getItemType(), this.getURI()));
		jpButtonsPanel.add(previewButton);

		// "Download" button
		if (this.isDownloadable()) {
		  // will have a link to the actual resource on myExperiment
		  // (tests of different conditions are made inside the action)
		  JButton downloadButton = new JButton();
		  downloadButton.setAction(pluginMainComponent.new DownloadResourceAction(this));
		  jpButtonsPanel.add(downloadButton);
		}

		// "Load" button is only to be displayed for workflows
		if (this.getItemType() == Resource.WORKFLOW) {
		  // (various checks apply to see if this can be done - these are made inside the action)
		  JButton loadButton = new JButton();
		  loadButton.setAction(pluginMainComponent.new LoadResourceInTavernaAction(this));
		  jpButtonsPanel.add(loadButton);
		}

		// "Import" button is only to be displayed for workflows
		if (this.getItemType() == Resource.WORKFLOW) {
		  // (various checks apply to see if this can be done - these are made inside the action)
		  JButton importButton = new JButton();
		  importButton.setAction(pluginMainComponent.new ImportIntoTavernaAction(this));
		  jpButtonsPanel.add(importButton);
		}

		// setting look and feel for buttons
		mainPanel.add(jpButtonsPanel, BorderLayout.SOUTH);
		jpButtonsPanel.setBackground(new Color(247, 247, 247)); // grey background (lighter than main background of the frame)
		jpButtonsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(new Color(235, 235, 235)), // subtle darker border around the button bar
		BorderFactory.createEmptyBorder(3, 3, 3, 3) // a bit of padding around the buttons
		));
	  }

	  // setting border around one workflow entry
	  if (bCreateFullSizeView) {
		mainPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5), BorderFactory.createLineBorder(Color.GRAY)));
	  } else {
		mainPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.GRAY));
	  }

	  return (mainPanel);
	} catch (Exception e) {
	  logger.error("Failed while creating " + this.getItemTypeName()
		  + " list view:\n" + e);
	  return (null);
	}
  }