http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52817a33/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/SearchOptionsPanel.java ---------------------------------------------------------------------- diff --git a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/SearchOptionsPanel.java b/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/SearchOptionsPanel.java deleted file mode 100644 index 8d6c7c4..0000000 --- a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/SearchOptionsPanel.java +++ /dev/null @@ -1,183 +0,0 @@ -package org.apache.taverna.biocatalogue.ui; -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.awt.Component; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.Arrays; - -import javax.swing.AbstractAction; -import javax.swing.JButton; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.event.CaretEvent; -import javax.swing.event.CaretListener; - -import org.apache.taverna.biocatalogue.model.BioCataloguePluginConstants; -import org.apache.taverna.biocatalogue.model.ResourceManager; -import org.apache.taverna.biocatalogue.model.Resource.TYPE; -import org.apache.taverna.biocatalogue.model.search.SearchOptions; -import org.apache.taverna.biocatalogue.ui.search_results.SearchResultsMainPanel; -import org.apache.taverna.lang.ui.DeselectingButton; - - -/** - * - * @author Sergejs Aleksejevs - */ -@SuppressWarnings("serial") -public class SearchOptionsPanel extends JPanel implements HasDefaultFocusCapability -{ - // COMPONENTS - private SearchOptionsPanel thisPanel; - -private JTextField tfSearchQuery; - private JButton bSearch; - - private final SearchResultsMainPanel tabbedSearchResultsPanel; - - - public SearchOptionsPanel(SearchResultsMainPanel tabbedSearchResultsPanel) - { - super(); - this.thisPanel = this; - this.tabbedSearchResultsPanel = tabbedSearchResultsPanel; - - this.initialiseUI(); - } - - - private void initialiseUI() - { - this.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - - c.gridx = 0; - c.gridy = 0; - c.weightx = 0.0; - c.fill = GridBagConstraints.NONE; - - - this.tfSearchQuery = new JTextField(30); - this.tfSearchQuery.setToolTipText( - "<html> Tips for creating search queries:<br>" + - " 1) Use wildcards to make more flexible queries. Asterisk (<b>*</b>) matches any zero or more<br>" + - " characters (e.g. <b><i>Seq*</i></b> would match <b><i>Sequence</i></b>), question mark (<b>?</b>) matches any single<br>" + - " character (e.g. <b><i>Bla?t</i></b> would match <b><i>Blast</i></b>).<br>" + - " 2) Enclose the <b><i>\"search query\"</i></b> in double quotes to make exact phrase matching, otherwise<br>" + - " items that contain any (or all) words in the <b><i>search query</i></b> will be found.</html>"); - - this.tfSearchQuery.addFocusListener(new FocusListener() { - public void focusGained(FocusEvent e) { - tfSearchQuery.selectAll(); - } - public void focusLost(FocusEvent e) { /* do nothing */ } - }); - this.tfSearchQuery.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - // ENTER pressed - start search by simulating "search" button click - // (only do this if the "search" button was active at that moment) - if (e.getKeyCode() == KeyEvent.VK_ENTER && bSearch.isEnabled()) { - bSearch.doClick(); - } - } - }); - JButton jbClearSearch = new DeselectingButton(new AbstractAction("Clear") { - - @Override - public void actionPerformed(ActionEvent e) { - tfSearchQuery.setText(""); - clearSearch(); - }}, ""); - jbClearSearch.setIcon(ResourceManager.getImageIcon(ResourceManager.CLEAR_ICON)); - - this.add(jbClearSearch, c); - - c.gridx++; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 0.1; - this.add(tfSearchQuery, c); - - - // --- Search button --- - - c.gridx++; - c.weightx = 0; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.EAST; - this.bSearch = new DeselectingButton("Search", - new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (getSearchQuery().length() == 0) { - clearSearch(); - } - else { - // search query available - collect data about the current search and execute it - tabbedSearchResultsPanel.startNewSearch(thisPanel.getState()); - } - } - }, - tfSearchQuery.getToolTipText()); - this.bSearch.setIcon(ResourceManager.getImageIcon(ResourceManager.SEARCH_ICON)); - this.add(bSearch, c); - -} - - private void clearSearch() { - tabbedSearchResultsPanel.clearSearch(); - thisPanel.focusDefaultComponent(); - } - - /** - * Saves the current state of the search options into a single {@link SearchOptions} object. - */ - public SearchOptions getState() { - return (new SearchOptions(getSearchQuery(), Arrays.asList(TYPE.values()))); - } - - - // *** GETTERS AND SETTERS *** - - public String getSearchQuery() { - return (this.tfSearchQuery.getText().trim()); - } - public void setSearchQuery(String strSearchQuery) { - this.tfSearchQuery.setText(strSearchQuery); - } - - - // *** Callbacks for HasDefaultFocusCapability interface *** - - public void focusDefaultComponent() { - this.tfSearchQuery.selectAll(); - this.tfSearchQuery.requestFocusInWindow(); - } - - public Component getDefaultComponent() { - return(this.tfSearchQuery); - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52817a33/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/FilterTreeNode.java ---------------------------------------------------------------------- diff --git a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/FilterTreeNode.java b/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/FilterTreeNode.java deleted file mode 100644 index 956c54d..0000000 --- a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/FilterTreeNode.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.apache.taverna.biocatalogue.ui.filtertree; -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.taverna.biocatalogue.ui.tristatetree.TriStateTreeNode; - -/** - * This class allows storing two pieces of data relevant to content filtering - * within the node of a tree. These values are kept hidden from the user and - * are only used when the filtering is about to happen. - * - * @author Sergejs Aleksejevs - */ -@SuppressWarnings("serial") -public class FilterTreeNode extends TriStateTreeNode -{ - private String type; - private String urlValue; - final private boolean isFilterCategory; - - - /** - * This constructor is useful for root nodes, which need not have filter type / value. - */ - public FilterTreeNode(Object userObject) { - super(userObject); - - this.isFilterCategory = true; - } - - - /** - * @param userObject As in the superclass (DefaultMutableTreeNode) - the object which represents the node in the UI - * @param filterType Type of the filter - e.g. 'Service Categories' --> "cat"; 'Service Types' --> "t" - * @param filterUrlValue Value that should be added to the URL to perform the filtering operation - */ - public FilterTreeNode(Object userObject, String filterType, String filterUrlValue) { - super(userObject); - - this.setType(filterType); - this.setUrlValue(filterUrlValue); - this.isFilterCategory = false; - } - - - public void setType(String type) { - this.type = type; - } - - public String getType() { - return type; - } - - public void setUrlValue(String urlValue) { - this.urlValue = urlValue; - } - - - public String getUrlValue() { - return urlValue; - } - - /** - * @return True if and only if this node is one of the "root" filter categories (not to be mixed with root of the filter tree). - */ - public boolean isFilterCategory() { - return isFilterCategory; - } - - - /** - * @return <code>true</code> if the current {@link FilterTreeNode} represents a tag with a namespace - * (i.e. an ontological term), whose full tag name looks like: - * <code>< http://example.namespace.com#tag_display_name ></code> - */ - public boolean isTagWithNamespaceNode() { - return (this.getType() != null && this.getType().contains("tag") && this.getUrlValue().contains("#") && - this.getUrlValue().startsWith("<") && this.getUrlValue().endsWith(">")); - } - - - /** - * Static wrapper for {@link FilterTreeNode#isTagWithNamespaceNode()} - * - * @param filterType - * @param filterUrlValue - * @return - */ - public static boolean isTagWithNamespaceNode(String filterType, String filterUrlValue) { - return (new FilterTreeNode("test_user_object", filterType, filterUrlValue).isTagWithNamespaceNode()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52817a33/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/FilterTreePane.java ---------------------------------------------------------------------- diff --git a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/FilterTreePane.java b/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/FilterTreePane.java deleted file mode 100644 index a35a8da..0000000 --- a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/FilterTreePane.java +++ /dev/null @@ -1,364 +0,0 @@ -package org.apache.taverna.biocatalogue.ui.filtertree; -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JToolBar; -import javax.swing.SwingUtilities; - -import org.apache.taverna.biocatalogue.model.BioCataloguePluginConstants; -import org.apache.taverna.biocatalogue.model.Resource.TYPE; -import org.apache.taverna.biocatalogue.model.ResourceManager; -import org.apache.taverna.biocatalogue.model.connectivity.BioCatalogueClient; -import org.apache.taverna.biocatalogue.model.search.SearchInstance; -import org.apache.taverna.biocatalogue.model.search.ServiceFilteringSettings; -import org.apache.taverna.biocatalogue.ui.tristatetree.JTriStateTree; -import org.apache.taverna.biocatalogue.ui.tristatetree.TriStateTreeCheckingListener; -import org.apache.taverna.ui.perspectives.biocatalogue.MainComponentFactory; -import org.apache.taverna.workbench.icons.WorkbenchIcons; - -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.log4j.Logger; - -import org.biocatalogue.x2009.xml.rest.Filter; -import org.biocatalogue.x2009.xml.rest.FilterGroup; -import org.biocatalogue.x2009.xml.rest.FilterType; -import org.biocatalogue.x2009.xml.rest.Filters; - -/** - * - * @author Sergejs Aleksejevs - */ -@SuppressWarnings("serial") -public class FilterTreePane extends JPanel implements TriStateTreeCheckingListener -{ - private TYPE resourceType; - private String filtersURL; - private BioCatalogueClient client; - private Logger logger; - - private FilterTreePane thisPanel; - - private JToolBar tbFilterTreeToolbar; - - private JPanel jpFilters = null; - private JFilterTree filterTree; // tree component to display filter selections - private Filters filtersRoot; // last filters element which was received from the API - - - - public FilterTreePane(TYPE resourceType) - { - this.thisPanel = this; - - this.resourceType = resourceType; - this.filtersURL = resourceType.getAPIResourceCollectionFiltersURL(); - this.client = BioCatalogueClient.getInstance(); - this.logger = Logger.getLogger(this.getClass()); - - initialiseUI(); - loadFiltersAndBuildTheTree(); - } - - - private void initialiseUI() - { - jpFilters = new JPanel(); - jpFilters.setBackground(Color.WHITE); - - JScrollPane spFilters = new JScrollPane(jpFilters); - spFilters.setMinimumSize(new Dimension(235,0)); - spFilters.setPreferredSize(new Dimension(300,0)); - spFilters.getVerticalScrollBar().setUnitIncrement(BioCataloguePluginConstants.DEFAULT_SCROLL); - - - tbFilterTreeToolbar = createTreeActionToolbar(); - resetTreeActionToolbar(); - - this.setLayout(new BorderLayout()); - this.add(tbFilterTreeToolbar, BorderLayout.NORTH); - this.add(spFilters, BorderLayout.CENTER); - } - - - /** - * @return A toolbar that replicates all actions available in the contextual menu of - * the filtering tree - mainly: saving current filter, reloading filter tree, - * expanding/collapsing and selecting/deselecting everything in the tree. - */ -private JToolBar createTreeActionToolbar() - { - - - // the actual toolbar - no actions are added to it yet: done in a separate method - JToolBar tbTreeActions = new JToolBar(JToolBar.HORIZONTAL); - tbTreeActions.setAlignmentX(RIGHT_ALIGNMENT); - tbTreeActions.setBorderPainted(true); - tbTreeActions.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - tbTreeActions.setFloatable(false); - return (tbTreeActions); - } - - - /** - * Resets the action toolbar to the original state. - */ - public void resetTreeActionToolbar() - { - - tbFilterTreeToolbar.removeAll(); - tbFilterTreeToolbar.repaint(); - } - - - /** - * This method loads filter data from API and populates the view. - */ - private void loadFiltersAndBuildTheTree() - { - SwingUtilities.invokeLater(new Runnable() { - public void run() - { - resetTreeActionToolbar(); - - jpFilters.removeAll(); - jpFilters.setLayout(new BorderLayout()); - jpFilters.add(new JLabel(" Loading filters..."), BorderLayout.NORTH); - jpFilters.add(new JLabel(ResourceManager.getImageIcon(ResourceManager.BAR_LOADER_ORANGE)), BorderLayout.CENTER); - thisPanel.validate(); - thisPanel.repaint(); // validate and repaint this component to make sure that - // scroll bar around the filter tree placeholder panel disappears - } - }); - - new Thread("Load filters") { - public void run() { - try { - // load filter data - filtersRoot = client.getBioCatalogueFilters(filtersURL); - - // Create root of the filter tree component - FilterTreeNode root = new FilterTreeNode("root"); - - // populate the tree via its root element - for (FilterGroup fgroup : filtersRoot.getGroupList()) - { - // attach filter group directly to the root node - FilterTreeNode fgroupNode = new FilterTreeNode("<html><span style=\"color: black; font-weight: bold;\">" + StringEscapeUtils.escapeHtml(fgroup.getName().toString()) + "</span></html>"); - root.add(fgroupNode); - - - // go through all filter types in this group and add them to the tree - for (FilterType ftype : fgroup.getTypeList()) - { - // if there's more than one filter type in the group, add the type node as another level of nesting - // (otherwise, attach filters inside the single type directly to the group node) - FilterTreeNode filterTypeNode = fgroupNode; - if (fgroup.getTypeList().size() > 1) { - filterTypeNode = new FilterTreeNode("<html><span style=\"color: black; font-weight: bold;\">" + StringEscapeUtils.escapeHtml(ftype.getName().toString()) + "</span></html>"); - fgroupNode.add(filterTypeNode); - } - - // For some reason sorting the list of filters before inserting into tree - // messes up the tree nodes -// Collections.sort(ftype.getFilterList(), new Comparator<Filter>(){ -// @Override -// public int compare(Filter f1, Filter f2) { -// return (f1.getName().compareToIgnoreCase(f2.getName())); -// } -// }); - addFilterChildren(filterTypeNode, ftype.getUrlKey().toString(), ftype.getFilterList()); - } - } - - // Create the tree view with the populated root - filterTree = new JFilterTree(root); - filterTree.setRootVisible(false); // don't want the root to be visible; not a standard thing, so not implemented within JTriStateTree - filterTree.setLargeModel(true); // potentially can have many filters! - filterTree.addCheckingListener(thisPanel); - - - // insert the created tree view into the filters panel - jpFilters.removeAll(); - jpFilters.setLayout(new GridLayout(0,1)); - jpFilters.add(filterTree); - jpFilters.validate(); - - - // add actions from the contextual menu of the filter tree into the toolbar - // that replicates those plus adds additional ones in this panel - tbFilterTreeToolbar.removeAll(); - for (Action a : filterTree.getContextualMenuActions()) { - tbFilterTreeToolbar.add(a); - } - - - // enable all actions - filterTree.enableAllContextualMenuAction(true); - } - catch (Exception e) { - logger.error("Failed to load filter tree from the following URL: " + filtersURL, e); - } - } - - - /** - * Recursive method to populate a node of the filter tree with all - * sub-filters. - * - * Ontological terms will be underlined. - * - * @param root Tree node to add children to. - * @param filterList A list of Filters to add to "root" as children. - */ - private void addFilterChildren(FilterTreeNode root, String filterCategory, List<Filter> filterList) { - for (Filter f : filterList) { - - // Is this an ontological term? - String ontology = null; - if (FilterTreeNode.isTagWithNamespaceNode(filterCategory, f - .getUrlValue())) { - String nameAndNamespace = f.getUrlValue().substring(1, - f.getUrlValue().length() - 1); - String[] namePlusNamespace = nameAndNamespace - .split("#"); - ontology = JFilterTree - .getOntologyFromNamespace(namePlusNamespace[0]); - } - - FilterTreeNode fNode = new FilterTreeNode("<html><span color=\"black\"" /*(FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue()) ? " style=\"text-decoration: underline;\"" : "") */ + ">" + - StringEscapeUtils.escapeHtml(f.getName()) + " (" + f.getCount() + ")" + "</span>" + - /*(FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue()) ? "<span color=\"gray\"> ("+f.getCount().intValue()+")</span></html>" : "</html>"),*/ - (ontology != null ? "<span color=\"#3090C7\"> <"+ ontology +"></span></html>" : "</html>"), - filterCategory, f.getUrlValue()); - addFilterChildren(fNode, filterCategory, f.getFilterList()); - - // Insert the node into the (alphabetically) sorted children nodes - List<FilterTreeNode> children = Collections.list(root.children()); - // Search for the index the new node should be inserted at - int index = Collections.binarySearch(children, fNode, - new Comparator<FilterTreeNode>() { - @Override - public int compare(FilterTreeNode o1, - FilterTreeNode o2) { - String str1 = ((String) o1.getUserObject()) - .toString(); - String str2 = ((String) o2.getUserObject()) - .toString(); - return (str1.compareToIgnoreCase(str2)); - } - }); - - if (index < 0){ // not found - index will be equal to -insertion-point -1 - index = -index - 1; - }// else node with the same name found in the array - insert it at that position - root.insert(fNode, index); - - //root.add(fNode); - } - } - }.start(); - } - - - /** - * @param si Uses this SearchInstance to restore the checking - * state of filtering criteria in the filter tree. - */ - public void restoreFilteringSettings(SearchInstance si) { - this.filterTree.restoreFilterCheckingSettings(si.getFilteringSettings().getFilterTreeRootsOfCheckedPaths()); - } - - - /** - * Clears any selections made in the filter tree - - * i.e. both clears checked nodes and removes all tree path selections. - */ - public void clearSelection() { - // filter tree may not have been initialised yet, so perform a check - if (this.filterTree != null) - { - // remove, then restore self as a listener - this is to avoid - // receiving checking state change event - this.filterTree.removeCheckingListener(thisPanel); - this.filterTree.selectAllNodes(false); - this.filterTree.clearSelection(); - this.filterTree.addCheckingListener(thisPanel); - } - } - - - /** - * Collapses all expanded nodes in the filter tree. - */ - public void collapseAll() { - // filter tree may not have been initialised yet, so perform a check - if (this.filterTree != null) { - this.filterTree.collapseAll(); - } - } - - public void applyQueryString(final String queryString) { - this.filtersURL = resourceType.getAPIResourceCollectionFiltersURL() + "?q=" + queryString; - loadFiltersAndBuildTheTree(); - } - - /** - * Used for making preferred height of the search status label - * the same as the height of this toolbar. - * - * @return - */ - public Dimension getTreeToolbarPreferredSize() { - return this.tbFilterTreeToolbar.getPreferredSize(); - } - - - // *** Callback for TriStateTreeCheckingListener *** - - /** - * We start a new search as soon as checking state of the filter tree changes. - */ - public void triStateTreeCheckingChanged(JTriStateTree source) - { - MainComponentFactory.getSharedInstance().getBioCatalogueExplorationTab().getTabbedSearchResultsPanel(). - startNewFiltering(resourceType, new ServiceFilteringSettings(filterTree)); - } - - -public void reset() { - this.filtersURL = resourceType.getAPIResourceCollectionFiltersURL(); - loadFiltersAndBuildTheTree(); -} - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52817a33/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/JFilterTree.java ---------------------------------------------------------------------- diff --git a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/JFilterTree.java b/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/JFilterTree.java deleted file mode 100644 index 104df89..0000000 --- a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/filtertree/JFilterTree.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.apache.taverna.biocatalogue.ui.filtertree; -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.awt.event.MouseEvent; -import java.util.HashMap; -import java.util.Map; - -import org.apache.taverna.biocatalogue.ui.tristatetree.JTriStateTree; -import org.apache.taverna.biocatalogue.ui.tristatetree.TriStateTreeNode; - -/** - * This subclass of {@link JTriStateTree} provides custom behaviour - * for tooltips: ontological terms will now always get a tooltip that - * displays the namespace for the tag, but plain text tags will still - * behave as before - the way it is defined in the superclass (so that - * the tooltip will only be shown if the tag does not fully fit into - * the visible part of the {@link FilterTreePane}. - * - * @author Sergejs Aleksejevs - */ -@SuppressWarnings("serial") -public class JFilterTree extends JTriStateTree -{ - - private static Map<String, String> nameSpaceToOntologyMap = new HashMap<String, String>(){ - { - put("http://www.mygrid.org.uk/ontology", "mygrid-domain-ontology"); - put("http://www.mygrid.org.uk/mygrid-moby-service", "mygrid-service-ontology"); - } - }; - - - public JFilterTree(TriStateTreeNode root) { - super(root); - } - - - public String getToolTipText(MouseEvent e) - { - Object correspondingObject = super.getTreeNodeObject(e); - if (correspondingObject != null && correspondingObject instanceof FilterTreeNode) { - FilterTreeNode filterNode = (FilterTreeNode) correspondingObject; - - if (filterNode.isTagWithNamespaceNode()) - { - String nameAndNamespace = filterNode.getUrlValue().substring(1, filterNode.getUrlValue().length() - 1); - String[] namePlusNamespace = nameAndNamespace.split("#"); - - return ("<html>" + namePlusNamespace[1] + " (<b>Namespace: </b>" + namePlusNamespace[0] + ")</html>"); - } - } - - return super.getToolTipText(e); - } - - public static String getOntologyFromNamespace(String namespace){ - if (namespace == null){ - return null; - } - else{ - if (nameSpaceToOntologyMap.containsKey(namespace)){ - return nameSpaceToOntologyMap.get(namespace); - } - else{ - return null; - } - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52817a33/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/ExpandableOnDemandLoadedListCellRenderer.java ---------------------------------------------------------------------- diff --git a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/ExpandableOnDemandLoadedListCellRenderer.java b/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/ExpandableOnDemandLoadedListCellRenderer.java deleted file mode 100644 index 2a3619e..0000000 --- a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/ExpandableOnDemandLoadedListCellRenderer.java +++ /dev/null @@ -1,236 +0,0 @@ -package org.apache.taverna.biocatalogue.ui.search_results; -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.awt.Color; -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.ListCellRenderer; -import javax.swing.SwingUtilities; - -import org.apache.taverna.biocatalogue.model.LoadingResource; -import org.apache.taverna.biocatalogue.model.Resource; -import org.apache.taverna.biocatalogue.model.ResourceManager; -import org.apache.taverna.biocatalogue.model.Resource.TYPE; - -import org.biocatalogue.x2009.xml.rest.ResourceLink; - - -/** - * - * @author Sergejs Aleksejevs - */ -@SuppressWarnings("serial") -public abstract class ExpandableOnDemandLoadedListCellRenderer extends JPanel implements ListCellRenderer -{ - protected static final int DESCRIPTION_MAX_LENGTH_COLLAPSED = 90; - protected static final int DESCRIPTION_MAX_LENGTH_EXPANDED = 500; - - protected static final int LINE_LENGTH = 90; - - - protected static final int TOOLTIP_DESCRIPTION_LENGTH = 150; - protected static final int TOOLTIP_LINE_LENGTH = 60; - - // list cells are not repainted by Swing by default - hence to use animated GIFs inside cells, - // need to have a special class that takes care of changing the frames as necessary - protected JLabel loaderBarAnimationOrange = new JLabel(ResourceManager.getImageIcon(ResourceManager.BAR_LOADER_ORANGE), JLabel.CENTER); - protected JLabel loaderBarAnimationGrey = new JLabel(ResourceManager.getImageIcon(ResourceManager.BAR_LOADER_GREY), JLabel.CENTER); - protected JLabel loaderBarAnimationGreyStill = new JLabel (ResourceManager.getImageIcon(ResourceManager.BAR_LOADER_GREY_STILL), JLabel.CENTER); - - - protected JPanel thisPanel; - private List<Class<? extends ResourceLink>> resourceClasses; - - - protected JLabel jlExpand; - protected static Rectangle expandRect; - - public ExpandableOnDemandLoadedListCellRenderer() - { - this.thisPanel = this; - - resourceClasses = new ArrayList<Class<? extends ResourceLink>>(); - try { - for (Resource.TYPE resourceType : Resource.TYPE.values()) { - resourceClasses.add(resourceType.getXmlBeansGeneratedClass()); - } - } - catch (Exception e) { - e.printStackTrace(); - } - - } - - - public static Rectangle getExpandRect() { - return (expandRect == null ? new Rectangle() : expandRect); - } - - - public Component getListCellRendererComponent(JList list, Object itemToRender, int itemIndex, boolean isSelected, boolean cellHasFocus) - { - // the same instance of the cell renderer is used for all cells, so - // need to remove everything from the current panel to ensure clean - // painting of the current cell - this.removeAll(); - - // GET THE DATA - - // LoadingResource is a placeholder for the detailed data on the resource -- - // it is being quickly fetched from the API and contanins just the name and the URL - // of the actual resource; - // - // these entries will be placed into the list when the initial part of the search - // is complete, further details will be loaded asynchronously and inserted into - // the same area - if (itemToRender instanceof LoadingResource) { - prepareInitiallyLoadingEntry(itemToRender); - } - - // real data about some resource: details, but in the collapsed form - else if (isInstanceOfResourceType(itemToRender)) { - prepareLoadedEntry(itemToRender, isSelected); - } - - // error case - unknown resource... - else { - prepareUnknownResourceTypeEntry(); - } - - - // MAKE SURE CELL SELECTION WORKS AS DESIRED - if (shouldBeHidden(itemToRender)) { - this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(3, 4, 3, 4, list.getBackground()), - BorderFactory.createLineBorder(Color.DARK_GRAY))); - setBackground(list.getBackground()); - setForeground(list.getBackground()); - } - else if (isSelected) { - this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(3, 4, 3, 4, list.getBackground()), - BorderFactory.createLineBorder(Color.DARK_GRAY))); - setBackground(Color.decode("#BAE8FF")); // very light blue colour - setForeground(list.getSelectionForeground()); - } else { - this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(3, 4, 3, 4, list.getBackground()), - BorderFactory.createLineBorder(Color.DARK_GRAY))); - setBackground(Color.WHITE); - setForeground(list.getForeground()); - } - - this.revalidate(); - - if (expandRect == null && jlExpand != null) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - expandRect = jlExpand.getBounds(); - expandRect.x -= Math.abs(thisPanel.getBounds().x); - } - }); - } - - return (this); - } - - - /** - * This entry can be in one of two states: - * -- containing only the name of the resource and NOT loading further details; - * -- containing only the name of the resource and LOADING further details. - * - * @param itemToRender - * @return - */ - protected abstract GridBagConstraints prepareInitiallyLoadingEntry(Object itemToRender); - - - /** - * - * @param itemToRender - * @param isSelected - * @param expandedView <code>true</code> to indicate that this method generates the top - * fragment of the expanded list entry for this SOAP operation / REST method. - * @return - */ - protected abstract GridBagConstraints prepareLoadedEntry(Object itemToRender, boolean isSelected); - - - private void prepareUnknownResourceTypeEntry() - { - this.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.anchor = GridBagConstraints.NORTHWEST; - c.fill = GridBagConstraints.HORIZONTAL; - - c.gridx = 0; - c.gridy = 0; - c.weightx = 0; - c.insets = new Insets(8, 6, 6, 3); - this.add(new JLabel(ResourceManager.getImageIcon(ResourceManager.UNKNOWN_RESOURCE_TYPE_ICON)), c); - - c.gridx++; - c.weightx = 1.0; - c.insets = new Insets(8, 3, 6, 3); - this.add(new JLabel("<html><font color=\"#FF0000\">ERROR: This item shoulnd't have been here...</font></html>"), c); - - c.gridx = 1; - c.gridy++; - c.gridheight = 1; - c.weightx = 1.0; - c.weighty = 0; - c.insets = new Insets(3, 3, 3, 3); - this.add(new JLabel(" "), c); - - c.gridy++; - c.insets = new Insets(3, 3, 8, 3); - this.add(new JLabel(" "), c); - } - - - private boolean isInstanceOfResourceType(Object itemToRender) - { - for (Class<? extends ResourceLink> resourceClass : resourceClasses) { - if (resourceClass.isInstance(itemToRender)) { - return (true); - } - } - - return (false); - } - - protected TYPE determineResourceType(Object itemToRender) { - if (itemToRender instanceof ResourceLink) { - return (Resource.getResourceTypeFromResourceURL(((ResourceLink)itemToRender).getHref())); - } - else { - return (null); - } - } - - abstract boolean shouldBeHidden(Object itemToRender); - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52817a33/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/RESTMethodListCellRenderer.java ---------------------------------------------------------------------- diff --git a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/RESTMethodListCellRenderer.java b/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/RESTMethodListCellRenderer.java deleted file mode 100644 index 7a3e894..0000000 --- a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/RESTMethodListCellRenderer.java +++ /dev/null @@ -1,264 +0,0 @@ -package org.apache.taverna.biocatalogue.ui.search_results; -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JLabel; - -import org.apache.taverna.biocatalogue.model.LoadingResource; -import org.apache.taverna.biocatalogue.model.Resource; -import org.apache.taverna.biocatalogue.model.ResourceManager; -import org.apache.taverna.biocatalogue.model.Util; -import org.apache.taverna.lang.ui.ReadOnlyTextArea; -import org.apache.taverna.ui.perspectives.biocatalogue.integration.health_check.ServiceMonitoringStatusInterpreter; - -import org.apache.commons.lang.StringEscapeUtils; -import org.biocatalogue.x2009.xml.rest.RestMethod; -import org.biocatalogue.x2009.xml.rest.RestParameter; -import org.biocatalogue.x2009.xml.rest.RestRepresentation; -import org.biocatalogue.x2009.xml.rest.Service; -import org.biocatalogue.x2009.xml.rest.RestMethod.Ancestors; - - -/** - * - * - * @author Sergejs Aleksejevs - */ -public class RESTMethodListCellRenderer extends ExpandableOnDemandLoadedListCellRenderer -{ - private JLabel jlTypeIcon = new JLabel(); - private JLabel jlItemStatus = new JLabel(); - private JLabel jlItemTitle = new JLabel("X"); - private JLabel jlPartOf = new JLabel("X"); - private ReadOnlyTextArea jtDescription = new ReadOnlyTextArea(5, 80); - private JLabel jlMethodType = new JLabel("X"); - private JLabel jlUrlTemplate = new JLabel("X"); - private JLabel jlMethodParameters = new JLabel("X"); - private JLabel jlInputRepresentations = new JLabel("X"); - private JLabel jlOutputRepresentations = new JLabel("X"); - - private GridBagConstraints c; - - private static Resource.TYPE resourceType = Resource.TYPE.RESTMethod; - - - - public RESTMethodListCellRenderer() { - jlItemTitle.setFont(jlItemTitle.getFont().deriveFont(Font.PLAIN, jlItemTitle.getFont().getSize() + 2)); - jtDescription.setOpaque(false); - jtDescription.setLineWrap(true); - jtDescription.setWrapStyleWord(true); - } - - - - /** - * This entry can be in one of two states: - * -- containing only the name of the resource and NOT loading further details; - * -- containing only the name of the resource and LOADING further details. - * - * @param itemToRender - * @return - */ - protected GridBagConstraints prepareInitiallyLoadingEntry(Object itemToRender) - { - LoadingResource resource = (LoadingResource)itemToRender; - - jlTypeIcon.setIcon(resourceType.getIcon()); - jlItemStatus.setIcon(ResourceManager.getImageIcon(ResourceManager.SERVICE_STATUS_UNCHECKED_ICON_LARGE)); - - jlItemTitle.setText("<html>" + StringEscapeUtils.escapeHtml(Resource.getDisplayNameForResource(resource)) + "<font color=\"gray\"><i>- fetching more information</i></font></html>"); - - jlPartOf.setText(""); - jtDescription.setText(" "); - jlMethodType.setText(" "); - jlUrlTemplate.setText(" "); - jlMethodParameters.setText(" "); - jlInputRepresentations.setText(" "); - jlOutputRepresentations.setText(" "); - - return (arrangeLayout()); - } - - - /** - * - * @param itemToRender - * @param expandedView <code>true</code> to indicate that this method generates the top - * fragment of the expanded list entry for this SOAP operation / REST method. - * @return - */ - protected GridBagConstraints prepareLoadedEntry(Object itemToRender, boolean selected) - { - RestMethod restMethod = (RestMethod)itemToRender;; - - Ancestors ancestors = restMethod.getAncestors(); - Service service = ancestors.getService(); - String title = "<html>" + StringEscapeUtils.escapeHtml(Resource.getDisplayNameForResource(restMethod)); - - if (restMethod.isSetArchived() || service.isSetArchived()) { - jlTypeIcon.setIcon(ResourceManager.getImageIcon(ResourceManager.WARNING_ICON)); - title = title + "<i> - this operation is archived and probably cannot be used</i></html>"; - } - else { - jlTypeIcon.setIcon(resourceType.getIcon()); - title = title + "</html>"; - } - - // service status - jlItemStatus.setIcon(ServiceMonitoringStatusInterpreter.getStatusIcon(service, false)); - jlItemTitle.setText(title); - - jlPartOf.setText("<html><b>Part of: </b>" + restMethod.getAncestors().getRestService().getResourceName() + "</html>"); - - String strDescription = (restMethod.getDescription() == null || restMethod.getDescription().length() == 0 ? - "No description" : - Util.stripAllHTML(restMethod.getDescription())); - jtDescription.setText(strDescription); - - jlMethodType.setText("<html><b>HTTP Method: </b>" + StringEscapeUtils.escapeHtml(restMethod.getHttpMethodType().toString()) + "</html>"); - jlUrlTemplate.setText("<html><b>URL Template: </b>" + StringEscapeUtils.escapeHtml(restMethod.getUrlTemplate()) + "</html>"); - - List<String> names = new ArrayList<String>(); - for (RestParameter restParameter : restMethod.getInputs().getParameters().getRestParameterList()) { - names.add(restParameter.getName() + (restParameter.getIsOptional() ? " (optional)" : "")); - } - - String methodParameters = "<b>" + names.size() + " " + Util.pluraliseNoun("Parameter", names.size()) + "</b>"; - if(names.size() > 0) { - methodParameters += ": " + StringEscapeUtils.escapeHtml(Util.ensureLineLengthWithinString(Util.join(names, ", "), LINE_LENGTH, false)); - } - methodParameters = "<html>" + methodParameters + "</html>"; - jlMethodParameters.setText(methodParameters); - - names.clear(); - for (RestRepresentation restRepresentation : restMethod.getInputs().getRepresentations().getRestRepresentationList()) { - names.add(restRepresentation.getContentType()); - } - - String inputRepresentations = "<b>" + names.size() + " " + Util.pluraliseNoun("Input representation", names.size()) + "</b>"; - if(names.size() > 0) { - inputRepresentations += ": " + StringEscapeUtils.escapeHtml(Util.ensureLineLengthWithinString(Util.join(names, ", "), LINE_LENGTH, false)); - } - inputRepresentations = "<html>" + inputRepresentations + "</html>"; - - jlInputRepresentations.setText(inputRepresentations); - - // output representations - names.clear(); - for (RestRepresentation restRepresentation : restMethod.getOutputs().getRepresentations().getRestRepresentationList()) { - names.add(restRepresentation.getContentType()); - } - - String outputRepresentations = "<b>" + names.size() + " " + Util.pluraliseNoun("Output representation", names.size()) + "</b>"; - if(names.size() > 0) { - outputRepresentations += ": " + StringEscapeUtils.escapeHtml(Util.ensureLineLengthWithinString(Util.join(names, ", "), LINE_LENGTH, false)); - } - outputRepresentations = "<html>" + outputRepresentations + "</html>"; - - jlOutputRepresentations.setText(outputRepresentations); - - return (arrangeLayout()); - } - - - /** - * @return Final state of the {@link GridBagConstraints} instance - * that was used to lay out components in the panel. - */ - private GridBagConstraints arrangeLayout() - { - // POPULATE PANEL WITH PREPARED COMPONENTS - this.setLayout(new GridBagLayout()); - c = new GridBagConstraints(); - c.anchor = GridBagConstraints.NORTHWEST; - c.fill = GridBagConstraints.HORIZONTAL; - - c.gridx = 0; - c.gridy = 0; - c.weightx = 0; - c.insets = new Insets(8, 6, 6, 3); - this.add(jlTypeIcon, c); - - c.gridx++; - c.weightx = 1.0; - c.insets = new Insets(8, 3, 6, 3); - this.add(jlItemTitle, c); - - c.gridx++; - c.gridheight = 8; - c.weightx = 0; - c.weighty = 1.0; - this.add(jlItemStatus, c); - - c.gridx = 1; - c.gridy++; - c.gridheight = 1; - c.weightx = 1.0; - c.weighty = 0; - this.add(jlPartOf, c); - - c.fill = GridBagConstraints.NONE; - c.gridy++; - this.add(jtDescription, c); - - c.fill = GridBagConstraints.HORIZONTAL; - c.gridy++; - this.add(jlMethodType, c); - - c.gridy++; - this.add(jlUrlTemplate, c); - - c.gridy++; - this.add(jlMethodParameters, c); - - c.gridy++; - this.add(jlInputRepresentations, c); - - c.gridy++; - this.add(jlOutputRepresentations, c); - return (c); - } - -@Override -boolean shouldBeHidden(Object itemToRender) { - if (!(itemToRender instanceof RestMethod)) { - return false; - } - RestMethod restMethod = (RestMethod)itemToRender;; - - Ancestors ancestors = restMethod.getAncestors(); - Service service = ancestors.getService(); - String title = Resource.getDisplayNameForResource(restMethod); - - if (restMethod.isSetArchived() || service.isSetArchived()) { - return true; - } - else { - return false; - } - -} - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/52817a33/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/SOAPOperationListCellRenderer.java ---------------------------------------------------------------------- diff --git a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/SOAPOperationListCellRenderer.java b/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/SOAPOperationListCellRenderer.java deleted file mode 100644 index 4386d12..0000000 --- a/taverna-perspective-biocatalogue/src/main/java/org/apache/taverna/biocatalogue/ui/search_results/SOAPOperationListCellRenderer.java +++ /dev/null @@ -1,273 +0,0 @@ -package org.apache.taverna.biocatalogue.ui.search_results; -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.ImageIcon; -import javax.swing.JLabel; - -import org.apache.taverna.biocatalogue.model.LoadingExpandedResource; -import org.apache.taverna.biocatalogue.model.LoadingResource; -import org.apache.taverna.biocatalogue.model.Resource; -import org.apache.taverna.biocatalogue.model.ResourceManager; -import org.apache.taverna.biocatalogue.model.Util; -import org.apache.taverna.lang.ui.ReadOnlyTextArea; -import org.apache.taverna.ui.perspectives.biocatalogue.integration.health_check.ServiceMonitoringStatusInterpreter; - -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.biocatalogue.x2009.xml.rest.Service; -import org.biocatalogue.x2009.xml.rest.ServiceTechnologyType; -import org.biocatalogue.x2009.xml.rest.SoapInput; -import org.biocatalogue.x2009.xml.rest.SoapOperation; -import org.biocatalogue.x2009.xml.rest.SoapOutput; -import org.biocatalogue.x2009.xml.rest.SoapService; -import org.biocatalogue.x2009.xml.rest.Service.ServiceTechnologyTypes; -import org.biocatalogue.x2009.xml.rest.ServiceTechnologyType.Enum; -import org.biocatalogue.x2009.xml.rest.SoapOperation.Ancestors; - - -/** - * - * - * @author Sergejs Aleksejevs - */ -@SuppressWarnings("serial") -public class SOAPOperationListCellRenderer extends ExpandableOnDemandLoadedListCellRenderer -{ - - private JLabel jlTypeIcon = new JLabel(); - private JLabel jlItemStatus = new JLabel(); - private JLabel jlItemTitle = new JLabel("X"); - private JLabel jlPartOf = new JLabel("X"); - private JLabel jlWsdlLocation = new JLabel("X"); - private ReadOnlyTextArea jtDescription = new ReadOnlyTextArea(5,80); - private JLabel jlSoapInputs = new JLabel("X"); - private JLabel jlSoapOutputs = new JLabel("X"); - - private GridBagConstraints c; - - private static Resource.TYPE resourceType = Resource.TYPE.SOAPOperation; - - - public SOAPOperationListCellRenderer() { - jlItemTitle.setFont(jlItemTitle.getFont().deriveFont(Font.PLAIN, jlItemTitle.getFont().getSize() + 2)); - jtDescription.setOpaque(false); - jtDescription.setLineWrap(true); - jtDescription.setWrapStyleWord(true); - } - - - /** - * This entry can be in one of two states: - * -- containing only the name of the resource and NOT loading further details; - * -- containing only the name of the resource and LOADING further details. - * - * @param itemToRender - * @return - */ - protected GridBagConstraints prepareInitiallyLoadingEntry(Object itemToRender) - { - LoadingResource resource = (LoadingResource)itemToRender; - - jlTypeIcon.setIcon(resourceType.getIcon()); - jlItemStatus.setIcon(ResourceManager.getImageIcon(ResourceManager.SERVICE_STATUS_UNCHECKED_ICON_LARGE)); - - jlItemTitle.setText("<html>" + StringEscapeUtils.escapeHtml(Resource.getDisplayNameForResource(resource)) + "<font color=\"gray\"><i>- fetching more information</i></font></html>"); - - jlPartOf.setText(" "); - jlWsdlLocation.setText(" "); - jtDescription.setText(""); - jlSoapInputs.setText(" "); - jlSoapOutputs.setText(" "); - - return (arrangeLayout()); - } - - - /** - * - * @param itemToRender - * @param selected - * @param expandedView <code>true</code> to indicate that this method generates the top - * fragment of the expanded list entry for this SOAP operation / REST method. - * @return - */ - protected GridBagConstraints prepareLoadedEntry(Object itemToRender, boolean selected) - { - SoapOperation soapOp = (SoapOperation)itemToRender; - - Ancestors ancestors = soapOp.getAncestors(); - SoapService soapService = ancestors.getSoapService(); - Service service = ancestors.getService(); - String title = StringEscapeUtils.escapeHtml(Resource.getDisplayNameForResource(soapOp)); - - if (soapOp.isSetArchived() || service.isSetArchived()) { - jlTypeIcon.setIcon(ResourceManager.getImageIcon(ResourceManager.WARNING_ICON)); - title = "<html>" + title + "<i> - this operation is archived and probably cannot be used</i></html>"; - } else if (isSoapLab(service)) { - jlTypeIcon.setIcon(ResourceManager.getImageIcon(ResourceManager.WARNING_ICON)); - title = "<html>" + title + "<i> - this operation can only be used as part of a SoapLab service</i></html>"; - } - else { - jlTypeIcon.setIcon(resourceType.getIcon()); - title = "<html>" + title + "</html>"; - } - - // service status - jlItemStatus.setIcon(ServiceMonitoringStatusInterpreter.getStatusIcon(service, false)); - jlItemTitle.setText(title); - - jlPartOf.setText("<html><b>Part of: </b>" + StringEscapeUtils.escapeHtml(soapOp.getAncestors().getSoapService().getResourceName()) + "</html>"); - - jlWsdlLocation.setText("<html><b>WSDL location: </b>" + soapService.getWsdlLocation() + "</html>"); - - String strDescription = (soapOp.getDescription() == null || soapOp.getDescription().length() == 0 ? - "No description" : - Util.stripAllHTML(soapOp.getDescription())); - - jtDescription.setText(strDescription); - - // add SOAP inputs - List<String> names = new ArrayList<String>(); - for (SoapInput soapInput : soapOp.getInputs().getSoapInputList()) { - names.add(soapInput.getName()); - } - - String soapInputs = "<b>" + names.size() + " " + Util.pluraliseNoun("Input", names.size()) + "</b>"; - if(names.size() > 0) { - soapInputs += ": " + StringEscapeUtils.escapeHtml(Util.ensureLineLengthWithinString(Util.join(names, ", "), LINE_LENGTH, false)); - } - soapInputs = "<html>" + soapInputs + "</html>"; - jlSoapInputs.setText(soapInputs); - - c.gridy++; - this.add(jlSoapInputs, c); - - - // add SOAP outputs - names.clear(); - for (SoapOutput soapOutput : soapOp.getOutputs().getSoapOutputList()) { - names.add(soapOutput.getName()); - } - - String soapOutputs = "<b>" + names.size() + " " + Util.pluraliseNoun("Output", names.size()) + "</b>"; - if(names.size() > 0) { - soapOutputs += ": " + StringEscapeUtils.escapeHtml(Util.ensureLineLengthWithinString(Util.join(names, ", "), LINE_LENGTH, false)); - } - soapOutputs = "<html>" + soapOutputs + "</html>"; - jlSoapOutputs.setText(soapOutputs); - - return (arrangeLayout()); - } - - -private boolean isSoapLab(Service service) { - boolean result = false; - ServiceTechnologyTypes serviceTechnologyTypes = service.getServiceTechnologyTypes(); - if (serviceTechnologyTypes == null) { - return result; - } - List<Enum> typeList = serviceTechnologyTypes.getTypeList(); - if (typeList == null) { - return result; - } - result = typeList.contains(ServiceTechnologyType.SOAPLAB); - return result; -} - - - /** - * @return Final state of the {@link GridBagConstraints} instance - * that was used to lay out components in the panel. - */ - private GridBagConstraints arrangeLayout() - { - // POPULATE PANEL WITH PREPARED COMPONENTS - this.setLayout(new GridBagLayout()); - c = new GridBagConstraints(); - c.anchor = GridBagConstraints.NORTHWEST; - c.fill = GridBagConstraints.HORIZONTAL; - - c.gridx = 0; - c.gridy = 0; - c.weightx = 0; - c.insets = new Insets(8, 6, 6, 3); - this.add(jlTypeIcon, c); - - c.gridx++; - c.weightx = 1.0; - c.insets = new Insets(8, 3, 6, 3); - this.add(jlItemTitle, c); - - c.gridx++; - c.gridheight = 7; - c.weightx = 0; - c.weighty = 1.0; - this.add(jlItemStatus, c); - - c.gridx = 1; - c.gridy++; - c.gridheight = 1; - c.weightx = 0; - c.weighty = 0; - this.add(jlPartOf, c); - - c.gridy++; - this.add(jlWsdlLocation, c); - - c.fill = GridBagConstraints.NONE; - c.gridy++; - this.add(jtDescription, c); - - c.fill = GridBagConstraints.HORIZONTAL; - c.gridy++; - this.add(jlSoapInputs, c); - - c.fill = GridBagConstraints.HORIZONTAL; - c.gridy++; - this.add(jlSoapOutputs, c); - - return (c); - } - -@Override -boolean shouldBeHidden(Object itemToRender) { - if (!(itemToRender instanceof SoapOperation)) { - return false; - } - SoapOperation soapOp = (SoapOperation) itemToRender; - Ancestors ancestors = soapOp.getAncestors(); - Service service = ancestors.getService(); - if (soapOp.isSetArchived() || service.isSetArchived()) { - return true; - } else if (isSoapLab(service)) { - return true; - } - else { - return false; - } - -} - -}