http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-activity-palette-ui/src/main/java/org/apache/taverna/workbench/ui/servicepanel/tree/TreePanel.java ---------------------------------------------------------------------- diff --git a/taverna-activity-palette-ui/src/main/java/org/apache/taverna/workbench/ui/servicepanel/tree/TreePanel.java b/taverna-activity-palette-ui/src/main/java/org/apache/taverna/workbench/ui/servicepanel/tree/TreePanel.java new file mode 100644 index 0000000..4fcc6cf --- /dev/null +++ b/taverna-activity-palette-ui/src/main/java/org/apache/taverna/workbench/ui/servicepanel/tree/TreePanel.java @@ -0,0 +1,370 @@ +/* +* 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. +*/ + +package org.apache.taverna.workbench.ui.servicepanel.tree; + +import static java.awt.BorderLayout.CENTER; +import static java.awt.BorderLayout.NORTH; +import static java.awt.BorderLayout.WEST; +import static java.awt.Color.GRAY; +import static java.awt.GridBagConstraints.HORIZONTAL; +import static java.awt.GridBagConstraints.NONE; +import static javax.swing.SwingUtilities.invokeLater; +import static org.apache.taverna.lang.ui.EdgeLineBorder.TOP; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import javax.swing.event.TreeExpansionEvent; +import javax.swing.event.TreeExpansionListener; +import javax.swing.tree.TreeCellRenderer; +import javax.swing.tree.TreePath; + +import org.apache.taverna.lang.ui.EdgeLineBorder; + +import org.apache.log4j.Logger; + +@SuppressWarnings("serial") +public abstract class TreePanel extends JPanel { + private static int MAX_EXPANSION = 100; + private static final int SEARCH_WIDTH = 15; + private static Logger logger = Logger.getLogger(TreePanel.class); + + protected Set<List<Object>> expandedPaths = new HashSet<>(); + protected FilterTreeModel filterTreeModel; + protected JTextField searchField = new JTextField(SEARCH_WIDTH); + protected JTree tree = new JTree(); + protected JScrollPane treeScrollPane; + + private String availableObjectsString = ""; + private String matchingObjectsString = ""; + private String noMatchingObjectsString = ""; + + private TreeExpandCollapseListener treeExpandListener = new TreeExpandCollapseListener(); + private Object filterLock = new Object(); + + public TreePanel(FilterTreeModel treeModel) { + filterTreeModel = treeModel; + } + + public void expandTreePaths() throws InterruptedException, + InvocationTargetException { +// Filter appliedFilter = filterTreeModel.getCurrentFilter(); +// if (appliedFilter == null) { + for (int i = 0; (i < tree.getRowCount()) && (i < MAX_EXPANSION); i++) + tree.expandRow(i); +// } else { +// boolean rowsFinished = false; +// for (int i = 0; (!appliedFilter.isSuperseded()) && (!rowsFinished) +// && (i < MAX_EXPANSION); i++) { +// TreePath tp = tree.getPathForRow(i); +// if (tp == null) { +// rowsFinished = true; +// } else { +// if (!appliedFilter.pass((DefaultMutableTreeNode) tp +// .getLastPathComponent())) { +// tree.expandRow(i); +// } +// } +// } +// } + } + + public void expandAll(FilterTreeNode node, boolean expand) { + @SuppressWarnings("unused") + FilterTreeNode root = (FilterTreeNode) tree.getModel().getRoot(); + + // Traverse tree from root + expandAll(new TreePath(node.getPath()), expand); + } + + @SuppressWarnings("rawtypes") + private void expandAll(TreePath parent, boolean expand) { + // Traverse children + FilterTreeNode node = (FilterTreeNode) parent.getLastPathComponent(); + if (node.getChildCount() >= 0) + for (Enumeration e=node.children(); e.hasMoreElements(); ) { + FilterTreeNode n = (FilterTreeNode) e.nextElement(); + TreePath path = parent.pathByAddingChild(n); + expandAll(path, expand); + } + + // Expansion or collapse must be done bottom-up + if (expand) + tree.expandPath(parent); + else + tree.collapsePath(parent); + } + + protected void initialize() { + setLayout(new BorderLayout()); + treeScrollPane = new JScrollPane(tree); + tree.setModel(filterTreeModel); + tree.addTreeExpansionListener(treeExpandListener); + tree.setCellRenderer(createCellRenderer()); + tree.setSelectionModel(new FilterTreeSelectionModel()); + + JPanel topPanel = new JPanel(); + topPanel.setBorder(new CompoundBorder(new EdgeLineBorder(TOP, GRAY), new EmptyBorder(10, 5, 0, 5))); + topPanel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + JLabel filterLabel = new JLabel("Filter: "); + c.fill = NONE; + c.gridx = 0; + c.gridy = 0; + c.weightx = 0.0; + c.anchor = GridBagConstraints.LINE_START; + topPanel.add(filterLabel, c); + + c.fill = HORIZONTAL; + c.gridx = 1; + c.gridy = 0; + c.weightx = 1.0; + topPanel.add(searchField, c); + + + c.fill = NONE; + c.gridx = 2; + c.gridy = 0; + c.weightx = 0.0; + final JButton clearButton = new JButton("Clear"); + clearButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + searchField.setText(""); + invokeLater(new RunFilter()); + clearButton.getParent().requestFocusInWindow();// so that the button does not stay focused after it is clicked on and did its action + } + }); + topPanel.add(clearButton, c); + + c.gridx = 3; + c.weightx = 0.2; + topPanel.add(new JPanel(), c); + + JPanel topExtraPanel = new JPanel(new BorderLayout()); + + topExtraPanel.add(topPanel, NORTH); + + Component extraComponent = createExtraComponent(); + if (extraComponent != null) { + JPanel extraPanel = new JPanel(); + extraPanel.setLayout(new BorderLayout()); + extraPanel.add(extraComponent, WEST); + topExtraPanel.add(extraPanel, CENTER); + } + + add(topExtraPanel, NORTH); + add(treeScrollPane, CENTER); + + searchField.addKeyListener(new SearchFieldKeyAdapter()); + } + + protected Component createExtraComponent() { + return null; + } + + protected TreeCellRenderer createCellRenderer() { + return new FilterTreeCellRenderer(); + } + + public void runFilter() throws InterruptedException, + InvocationTargetException { + /* + * Special lock object, don't do a synchronized model, as the lock on + * JComponent might deadlock when painting the panel - see comments at + * http://www.mygrid.org.uk/dev/issues/browse/T2-1438 + */ + synchronized (filterLock) { + tree.removeTreeExpansionListener(treeExpandListener); + String text = searchField.getText(); + FilterTreeNode root = (FilterTreeNode) tree.getModel().getRoot(); + if (text.isEmpty()) { + setFilter(null); + root.setUserObject(getAvailableObjectsString()); + filterTreeModel.nodeChanged(root); + for (List<Object> tp : expandedPaths) { + // for (int i = 0; i < tp.length; i++) + // logger.info("Trying to expand " + tp[i]); + tree.expandPath(filterTreeModel.getTreePathForObjectPath(tp)); + } + } else { + setFilter(createFilter(text)); + root.setUserObject(root.getChildCount() > 0 ? getMatchingObjectsString() + : getNoMatchingObjectsString()); + filterTreeModel.nodeChanged(root); + expandTreePaths(); + } + tree.addTreeExpansionListener(treeExpandListener); + } + } + + /** + * @return the availableObjectsString + */ + public String getAvailableObjectsString() { + return availableObjectsString; + } + + /** + * @param availableObjectsString the availableObjectsString to set + */ + public void setAvailableObjectsString(String availableObjectsString) { + this.availableObjectsString = availableObjectsString; + } + + /** + * @return the matchingObjectsString + */ + public String getMatchingObjectsString() { + return matchingObjectsString; + } + + /** + * @param matchingObjectsString the matchingObjectsString to set + */ + public void setMatchingObjectsString(String matchingObjectsString) { + this.matchingObjectsString = matchingObjectsString; + } + + /** + * @return the noMatchingObjectsString + */ + public String getNoMatchingObjectsString() { + return noMatchingObjectsString; + } + + /** + * @param noMatchingObjectsString the noMatchingObjectsString to set + */ + public void setNoMatchingObjectsString(String noMatchingObjectsString) { + this.noMatchingObjectsString = noMatchingObjectsString; + } + + public Filter createFilter(String text) { + return new MyFilter(text); + } + + public void setFilter(Filter filter) { + if (tree.getCellRenderer() instanceof FilterTreeCellRenderer) + ((FilterTreeCellRenderer)tree.getCellRenderer()).setFilter(filter); + filterTreeModel.setFilter(filter); + } + + protected class ExpandRowRunnable implements Runnable { + int rowNumber; + + public ExpandRowRunnable(int rowNumber) { + this.rowNumber = rowNumber; + } + + @Override + public void run() { + tree.expandRow(rowNumber); + } + } + + protected class RunFilter implements Runnable { + @Override + public void run() { + Filter oldFilter = filterTreeModel.getCurrentFilter(); + if (oldFilter != null) + oldFilter.setSuperseded(true); + try { + runFilter(); + } catch (InterruptedException e) { + Thread.interrupted(); + } catch (InvocationTargetException e) { + logger.error("", e); + } + } + } + + protected class SearchFieldKeyAdapter extends KeyAdapter { + private final Runnable runFilterRunnable; + Timer timer = new Timer("Search field timer", true); + + private SearchFieldKeyAdapter() { + this.runFilterRunnable = new RunFilter(); + } + + @Override + public void keyReleased(KeyEvent e) { + timer.cancel(); + timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + invokeLater(runFilterRunnable); + } + }, 500); + } + } + + private void noteExpansions() { + expandedPaths.clear(); + TreePath rootPath = new TreePath(filterTreeModel.getRoot()); + for (Enumeration<TreePath> e = tree.getExpandedDescendants(rootPath); e.hasMoreElements();) { + List<Object> userObjects = new ArrayList<>(); + Object[] expandedPath = e.nextElement().getPath(); + for (int i = 0; i < expandedPath.length; i++) { + FilterTreeNode node = (FilterTreeNode) expandedPath[i]; +// logger.info("The object in the path is a " + expandedPath[i].getClass()); + userObjects.add(node.getUserObject()); +// logger.info("Added " + node.getUserObject() + " to path"); + } + expandedPaths.add(userObjects); + } + } + + protected class TreeExpandCollapseListener implements TreeExpansionListener { + @Override + public void treeCollapsed(TreeExpansionEvent event) { + noteExpansions(); + } + + @Override + public void treeExpanded(TreeExpansionEvent event) { + noteExpansions(); + } + } +}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-activity-palette-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.zaria.UIComponentFactorySPI ---------------------------------------------------------------------- diff --git a/taverna-activity-palette-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.zaria.UIComponentFactorySPI b/taverna-activity-palette-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.zaria.UIComponentFactorySPI deleted file mode 100644 index bb87331..0000000 --- a/taverna-activity-palette-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.zaria.UIComponentFactorySPI +++ /dev/null @@ -1 +0,0 @@ -net.sf.taverna.t2.workbench.ui.servicepanel.ServicePanelComponentFactory \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-activity-palette-ui/src/main/resources/META-INF/services/org.apache.taverna.workbench.ui.zaria.UIComponentFactorySPI ---------------------------------------------------------------------- diff --git a/taverna-activity-palette-ui/src/main/resources/META-INF/services/org.apache.taverna.workbench.ui.zaria.UIComponentFactorySPI b/taverna-activity-palette-ui/src/main/resources/META-INF/services/org.apache.taverna.workbench.ui.zaria.UIComponentFactorySPI new file mode 100644 index 0000000..a914820 --- /dev/null +++ b/taverna-activity-palette-ui/src/main/resources/META-INF/services/org.apache.taverna.workbench.ui.zaria.UIComponentFactorySPI @@ -0,0 +1 @@ +org.apache.taverna.workbench.ui.servicepanel.ServicePanelComponentFactory \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context-osgi.xml ---------------------------------------------------------------------- diff --git a/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context-osgi.xml b/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context-osgi.xml index 2d96b28..73e3fbe 100644 --- a/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context-osgi.xml +++ b/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context-osgi.xml @@ -8,13 +8,13 @@ <service ref="ServiceDescriptionConfigUIFactory" interface="uk.org.taverna.configuration.ConfigurationUIFactory" /> - <service ref="ServicePanelComponentFactory" interface="net.sf.taverna.t2.workbench.ui.zaria.UIComponentFactorySPI" /> + <service ref="ServicePanelComponentFactory" interface="org.apache.taverna.workbench.ui.zaria.UIComponentFactorySPI" /> - <reference id="editManager" interface="net.sf.taverna.t2.workbench.edits.EditManager" /> - <reference id="menuManager" interface="net.sf.taverna.t2.ui.menu.MenuManager" /> - <reference id="selectionManager" interface="net.sf.taverna.t2.workbench.selection.SelectionManager" /> - <reference id="serviceDescriptionRegistry" interface="net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry"/> - <reference id="serviceDescriptionsConfiguration" interface="net.sf.taverna.t2.servicedescriptions.ServiceDescriptionsConfiguration"/> + <reference id="editManager" interface="org.apache.taverna.workbench.edits.EditManager" /> + <reference id="menuManager" interface="org.apache.taverna.ui.menu.MenuManager" /> + <reference id="selectionManager" interface="org.apache.taverna.workbench.selection.SelectionManager" /> + <reference id="serviceDescriptionRegistry" interface="org.apache.taverna.servicedescriptions.ServiceDescriptionRegistry"/> + <reference id="serviceDescriptionsConfiguration" interface="org.apache.taverna.servicedescriptions.ServiceDescriptionsConfiguration"/> <reference id="serviceRegistry" interface="uk.org.taverna.commons.services.ServiceRegistry" /> </beans:beans> http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context.xml ---------------------------------------------------------------------- diff --git a/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context.xml b/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context.xml index f0a11c1..fdb40db 100644 --- a/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context.xml +++ b/taverna-activity-palette-ui/src/main/resources/META-INF/spring/activity-palette-ui-context.xml @@ -5,13 +5,13 @@ http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="ServiceDescriptionConfigUIFactory" - class="net.sf.taverna.t2.workbench.ui.servicepanel.config.ServiceDescriptionConfigUIFactory"> + class="org.apache.taverna.workbench.ui.servicepanel.config.ServiceDescriptionConfigUIFactory"> <property name="serviceDescriptionRegistry" ref="serviceDescriptionRegistry" /> <property name="serviceDescriptionsConfiguration" ref="serviceDescriptionsConfiguration" /> </bean> <bean id="ServicePanelComponentFactory" - class="net.sf.taverna.t2.workbench.ui.servicepanel.ServicePanelComponentFactory"> + class="org.apache.taverna.workbench.ui.servicepanel.ServicePanelComponentFactory"> <property name="editManager" ref="editManager" /> <property name="menuManager" ref="menuManager" /> <property name="selectionManager" ref="selectionManager" /> http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-activity-tools/src/main/java/net/sf/taverna/t2/workbench/activitytools/AbstractConfigureActivityMenuAction.java ---------------------------------------------------------------------- diff --git a/taverna-activity-tools/src/main/java/net/sf/taverna/t2/workbench/activitytools/AbstractConfigureActivityMenuAction.java b/taverna-activity-tools/src/main/java/net/sf/taverna/t2/workbench/activitytools/AbstractConfigureActivityMenuAction.java deleted file mode 100644 index 8ca91e8..0000000 --- a/taverna-activity-tools/src/main/java/net/sf/taverna/t2/workbench/activitytools/AbstractConfigureActivityMenuAction.java +++ /dev/null @@ -1,64 +0,0 @@ -package net.sf.taverna.t2.workbench.activitytools; - -import static javax.swing.Action.NAME; - -import java.awt.Frame; -import java.net.URI; - -import javax.swing.Action; - -import org.apache.taverna.scufl2.api.activity.Activity; -import org.apache.taverna.scufl2.api.common.Scufl2Tools; -import org.apache.taverna.scufl2.api.core.Processor; -import org.apache.taverna.scufl2.api.profiles.ProcessorBinding; -import org.apache.taverna.scufl2.api.profiles.Profile; -import net.sf.taverna.t2.ui.menu.AbstractContextualMenuAction; -import net.sf.taverna.t2.workbench.ui.Utils; - -public abstract class AbstractConfigureActivityMenuAction extends AbstractContextualMenuAction { - private static final URI configureSection = URI - .create("http://taverna.sf.net/2009/contextMenu/configure"); - - protected Scufl2Tools scufl2Tools = new Scufl2Tools(); - protected final URI activityType; - - public AbstractConfigureActivityMenuAction(URI activityType) { - super(configureSection, 50); - this.activityType = activityType; - } - - @Override - public boolean isEnabled() { - return super.isEnabled() && findActivity() != null; - } - - protected Activity findActivity() { - if (getContextualSelection() == null) - return null; - Object selection = getContextualSelection().getSelection(); - if (selection instanceof Activity) { - Activity activity = (Activity) selection; - if (activity.getType().equals(activityType)) - return activity; - } - if (selection instanceof Processor) { - Processor processor = (Processor) selection; - Profile profile = processor.getParent().getParent().getMainProfile(); - for (ProcessorBinding processorBinding : scufl2Tools.processorBindingsForProcessor(processor, profile)) - if (processorBinding.getBoundActivity().getType().equals(activityType)) - return processorBinding.getBoundActivity(); - } - return null; - } - - protected Frame getParentFrame() { - return Utils.getParentFrame(getContextualSelection() - .getRelativeToComponent()); - } - - protected void addMenuDots(Action configAction) { - String oldName = (String) configAction.getValue(NAME); - if (!oldName.endsWith("..")) - configAction.putValue(NAME, oldName + "..."); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-activity-tools/src/main/java/org/apache/taverna/workbench/activitytools/AbstractConfigureActivityMenuAction.java ---------------------------------------------------------------------- diff --git a/taverna-activity-tools/src/main/java/org/apache/taverna/workbench/activitytools/AbstractConfigureActivityMenuAction.java b/taverna-activity-tools/src/main/java/org/apache/taverna/workbench/activitytools/AbstractConfigureActivityMenuAction.java new file mode 100644 index 0000000..a3660cf --- /dev/null +++ b/taverna-activity-tools/src/main/java/org/apache/taverna/workbench/activitytools/AbstractConfigureActivityMenuAction.java @@ -0,0 +1,83 @@ +/* +* 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. +*/ + +package org.apache.taverna.workbench.activitytools; + +import static javax.swing.Action.NAME; + +import java.awt.Frame; +import java.net.URI; + +import javax.swing.Action; + +import org.apache.taverna.scufl2.api.activity.Activity; +import org.apache.taverna.scufl2.api.common.Scufl2Tools; +import org.apache.taverna.scufl2.api.core.Processor; +import org.apache.taverna.scufl2.api.profiles.ProcessorBinding; +import org.apache.taverna.scufl2.api.profiles.Profile; +import org.apache.taverna.ui.menu.AbstractContextualMenuAction; +import org.apache.taverna.workbench.ui.Utils; + +public abstract class AbstractConfigureActivityMenuAction extends AbstractContextualMenuAction { + private static final URI configureSection = URI + .create("http://taverna.sf.net/2009/contextMenu/configure"); + + protected Scufl2Tools scufl2Tools = new Scufl2Tools(); + protected final URI activityType; + + public AbstractConfigureActivityMenuAction(URI activityType) { + super(configureSection, 50); + this.activityType = activityType; + } + + @Override + public boolean isEnabled() { + return super.isEnabled() && findActivity() != null; + } + + protected Activity findActivity() { + if (getContextualSelection() == null) + return null; + Object selection = getContextualSelection().getSelection(); + if (selection instanceof Activity) { + Activity activity = (Activity) selection; + if (activity.getType().equals(activityType)) + return activity; + } + if (selection instanceof Processor) { + Processor processor = (Processor) selection; + Profile profile = processor.getParent().getParent().getMainProfile(); + for (ProcessorBinding processorBinding : scufl2Tools.processorBindingsForProcessor(processor, profile)) + if (processorBinding.getBoundActivity().getType().equals(activityType)) + return processorBinding.getBoundActivity(); + } + return null; + } + + protected Frame getParentFrame() { + return Utils.getParentFrame(getContextualSelection() + .getRelativeToComponent()); + } + + protected void addMenuDots(Action configAction) { + String oldName = (String) configAction.getValue(NAME); + if (!oldName.endsWith("..")) + configAction.putValue(NAME, oldName + "..."); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotated.java ---------------------------------------------------------------------- diff --git a/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotated.java b/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotated.java deleted file mode 100644 index aa59e68..0000000 --- a/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotated.java +++ /dev/null @@ -1,74 +0,0 @@ -/********************************************************************** - * Copyright (C) 2009 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - **********************************************************************/ -package net.sf.taverna.t2.lang.beans; - -import java.beans.BeanInfo; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.beans.SimpleBeanInfo; - -/** - * A {@link BeanInfo} that includes {@link PropertyDescriptor}s from methods - * annotated using {@link PropertyAnnotation}. - * <p> - * The bean info from the PropertyAnnotation will then be available through - * Java's {@link Introspector}, and allows you to specify details such as - * {@link PropertyAnnotation#displayName()} and - * {@link PropertyAnnotation#hidden()} for the properties of a Java Bean. - * <p> - * This class can either be used as a superclass for the classes containing - * property annotated methods, or put in a neighbouring BeanInfo class. - * <p> - * For instance, if your class is called DescribedClass and has methods - * annotated using {@link PropertyAnnotation}, either let DescribedClass - * subclass {@link PropertyAnnotated}, or make a neighbouring {@link BeanInfo} - * class called DescribedClassBeanInfo, which should subclass - * {@link PropertyAnnotated}. - * - * - * @author Stian Soiland-Reyes - * - */ -public class PropertyAnnotated extends SimpleBeanInfo { - - private static PropertyAnnotationExtractor extractor = new PropertyAnnotationExtractor(); - - /** - * {@inheritDoc} - */ - @Override - public PropertyDescriptor[] getPropertyDescriptors() { - return extractor.getPropertyDescriptors(getDescribedClass()); - } - - /** - * The class that is being described. By default this returns - * {@link #getClass()} so that {@link PropertyAnnotated} can be used as a - * superclass, but if instead the DescribedClassBeanInfo pattern is used, - * subclass PropertyAnnotated in each BeanInfo class, and override this - * method to return the described class. (DescribedClass in this example) - * - */ - public Class<?> getDescribedClass() { - return getClass(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotation.java ---------------------------------------------------------------------- diff --git a/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotation.java b/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotation.java deleted file mode 100644 index 5923a21..0000000 --- a/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotation.java +++ /dev/null @@ -1,109 +0,0 @@ -/********************************************************************** - * Copyright (C) 2009 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - **********************************************************************/ -package net.sf.taverna.t2.lang.beans; - -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation of a Java bean style property method, ie. a getXX() or setXX() - * method. - * <p> - * The annotations allow the method to better describe properties such as - * {@link #displayName()}, {@link #shortDescription()} and {@link #hidden()}. - * <p> - * The annotations can be retrieved as {@link PropertyDescriptor} using - * {@link PropertyAnnotationExtractor}, or if {@link PropertyAnnotated} has been - * used (recommended), through Java's BeanInfo support, such as using - * {@link Introspector}. - * <p> - * Annotations can be applied to interfaces or classes, abstract and normal - * methods, as long as they confirm with the Java bean conventions. Annotations - * will be inherited, so overriding methods don't need to reapply the annotations, - * although they can if they want to override. - * <p> - * It is recommended that classes using these annotations either subclass - * {@link PropertyAnnotated} or have a neighbouring BeanInfo class that - * subclasses PropertyAnnotated. - * <p> - * Example usage: - * - * <pre> - * public interface MyBean { - * // Annotation for the property called "name". displayName: Title - * // of the property shown in UI instead of "name". - * @PropertyAnnotation(displayName = "Full name") - * public String getName(); - * - * // Second annotation for the write-method of the same property called - * // "name". Both displayName and shortDescription will be set on the - * // property descriptor. - * @PropertyAnnotation(shortDescription = "The name of the person") - * public void setName(String name); - * - * // Boolean read method for the property "married", two annotations. - * // expert: Only shown in UI under "advanced" views. - * @PropertyAnnotation(expert = true, shortDescription = "Marital status") - * public boolean isMarried(); - * - * // Write-method for the "married" property, no new annotations, but will - * // get the ones from {@link #isMarried()}. - * public void setMarried(boolean married); - * - * // Write-only method, hidden (not shown in UIs). - * @PropertyAnnotation(hidden = true) - * public void setID(String id); - * - * // Read-only method, no annotations, defaults will be used. - * public void getTelephoneNumber(String number); - * } - * </pre> - * - * @see PropertyAnnotated - * @author Stian Soiland-Reyes - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target( { ElementType.METHOD }) -public @interface PropertyAnnotation { - - /** - * A unique string that means the default should be used - */ - public static String DEFAULT = "Default_8930B86A-50C0-4859-9B6F-DD034B3C5C1E"; - - String displayName() default DEFAULT; - - String name() default DEFAULT; - - String shortDescription() default DEFAULT; - - boolean expert() default false; - - boolean hidden() default false; - - boolean preferred() default false; - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotationExtractor.java ---------------------------------------------------------------------- diff --git a/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotationExtractor.java b/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotationExtractor.java deleted file mode 100644 index 4524822..0000000 --- a/taverna-beaninfo/src/main/java/net/sf/taverna/t2/lang/beans/PropertyAnnotationExtractor.java +++ /dev/null @@ -1,202 +0,0 @@ -/********************************************************************** - * Copyright (C) 2009 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - **********************************************************************/ -package net.sf.taverna.t2.lang.beans; - -import java.beans.IntrospectionException; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.WeakHashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A utility class for extracting {@link PropertyDescriptor}s from a class which - * methods have been described using {@link PropertyAnnotation}. - * - * @author Stian Soiland-Reyes - * - */ -public class PropertyAnnotationExtractor { - - protected static Pattern methodPattern = Pattern - .compile("(get|is|set)(.+)"); - - protected WeakHashMap<Class<?>, List<Method>> allMethodsCache = new WeakHashMap<Class<?>, List<Method>>(); - - protected WeakHashMap<Class<?>, PropertyDescriptor[]> propertyDescriptorsCache = new WeakHashMap<Class<?>, PropertyDescriptor[]>(); - - @SuppressWarnings("unchecked") - protected List<Class> ignoreClasses = Arrays.<Class>asList(Class.class, Object.class, PropertyAnnotated.class); - - /** - * Find PropertyDescriptors for the given bean class based on descriptions - * using {@link PropertyAnnotation}s. - * <p> - * Annotations will be inherited from interfaces and superclasses. - * - * @param beanClass - * @return Array of {@link PropertyDescriptor} - */ - public PropertyDescriptor[] getPropertyDescriptors(Class<?> beanClass) { - PropertyDescriptor[] cached = propertyDescriptorsCache.get(beanClass); - if (cached != null) { - return cached; - } - - Map<String, PropertyDescriptor> descriptors = new HashMap<String, PropertyDescriptor>(); - - for (Method method : allMethods(beanClass)) { - PropertyAnnotation annotation = method - .getAnnotation(PropertyAnnotation.class); - Matcher methodMatcher = methodPattern.matcher(method.getName()); - if (!methodMatcher.matches() && annotation == null) { - continue; - } - - String name = PropertyAnnotation.DEFAULT; - if (annotation != null) { - annotation.name(); - } - if (name.equals(PropertyAnnotation.DEFAULT)) { - name = methodMatcher.group(2); - if (name.length() < 1) { - continue; - } - // decapitalize first letter - name = name.substring(0, 1).toLowerCase() + name.substring(1); - } - Method writeMethod = null; - Method readMethod = null; - if (methodMatcher.group(1).equals("set")) { - writeMethod = method; - if (writeMethod.getParameterTypes().length != 1) { - continue; - } - } else { - readMethod = method; - if (readMethod.getParameterTypes().length != 0) { - continue; - } - } - - PropertyDescriptor descriptor = descriptors.get(name); - try { - if (descriptor == null) { - descriptor = new PropertyDescriptor(name, readMethod, - writeMethod); - descriptors.put(name, descriptor); - } - // Set the one we just found - if (readMethod != null) { - descriptor.setReadMethod(readMethod); - } - if (writeMethod != null) { - descriptor.setWriteMethod(writeMethod); - } - } catch (IntrospectionException ex) { - throw new RuntimeException("Can't inspect property " + name - + " using method " + method, ex); - } - if (annotation != null) { - descriptor.setExpert(annotation.expert()); - descriptor.setHidden(annotation.hidden()); - descriptor.setPreferred(annotation.preferred()); - if (!annotation.displayName() - .equals(PropertyAnnotation.DEFAULT)) { - descriptor.setDisplayName(annotation.displayName()); - } - if (!annotation.shortDescription().equals( - PropertyAnnotation.DEFAULT)) { - descriptor.setShortDescription(annotation - .shortDescription()); - } - } - } - cached = descriptors.values().toArray( - new PropertyDescriptor[descriptors.size()]); - propertyDescriptorsCache.put(beanClass, cached); - return cached; - } - - /** - * Find all {@link Method}s defined in the class, all its superclasses and - * interfaces. This might include methods that override each other. - * <p> - * The list contains first the methods from each of the class's interfaces - * (and the methods they inherit from their interfaces), then recurses for - * the subclass of this class (including any additional interfaces used in - * the superclasses), before finally adding methods declared in the given - * class. - * <p> - * This can be useful to find annotations given to methods that have been - * overridden in subclasses. - * - * @param theClass - * @return - */ - @SuppressWarnings("unchecked") - protected List<Method> allMethods(Class<?> theClass) { - List<Method> methods = allMethodsCache.get(theClass); - if (methods == null) { - methods = new ArrayList<Method>(); - allMethods(theClass, new HashSet<Class>(ignoreClasses), methods); - allMethodsCache.put(theClass, methods); - } - return methods; - } - - @SuppressWarnings("unchecked") - protected void allMethods(Class<?> theClass, Set<Class> visitedClasses, - List<Method> foundMethods) { - if (theClass == null || theClass == Object.class - || theClass == Class.class || !visitedClasses.add(theClass)) { - // Top class or already visted - return; - } - // Let's first dig down into our interfaces - for (Class anInterface : theClass.getInterfaces()) { - allMethods(anInterface, visitedClasses, foundMethods); - } - // And our superclasses - allMethods(theClass.getSuperclass(), visitedClasses, foundMethods); - // Before we find any methods only declared in this class - // (parent methods are already earlier in the list - - // note that the new methods might override earlier methods) - for (Method method : theClass.getDeclaredMethods()) { - int methodModifiers = method.getModifiers(); - if (!Modifier.isPublic(methodModifiers) - || Modifier.isStatic(methodModifiers)) { - continue; - } - assert !foundMethods.contains(method) : "Method discovered twice: " - + method; - foundMethods.add(method); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotated.java ---------------------------------------------------------------------- diff --git a/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotated.java b/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotated.java new file mode 100644 index 0000000..65febbc --- /dev/null +++ b/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotated.java @@ -0,0 +1,73 @@ +/* +* 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. +*/ + +package org.apache.taverna.lang.beans; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.beans.SimpleBeanInfo; + +/** + * A {@link BeanInfo} that includes {@link PropertyDescriptor}s from methods + * annotated using {@link PropertyAnnotation}. + * <p> + * The bean info from the PropertyAnnotation will then be available through + * Java's {@link Introspector}, and allows you to specify details such as + * {@link PropertyAnnotation#displayName()} and + * {@link PropertyAnnotation#hidden()} for the properties of a Java Bean. + * <p> + * This class can either be used as a superclass for the classes containing + * property annotated methods, or put in a neighbouring BeanInfo class. + * <p> + * For instance, if your class is called DescribedClass and has methods + * annotated using {@link PropertyAnnotation}, either let DescribedClass + * subclass {@link PropertyAnnotated}, or make a neighbouring {@link BeanInfo} + * class called DescribedClassBeanInfo, which should subclass + * {@link PropertyAnnotated}. + * + * + * @author Stian Soiland-Reyes + * + */ +public class PropertyAnnotated extends SimpleBeanInfo { + + private static PropertyAnnotationExtractor extractor = new PropertyAnnotationExtractor(); + + /** + * {@inheritDoc} + */ + @Override + public PropertyDescriptor[] getPropertyDescriptors() { + return extractor.getPropertyDescriptors(getDescribedClass()); + } + + /** + * The class that is being described. By default this returns + * {@link #getClass()} so that {@link PropertyAnnotated} can be used as a + * superclass, but if instead the DescribedClassBeanInfo pattern is used, + * subclass PropertyAnnotated in each BeanInfo class, and override this + * method to return the described class. (DescribedClass in this example) + * + */ + public Class<?> getDescribedClass() { + return getClass(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotation.java ---------------------------------------------------------------------- diff --git a/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotation.java b/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotation.java new file mode 100644 index 0000000..06480fc --- /dev/null +++ b/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotation.java @@ -0,0 +1,108 @@ +/* +* 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. +*/ + +package org.apache.taverna.lang.beans; + +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * An annotation of a Java bean style property method, ie. a getXX() or setXX() + * method. + * <p> + * The annotations allow the method to better describe properties such as + * {@link #displayName()}, {@link #shortDescription()} and {@link #hidden()}. + * <p> + * The annotations can be retrieved as {@link PropertyDescriptor} using + * {@link PropertyAnnotationExtractor}, or if {@link PropertyAnnotated} has been + * used (recommended), through Java's BeanInfo support, such as using + * {@link Introspector}. + * <p> + * Annotations can be applied to interfaces or classes, abstract and normal + * methods, as long as they confirm with the Java bean conventions. Annotations + * will be inherited, so overriding methods don't need to reapply the annotations, + * although they can if they want to override. + * <p> + * It is recommended that classes using these annotations either subclass + * {@link PropertyAnnotated} or have a neighbouring BeanInfo class that + * subclasses PropertyAnnotated. + * <p> + * Example usage: + * + * <pre> + * public interface MyBean { + * // Annotation for the property called "name". displayName: Title + * // of the property shown in UI instead of "name". + * @PropertyAnnotation(displayName = "Full name") + * public String getName(); + * + * // Second annotation for the write-method of the same property called + * // "name". Both displayName and shortDescription will be set on the + * // property descriptor. + * @PropertyAnnotation(shortDescription = "The name of the person") + * public void setName(String name); + * + * // Boolean read method for the property "married", two annotations. + * // expert: Only shown in UI under "advanced" views. + * @PropertyAnnotation(expert = true, shortDescription = "Marital status") + * public boolean isMarried(); + * + * // Write-method for the "married" property, no new annotations, but will + * // get the ones from {@link #isMarried()}. + * public void setMarried(boolean married); + * + * // Write-only method, hidden (not shown in UIs). + * @PropertyAnnotation(hidden = true) + * public void setID(String id); + * + * // Read-only method, no annotations, defaults will be used. + * public void getTelephoneNumber(String number); + * } + * </pre> + * + * @see PropertyAnnotated + * @author Stian Soiland-Reyes + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target( { ElementType.METHOD }) +public @interface PropertyAnnotation { + + /** + * A unique string that means the default should be used + */ + public static String DEFAULT = "Default_8930B86A-50C0-4859-9B6F-DD034B3C5C1E"; + + String displayName() default DEFAULT; + + String name() default DEFAULT; + + String shortDescription() default DEFAULT; + + boolean expert() default false; + + boolean hidden() default false; + + boolean preferred() default false; + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotationExtractor.java ---------------------------------------------------------------------- diff --git a/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotationExtractor.java b/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotationExtractor.java new file mode 100644 index 0000000..3b640ca --- /dev/null +++ b/taverna-beaninfo/src/main/java/org/apache/taverna/lang/beans/PropertyAnnotationExtractor.java @@ -0,0 +1,201 @@ +/* +* 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. +*/ + +package org.apache.taverna.lang.beans; + +import java.beans.IntrospectionException; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.WeakHashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A utility class for extracting {@link PropertyDescriptor}s from a class which + * methods have been described using {@link PropertyAnnotation}. + * + * @author Stian Soiland-Reyes + * + */ +public class PropertyAnnotationExtractor { + + protected static Pattern methodPattern = Pattern + .compile("(get|is|set)(.+)"); + + protected WeakHashMap<Class<?>, List<Method>> allMethodsCache = new WeakHashMap<Class<?>, List<Method>>(); + + protected WeakHashMap<Class<?>, PropertyDescriptor[]> propertyDescriptorsCache = new WeakHashMap<Class<?>, PropertyDescriptor[]>(); + + @SuppressWarnings("unchecked") + protected List<Class> ignoreClasses = Arrays.<Class>asList(Class.class, Object.class, PropertyAnnotated.class); + + /** + * Find PropertyDescriptors for the given bean class based on descriptions + * using {@link PropertyAnnotation}s. + * <p> + * Annotations will be inherited from interfaces and superclasses. + * + * @param beanClass + * @return Array of {@link PropertyDescriptor} + */ + public PropertyDescriptor[] getPropertyDescriptors(Class<?> beanClass) { + PropertyDescriptor[] cached = propertyDescriptorsCache.get(beanClass); + if (cached != null) { + return cached; + } + + Map<String, PropertyDescriptor> descriptors = new HashMap<String, PropertyDescriptor>(); + + for (Method method : allMethods(beanClass)) { + PropertyAnnotation annotation = method + .getAnnotation(PropertyAnnotation.class); + Matcher methodMatcher = methodPattern.matcher(method.getName()); + if (!methodMatcher.matches() && annotation == null) { + continue; + } + + String name = PropertyAnnotation.DEFAULT; + if (annotation != null) { + annotation.name(); + } + if (name.equals(PropertyAnnotation.DEFAULT)) { + name = methodMatcher.group(2); + if (name.length() < 1) { + continue; + } + // decapitalize first letter + name = name.substring(0, 1).toLowerCase() + name.substring(1); + } + Method writeMethod = null; + Method readMethod = null; + if (methodMatcher.group(1).equals("set")) { + writeMethod = method; + if (writeMethod.getParameterTypes().length != 1) { + continue; + } + } else { + readMethod = method; + if (readMethod.getParameterTypes().length != 0) { + continue; + } + } + + PropertyDescriptor descriptor = descriptors.get(name); + try { + if (descriptor == null) { + descriptor = new PropertyDescriptor(name, readMethod, + writeMethod); + descriptors.put(name, descriptor); + } + // Set the one we just found + if (readMethod != null) { + descriptor.setReadMethod(readMethod); + } + if (writeMethod != null) { + descriptor.setWriteMethod(writeMethod); + } + } catch (IntrospectionException ex) { + throw new RuntimeException("Can't inspect property " + name + + " using method " + method, ex); + } + if (annotation != null) { + descriptor.setExpert(annotation.expert()); + descriptor.setHidden(annotation.hidden()); + descriptor.setPreferred(annotation.preferred()); + if (!annotation.displayName() + .equals(PropertyAnnotation.DEFAULT)) { + descriptor.setDisplayName(annotation.displayName()); + } + if (!annotation.shortDescription().equals( + PropertyAnnotation.DEFAULT)) { + descriptor.setShortDescription(annotation + .shortDescription()); + } + } + } + cached = descriptors.values().toArray( + new PropertyDescriptor[descriptors.size()]); + propertyDescriptorsCache.put(beanClass, cached); + return cached; + } + + /** + * Find all {@link Method}s defined in the class, all its superclasses and + * interfaces. This might include methods that override each other. + * <p> + * The list contains first the methods from each of the class's interfaces + * (and the methods they inherit from their interfaces), then recurses for + * the subclass of this class (including any additional interfaces used in + * the superclasses), before finally adding methods declared in the given + * class. + * <p> + * This can be useful to find annotations given to methods that have been + * overridden in subclasses. + * + * @param theClass + * @return + */ + @SuppressWarnings("unchecked") + protected List<Method> allMethods(Class<?> theClass) { + List<Method> methods = allMethodsCache.get(theClass); + if (methods == null) { + methods = new ArrayList<Method>(); + allMethods(theClass, new HashSet<Class>(ignoreClasses), methods); + allMethodsCache.put(theClass, methods); + } + return methods; + } + + @SuppressWarnings("unchecked") + protected void allMethods(Class<?> theClass, Set<Class> visitedClasses, + List<Method> foundMethods) { + if (theClass == null || theClass == Object.class + || theClass == Class.class || !visitedClasses.add(theClass)) { + // Top class or already visted + return; + } + // Let's first dig down into our interfaces + for (Class anInterface : theClass.getInterfaces()) { + allMethods(anInterface, visitedClasses, foundMethods); + } + // And our superclasses + allMethods(theClass.getSuperclass(), visitedClasses, foundMethods); + // Before we find any methods only declared in this class + // (parent methods are already earlier in the list - + // note that the new methods might override earlier methods) + for (Method method : theClass.getDeclaredMethods()) { + int methodModifiers = method.getModifiers(); + if (!Modifier.isPublic(methodModifiers) + || Modifier.isStatic(methodModifiers)) { + continue; + } + assert !foundMethods.contains(method) : "Method discovered twice: " + + method; + foundMethods.add(method); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/colour/ColourManager.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/colour/ColourManager.java b/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/colour/ColourManager.java deleted file mode 100644 index 4d5356f..0000000 --- a/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/colour/ColourManager.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2011 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.configuration.colour; - -import java.awt.Color; - -import uk.org.taverna.configuration.Configurable; - -/** - * @author David Withers - */ -public interface ColourManager extends Configurable { - /** - * Builds a Color that has been configured and associated with the given - * String (usually an object type). - * - * @return the associated Color, or if nothing is associated returns - * {@link Color#WHITE}. - */ - Color getPreferredColour(String itemKey); - - void setPreferredColour(String itemKey, Color colour); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/mimetype/MimeTypeManager.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/mimetype/MimeTypeManager.java b/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/mimetype/MimeTypeManager.java deleted file mode 100644 index f0ae0d3..0000000 --- a/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/mimetype/MimeTypeManager.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.configuration.mimetype; - -import java.util.Map; - -import uk.org.taverna.configuration.Configurable; - -public interface MimeTypeManager extends Configurable { - @Override - String getCategory(); - - @Override - Map<String, String> getDefaultPropertyMap(); - - @Override - String getUUID(); - - @Override - String getDisplayName(); - - @Override - String getFilePrefix(); -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/workbench/WorkbenchConfiguration.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/workbench/WorkbenchConfiguration.java b/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/workbench/WorkbenchConfiguration.java deleted file mode 100644 index 461ba5c..0000000 --- a/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/workbench/WorkbenchConfiguration.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2011 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.configuration.workbench; - -import uk.org.taverna.configuration.Configurable; - -/** - * @author David Withers - */ -public interface WorkbenchConfiguration extends Configurable { - boolean getCaptureConsole(); - - void setCaptureConsole(boolean captureConsole); - - boolean getWarnInternalErrors(); - - void setWarnInternalErrors(boolean warnInternalErrors); - - int getMaxMenuItems(); - - void setMaxMenuItems(int maxMenuItems); - - String getDotLocation(); - - void setDotLocation(String dotLocation); -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/workbench/ui/T2ConfigurationFrame.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/workbench/ui/T2ConfigurationFrame.java b/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/workbench/ui/T2ConfigurationFrame.java deleted file mode 100644 index 577484f..0000000 --- a/taverna-configuration-api/src/main/java/net/sf/taverna/t2/workbench/configuration/workbench/ui/T2ConfigurationFrame.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2013 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.configuration.workbench.ui; - -/** - * @author David Withers - */ -public interface T2ConfigurationFrame { - void showFrame(); - - void showConfiguration(String name); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/colour/ColourManager.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/colour/ColourManager.java b/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/colour/ColourManager.java new file mode 100644 index 0000000..b471722 --- /dev/null +++ b/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/colour/ColourManager.java @@ -0,0 +1,40 @@ +/* +* 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. +*/ + +package org.apache.taverna.workbench.configuration.colour; + +import java.awt.Color; + +import uk.org.taverna.configuration.Configurable; + +/** + * @author David Withers + */ +public interface ColourManager extends Configurable { + /** + * Builds a Color that has been configured and associated with the given + * String (usually an object type). + * + * @return the associated Color, or if nothing is associated returns + * {@link Color#WHITE}. + */ + Color getPreferredColour(String itemKey); + + void setPreferredColour(String itemKey, Color colour); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/mimetype/MimeTypeManager.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/mimetype/MimeTypeManager.java b/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/mimetype/MimeTypeManager.java new file mode 100644 index 0000000..9d3a86b --- /dev/null +++ b/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/mimetype/MimeTypeManager.java @@ -0,0 +1,41 @@ +/* +* 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. +*/ + +package org.apache.taverna.workbench.configuration.mimetype; + +import java.util.Map; + +import uk.org.taverna.configuration.Configurable; + +public interface MimeTypeManager extends Configurable { + @Override + String getCategory(); + + @Override + Map<String, String> getDefaultPropertyMap(); + + @Override + String getUUID(); + + @Override + String getDisplayName(); + + @Override + String getFilePrefix(); +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/workbench/WorkbenchConfiguration.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/workbench/WorkbenchConfiguration.java b/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/workbench/WorkbenchConfiguration.java new file mode 100644 index 0000000..9678812 --- /dev/null +++ b/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/workbench/WorkbenchConfiguration.java @@ -0,0 +1,43 @@ +/* +* 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. +*/ + +package org.apache.taverna.workbench.configuration.workbench; + +import uk.org.taverna.configuration.Configurable; + +/** + * @author David Withers + */ +public interface WorkbenchConfiguration extends Configurable { + boolean getCaptureConsole(); + + void setCaptureConsole(boolean captureConsole); + + boolean getWarnInternalErrors(); + + void setWarnInternalErrors(boolean warnInternalErrors); + + int getMaxMenuItems(); + + void setMaxMenuItems(int maxMenuItems); + + String getDotLocation(); + + void setDotLocation(String dotLocation); +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/workbench/ui/T2ConfigurationFrame.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/workbench/ui/T2ConfigurationFrame.java b/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/workbench/ui/T2ConfigurationFrame.java new file mode 100644 index 0000000..7defd40 --- /dev/null +++ b/taverna-configuration-api/src/main/java/org/apache/taverna/workbench/configuration/workbench/ui/T2ConfigurationFrame.java @@ -0,0 +1,29 @@ +/* +* 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. +*/ + +package org.apache.taverna.workbench.configuration.workbench.ui; + +/** + * @author David Withers + */ +public interface T2ConfigurationFrame { + void showFrame(); + + void showConfiguration(String name); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/WorkbenchConfigurationImpl.java ---------------------------------------------------------------------- diff --git a/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/WorkbenchConfigurationImpl.java b/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/WorkbenchConfigurationImpl.java deleted file mode 100644 index 0e63a4a..0000000 --- a/taverna-configuration-impl/src/main/java/net/sf/taverna/t2/workbench/ui/impl/configuration/WorkbenchConfigurationImpl.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.ui.impl.configuration; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import net.sf.taverna.t2.workbench.configuration.workbench.WorkbenchConfiguration; - -import org.apache.log4j.Logger; - -import uk.org.taverna.configuration.AbstractConfigurable; -import uk.org.taverna.configuration.ConfigurationManager; -import uk.org.taverna.configuration.app.ApplicationConfiguration; - -/** - * An implementation of Configurable for general Workbench configuration - * properties - * - * @author Stuart Owen - * @author Stian Soiland-Reyes - */ -public class WorkbenchConfigurationImpl extends AbstractConfigurable implements - WorkbenchConfiguration { - private static Logger logger = Logger - .getLogger(WorkbenchConfiguration.class); - private static final int DEFAULT_MAX_MENU_ITEMS = 20; - public static final String TAVERNA_DOTLOCATION = "taverna.dotlocation"; - public static final String MAX_MENU_ITEMS = "taverna.maxmenuitems"; - public static final String WARN_INTERNAL_ERRORS = "taverna.warninternal"; - public static final String CAPTURE_CONSOLE = "taverna.captureconsole"; - private static final String BIN = "bin"; - private static final String BUNDLE_CONTENTS = "Contents"; - private static final String BUNDLE_MAC_OS = "MacOS"; - private static final String DOT_EXE = "dot.exe"; - private static final String DOT_FALLBACK = "dot"; - public static String uuid = "c14856f0-5967-11dd-ae16-0800200c9a66"; - private static final String MAC_OS_X = "Mac OS X"; - private static final String WIN32I386 = "win32i386"; - private static final String WINDOWS = "Windows"; - - private ApplicationConfiguration applicationConfiguration; - - /** - * Constructs a new <code>WorkbenchConfigurationImpl</code>. - * - * @param configurationManager - */ - public WorkbenchConfigurationImpl(ConfigurationManager configurationManager) { - super(configurationManager); - } - - Map<String, String> defaultWorkbenchProperties = null; - Map<String, String> workbenchProperties = new HashMap<String, String>(); - - @Override - public String getCategory() { - return "general"; - } - - @Override - public Map<String, String> getDefaultPropertyMap() { - if (defaultWorkbenchProperties == null) { - defaultWorkbenchProperties = new HashMap<>(); - String dotLocation = System.getProperty(TAVERNA_DOTLOCATION) != null ? System - .getProperty(TAVERNA_DOTLOCATION) : getDefaultDotLocation(); - if (dotLocation != null) - defaultWorkbenchProperties - .put(TAVERNA_DOTLOCATION, dotLocation); - defaultWorkbenchProperties.put(MAX_MENU_ITEMS, - Integer.toString(DEFAULT_MAX_MENU_ITEMS)); - defaultWorkbenchProperties.put(WARN_INTERNAL_ERRORS, - Boolean.FALSE.toString()); - defaultWorkbenchProperties.put(CAPTURE_CONSOLE, - Boolean.TRUE.toString()); - } - return defaultWorkbenchProperties; - } - - @Override - public String getDisplayName() { - return "Workbench"; - } - - @Override - public String getFilePrefix() { - return "Workbench"; - } - - @Override - public String getUUID() { - return uuid; - } - - @Override - public boolean getWarnInternalErrors() { - String property = getProperty(WARN_INTERNAL_ERRORS); - return Boolean.parseBoolean(property); - } - - @Override - public boolean getCaptureConsole() { - String property = getProperty(CAPTURE_CONSOLE); - return Boolean.parseBoolean(property); - } - - @Override - public void setWarnInternalErrors(boolean warnInternalErrors) { - setProperty(WARN_INTERNAL_ERRORS, Boolean.toString(warnInternalErrors)); - } - - @Override - public void setCaptureConsole(boolean captureConsole) { - setProperty(CAPTURE_CONSOLE, Boolean.toString(captureConsole)); - } - - @Override - public void setMaxMenuItems(int maxMenuItems) { - if (maxMenuItems < 2) - throw new IllegalArgumentException( - "Maximum menu items must be at least 2"); - setProperty(MAX_MENU_ITEMS, Integer.toString(maxMenuItems)); - } - - @Override - public int getMaxMenuItems() { - String property = getProperty(MAX_MENU_ITEMS); - try { - int maxMenuItems = Integer.parseInt(property); - if (maxMenuItems >= 2) - return maxMenuItems; - logger.warn(MAX_MENU_ITEMS + " can't be less than 2"); - } catch (NumberFormatException ex) { - logger.warn("Invalid number for " + MAX_MENU_ITEMS + ": " - + property); - } - // We'll return the default instead - return DEFAULT_MAX_MENU_ITEMS; - } - - @Override - public String getDotLocation() { - return getProperty(TAVERNA_DOTLOCATION); - } - - @Override - public void setDotLocation(String dotLocation) { - setProperty(TAVERNA_DOTLOCATION, dotLocation); - } - - private String getDefaultDotLocation() { - if (applicationConfiguration == null) - return null; - File startupDir = applicationConfiguration.getStartupDir(); - if (startupDir == null) - return DOT_FALLBACK; - - String os = System.getProperty("os.name"); - if (os.equals(MAC_OS_X)) - if (startupDir.getParentFile() != null) { - File contentsDir = startupDir.getParentFile().getParentFile(); - if (contentsDir != null - && contentsDir.getName().equalsIgnoreCase( - BUNDLE_CONTENTS)) { - File dot = new File(new File(contentsDir, BUNDLE_MAC_OS), - DOT_FALLBACK); - if (dot.exists()) - return dot.getAbsolutePath(); - } - } else if (os.startsWith(WINDOWS)) { - File binWin386Dir = new File(new File(startupDir, BIN), - WIN32I386); - File dot = new File(binWin386Dir, DOT_EXE); - if (dot.exists()) - return dot.getAbsolutePath(); - } - return DOT_FALLBACK; - } - - /** - * Sets the applicationConfiguration. - * - * @param applicationConfiguration - * the new value of applicationConfiguration - */ - public void setApplicationConfiguration( - ApplicationConfiguration applicationConfiguration) { - this.applicationConfiguration = applicationConfiguration; - defaultWorkbenchProperties = null; - } -}
