You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/04/14 20:30:57 UTC
[55/90] [abbrv] AIRAVATA-1124
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaLinkButton.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaLinkButton.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaLinkButton.java
new file mode 100644
index 0000000..b963475
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaLinkButton.java
@@ -0,0 +1,306 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets;
+
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.GridLayout;
+import java.awt.Rectangle;
+import java.net.URL;
+
+import javax.swing.Action;
+import javax.swing.ButtonModel;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.metal.MetalButtonUI;
+
+public class XBayaLinkButton extends JButton {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4827125226349868996L;
+
+ public static final int ALWAYS_UNDERLINE = 0;
+
+ public static final int HOVER_UNDERLINE = 1;
+
+ public static final int NEVER_UNDERLINE = 2;
+
+ public static final int SYSTEM_DEFAULT = 3;
+
+ private int linkBehavior;
+
+ private Color linkColor;
+
+ private Color colorPressed;
+
+ private Color visitedLinkColor;
+
+ private Color disabledLinkColor;
+
+ private URL buttonURL;
+
+ private Action defaultAction;
+
+ private boolean isLinkVisited;
+
+ public static void main(String[] a) {
+ JFrame f = new JFrame();
+ f.getContentPane().setLayout(new GridLayout(0, 2));
+ f.getContentPane().add(new XBayaLinkButton("www.java2s.com"));
+ f.getContentPane().add(new XBayaLinkButton("www.java2s.com/ExampleCode/CatalogExampleCode.htm"));
+ f.setSize(600, 200);
+ f.setVisible(true);
+ }
+
+ public XBayaLinkButton() {
+ this(null, null, null);
+ }
+
+ public XBayaLinkButton(Action action) {
+ this();
+ setAction(action);
+ }
+
+ public XBayaLinkButton(Icon icon) {
+ this(null, icon, null);
+ }
+
+ public XBayaLinkButton(String s) {
+ this(s, null, null);
+ }
+
+ public XBayaLinkButton(URL url) {
+ this(null, null, url);
+ }
+
+ public XBayaLinkButton(String s, URL url) {
+ this(s, null, url);
+ }
+
+ public XBayaLinkButton(Icon icon, URL url) {
+ this(null, icon, url);
+ }
+
+ public XBayaLinkButton(String text, Icon icon, URL url) {
+ super(text, icon);
+ linkBehavior = SYSTEM_DEFAULT;
+ linkColor = Color.blue;
+ colorPressed = Color.red;
+ visitedLinkColor = new Color(128, 0, 128);
+ if (text == null && url != null)
+ setText(url.toExternalForm());
+ setLinkURL(url);
+ setCursor(Cursor.getPredefinedCursor(12));
+ setBorderPainted(false);
+ setContentAreaFilled(false);
+ setRolloverEnabled(true);
+ addActionListener(defaultAction);
+ }
+
+ public void updateUI() {
+ setUI(BasicLinkButtonUI.createUI(this));
+ }
+
+ public String getUIClassID() {
+ return "LinkButtonUI";
+ }
+
+ protected void setupToolTipText() {
+ String tip = null;
+ if (buttonURL != null)
+ tip = buttonURL.toExternalForm();
+ setToolTipText(tip);
+ }
+
+ public void setLinkBehavior(int bnew) {
+ checkLinkBehaviour(bnew);
+ int old = linkBehavior;
+ linkBehavior = bnew;
+ firePropertyChange("linkBehavior", old, bnew);
+ repaint();
+ }
+
+ private void checkLinkBehaviour(int beha) {
+ if (beha != ALWAYS_UNDERLINE && beha != HOVER_UNDERLINE && beha != NEVER_UNDERLINE && beha != SYSTEM_DEFAULT)
+ throw new IllegalArgumentException("Not a legal LinkBehavior");
+ else
+ return;
+ }
+
+ public int getLinkBehavior() {
+ return linkBehavior;
+ }
+
+ public void setLinkColor(Color color) {
+ Color colorOld = linkColor;
+ linkColor = color;
+ firePropertyChange("linkColor", colorOld, color);
+ repaint();
+ }
+
+ public Color getLinkColor() {
+ return linkColor;
+ }
+
+ public void setActiveLinkColor(Color colorNew) {
+ Color colorOld = colorPressed;
+ colorPressed = colorNew;
+ firePropertyChange("activeLinkColor", colorOld, colorNew);
+ repaint();
+ }
+
+ public Color getActiveLinkColor() {
+ return colorPressed;
+ }
+
+ public void setDisabledLinkColor(Color color) {
+ Color colorOld = disabledLinkColor;
+ disabledLinkColor = color;
+ firePropertyChange("disabledLinkColor", colorOld, color);
+ if (!isEnabled())
+ repaint();
+ }
+
+ public Color getDisabledLinkColor() {
+ return disabledLinkColor;
+ }
+
+ public void setVisitedLinkColor(Color colorNew) {
+ Color colorOld = visitedLinkColor;
+ visitedLinkColor = colorNew;
+ firePropertyChange("visitedLinkColor", colorOld, colorNew);
+ repaint();
+ }
+
+ public Color getVisitedLinkColor() {
+ return visitedLinkColor;
+ }
+
+ public URL getLinkURL() {
+ return buttonURL;
+ }
+
+ public void setLinkURL(URL url) {
+ URL urlOld = buttonURL;
+ buttonURL = url;
+ setupToolTipText();
+ firePropertyChange("linkURL", urlOld, url);
+ revalidate();
+ repaint();
+ }
+
+ public void setLinkVisited(boolean flagNew) {
+ boolean flagOld = isLinkVisited;
+ isLinkVisited = flagNew;
+ firePropertyChange("linkVisited", flagOld, flagNew);
+ repaint();
+ }
+
+ public boolean isLinkVisited() {
+ return isLinkVisited;
+ }
+
+ public void setDefaultAction(Action actionNew) {
+ Action actionOld = defaultAction;
+ defaultAction = actionNew;
+ firePropertyChange("defaultAction", actionOld, actionNew);
+ }
+
+ public Action getDefaultAction() {
+ return defaultAction;
+ }
+
+ protected String paramString() {
+ String str;
+ if (linkBehavior == ALWAYS_UNDERLINE)
+ str = "ALWAYS_UNDERLINE";
+ else if (linkBehavior == HOVER_UNDERLINE)
+ str = "HOVER_UNDERLINE";
+ else if (linkBehavior == NEVER_UNDERLINE)
+ str = "NEVER_UNDERLINE";
+ else
+ str = "SYSTEM_DEFAULT";
+ String colorStr = linkColor == null ? "" : linkColor.toString();
+ String colorPressStr = colorPressed == null ? "" : colorPressed.toString();
+ String disabledLinkColorStr = disabledLinkColor == null ? "" : disabledLinkColor.toString();
+ String visitedLinkColorStr = visitedLinkColor == null ? "" : visitedLinkColor.toString();
+ String buttonURLStr = buttonURL == null ? "" : buttonURL.toString();
+ String isLinkVisitedStr = isLinkVisited ? "true" : "false";
+ return super.paramString() + ",linkBehavior=" + str + ",linkURL=" + buttonURLStr + ",linkColor=" + colorStr
+ + ",activeLinkColor=" + colorPressStr + ",disabledLinkColor=" + disabledLinkColorStr
+ + ",visitedLinkColor=" + visitedLinkColorStr + ",linkvisitedString=" + isLinkVisitedStr;
+ }
+}
+
+class BasicLinkButtonUI extends MetalButtonUI {
+ private static final BasicLinkButtonUI ui = new BasicLinkButtonUI();
+
+ public BasicLinkButtonUI() {
+ }
+
+ public static ComponentUI createUI(JComponent jcomponent) {
+ return ui;
+ }
+
+ protected void paintText(Graphics g, JComponent com, Rectangle rect, String s) {
+ XBayaLinkButton bn = (XBayaLinkButton) com;
+ ButtonModel bnModel = bn.getModel();
+ if (bnModel.isEnabled()) {
+ if (bnModel.isPressed())
+ bn.setForeground(bn.getActiveLinkColor());
+ else if (bn.isLinkVisited())
+ bn.setForeground(bn.getVisitedLinkColor());
+
+ else
+ bn.setForeground(bn.getLinkColor());
+ } else {
+ if (bn.getDisabledLinkColor() != null)
+ bn.setForeground(bn.getDisabledLinkColor());
+ }
+ super.paintText(g, com, rect, s);
+ int behaviour = bn.getLinkBehavior();
+ boolean drawLine = false;
+ if (behaviour == XBayaLinkButton.HOVER_UNDERLINE) {
+ if (bnModel.isRollover())
+ drawLine = true;
+ } else if (behaviour == XBayaLinkButton.ALWAYS_UNDERLINE || behaviour == XBayaLinkButton.SYSTEM_DEFAULT)
+ drawLine = true;
+ if (!drawLine)
+ return;
+ FontMetrics fm = g.getFontMetrics();
+ int x = rect.x + getTextShiftOffset();
+ int y = (rect.y + fm.getAscent() + fm.getDescent() + getTextShiftOffset()) - 1;
+ if (bnModel.isEnabled()) {
+ g.setColor(bn.getForeground());
+ g.drawLine(x, y, (x + rect.width) - 1, y);
+ } else {
+ g.setColor(bn.getBackground().brighter());
+ g.drawLine(x, y, (x + rect.width) - 1, y);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaList.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaList.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaList.java
new file mode 100644
index 0000000..89fbf77
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaList.java
@@ -0,0 +1,169 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets;
+
+import java.awt.Dimension;
+import java.awt.event.MouseAdapter;
+import java.util.Collection;
+import java.util.Vector;
+
+import javax.swing.JList;
+import javax.swing.JScrollPane;
+import javax.swing.ListSelectionModel;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.event.ListSelectionListener;
+
+
+/**
+ * @param <E>
+ */
+public class XBayaList<E> implements XBayaComponent {
+
+ private static final int DEFAULT_WIDTH = 300;
+
+ private static final int DEFAULT_HEIGHT = 200;
+
+ private JList list;
+
+ private JScrollPane scrollPane;
+
+ /**
+ * Constructs a XBayaTextArea.
+ */
+ public XBayaList() {
+ init();
+ }
+
+ /**
+ * @return The swing component.
+ */
+ public JScrollPane getSwingComponent() {
+ return getScrollPane();
+ }
+
+ /**
+ * @return The scroll pane.
+ */
+ public JScrollPane getScrollPane() {
+ return this.scrollPane;
+ }
+
+ /**
+ * @param enabled
+ */
+ public void setEnabled(boolean enabled) {
+ this.list.setEnabled(enabled);
+ }
+
+ /**
+ * @return The text area
+ */
+ public JList getList() {
+ return this.list;
+ }
+
+ /**
+ * @param width
+ * @param height
+ */
+ public void setSize(int width, int height) {
+ Dimension size = new Dimension(width, height);
+ this.scrollPane.setMinimumSize(size);
+ this.scrollPane.setPreferredSize(size);
+ }
+
+ /**
+ * Returns the first selected index; returns -1 if there is no selected item.
+ *
+ * @return The first selected index; -1 if there is no selected item.
+ */
+ public int getSelectedIndex() {
+ return this.list.getSelectedIndex();
+ }
+
+ /**
+ * Selects a single cell.
+ *
+ * @param index
+ * the index of the one cell to select
+ */
+ public void setSelectedIndex(int index) {
+ this.list.setSelectedIndex(index);
+ }
+
+ /**
+ * Returns the first selected value, or <code>null</code> if the selection is empty.
+ *
+ * @return the first selected value
+ */
+ @SuppressWarnings("unchecked")
+ public E getSelectedValue() {
+ return (E) this.list.getSelectedValue();
+ }
+
+ /**
+ * @param listData
+ */
+ public void setListData(Iterable<E> listData) {
+ if (listData instanceof Vector) {
+ this.list.setListData((Vector) listData);
+ } else if (listData instanceof Collection) {
+ this.list.setListData(new Vector<E>((Collection<E>) listData));
+ } else {
+ Vector<E> data = new Vector<E>();
+ for (E datum : data) {
+ data.add(datum);
+ }
+ this.list.setListData(data);
+ }
+ }
+
+ /**
+ * @param listData
+ */
+ public void setListData(E[] listData) {
+ this.list.setListData(listData);
+ }
+
+ /**
+ * @param listener
+ */
+ public void addListSelectionListener(ListSelectionListener listener) {
+ this.list.addListSelectionListener(listener);
+ }
+
+ /**
+ * @param adapter
+ */
+ public void addMouseListener(MouseAdapter adapter) {
+ this.list.addMouseListener(adapter);
+ }
+
+ private void init() {
+ this.list = new JList();
+ this.list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ this.scrollPane = new JScrollPane(this.list);
+ this.scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+ setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextArea.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextArea.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextArea.java
new file mode 100644
index 0000000..49af32f
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextArea.java
@@ -0,0 +1,120 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets;
+
+import java.awt.Dimension;
+
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.ScrollPaneConstants;
+
+public class XBayaTextArea implements XBayaTextComponent {
+
+ /**
+ * DEFAULT_WIDTH
+ */
+ public static final int DEFAULT_WIDTH = 300;
+
+ /**
+ * DEFAULT_HEIGHT
+ */
+ public static final int DEFAULT_HEIGHT = 200;
+
+ private JTextArea textArea;
+
+ private JScrollPane scrollPane;
+
+ /**
+ * Constructs a XBayaTextArea.
+ */
+ public XBayaTextArea() {
+ init();
+ }
+
+ /**
+ * @return The swing component.
+ */
+ public JScrollPane getSwingComponent() {
+ return getScrollPane();
+ }
+
+ /**
+ * @param text
+ */
+ public void setText(String text) {
+ if (text == null) {
+ text = "";
+ } else {
+ text = text.trim();
+ }
+ this.textArea.setText(text);
+ this.textArea.setCaretPosition(0);
+ }
+
+ /**
+ * @return The text
+ */
+ public String getText() {
+ return this.textArea.getText().trim();
+ }
+
+ /**
+ * @return The scroll pane.
+ */
+ public JScrollPane getScrollPane() {
+ return this.scrollPane;
+ }
+
+ /**
+ * @return The text area
+ */
+ public JTextArea getTextArea() {
+ return this.textArea;
+ }
+
+ /**
+ * @param editable
+ */
+ public void setEditable(boolean editable) {
+ this.textArea.setEditable(editable);
+ }
+
+ /**
+ * @param width
+ * @param height
+ */
+ public void setSize(int width, int height) {
+ Dimension size = new Dimension(width, height);
+ this.scrollPane.setMinimumSize(size);
+ this.scrollPane.setPreferredSize(size);
+ }
+
+ private void init() {
+ this.textArea = new JTextArea();
+ this.textArea.setEditable(true);
+ this.textArea.setLineWrap(true);
+ this.textArea.setWrapStyleWord(true);
+ this.scrollPane = new JScrollPane(this.textArea);
+ this.scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+ setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextComponent.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextComponent.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextComponent.java
new file mode 100644
index 0000000..68a499a
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextComponent.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets;
+
+
+public interface XBayaTextComponent extends XBayaComponent {
+
+ /**
+ * @param text
+ */
+ public void setText(String text);
+
+ /**
+ * @return The text
+ */
+ public String getText();
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextField.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextField.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextField.java
new file mode 100644
index 0000000..c8397d8
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaTextField.java
@@ -0,0 +1,124 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets;
+
+import java.net.URI;
+
+import javax.swing.JTextField;
+
+import org.apache.airavata.common.utils.StringUtil;
+
+public class XBayaTextField implements XBayaTextComponent {
+
+ /**
+ * DEFAULT_COLUMNS
+ */
+ public static final int DEFAULT_COLUMNS = 30;
+
+ private JTextField textArea;
+
+ /**
+ * Constructs a XBayaTextArea.
+ */
+ public XBayaTextField() {
+ init();
+ }
+
+ /**
+ * Constructs a XBayaTextField.
+ *
+ * @param initStr
+ */
+ public XBayaTextField(String initStr) {
+ init();
+ this.textArea.setText(initStr);
+ }
+
+ /**
+ * @return The swing component.
+ */
+ public JTextField getSwingComponent() {
+ return getTextField();
+ }
+
+ /**
+ * @param uri
+ */
+ public void setText(URI uri) {
+ setText(StringUtil.toString(uri));
+ }
+
+ /**
+ * @param text
+ */
+ public void setText(String text) {
+ if (text == null) {
+ text = "";
+ } else {
+ text = text.trim();
+ }
+ this.textArea.setText(text);
+ this.textArea.setCaretPosition(0);
+ }
+
+ /**
+ * @return The text. It never returns null.
+ */
+ public String getText() {
+ return this.textArea.getText().trim();
+ }
+
+ /**
+ * @return The text field
+ */
+ public JTextField getTextField() {
+ return this.textArea;
+ }
+
+ /**
+ * @param editable
+ */
+ public void setEditable(boolean editable) {
+ this.textArea.setEditable(editable);
+ }
+
+ /**
+ * @param columns
+ */
+ public void setColumns(int columns) {
+ this.textArea.setColumns(columns);
+ }
+
+ /**
+ * Sets whether or not this component is enabled.
+ *
+ * @param enabled
+ */
+ public void setEnabled(boolean enabled) {
+ this.textArea.setEnabled(enabled);
+ }
+
+ private void init() {
+ this.textArea = new JTextField(DEFAULT_COLUMNS);
+ this.textArea.setEditable(true);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaToolBar.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaToolBar.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaToolBar.java
new file mode 100644
index 0000000..9f18440
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XBayaToolBar.java
@@ -0,0 +1,362 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.AbstractAction;
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JToolBar;
+import javax.swing.border.Border;
+
+import org.apache.airavata.common.utils.SwingUtil;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.workflow.model.wf.WorkflowExecutionState;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+
+import com.amazonaws.transform.MapEntry;
+
+public class XBayaToolBar implements XBayaComponent {
+
+ private XBayaEngine engine;
+
+ private JToolBar toolbar;
+
+ private JButton play;
+
+ private JButton step;
+
+ private JButton stop;
+
+ private Map<String,List<ToolbarButton>> toolbarButtons = new HashMap<String,List<ToolbarButton>>();
+
+ private static Map<String,Integer> groupOrder;
+ /**
+ * IMAGES_STOP_JPEG
+ */
+ public static final String IMAGES_STOP_JPEG = "stop.jpeg";
+ /**
+ * IMAGES_PAUSE_JPEG
+ */
+ public static final String IMAGES_PAUSE_JPEG = "pause.jpeg";
+ /**
+ * IMAGES_PLAY_JPEG
+ */
+ public static final String IMAGES_PLAY_JPEG = "play.jpeg";
+ /**
+ * IMAGES_STEP_JPEG
+ */
+ private static final String IMAGES_STEP_JPEG = "step.gif";
+
+ private AbstractAction playAction;
+
+ private AbstractAction stepAction;
+
+ private AbstractAction stopAction;
+
+ private ImageIcon PLAY_ICON;
+
+ private ImageIcon PAUSE_ICON;
+
+ /**
+ * Creates a toolbar.
+ *
+ * @param client
+ */
+ public XBayaToolBar(XBayaEngine client) {
+ this.engine = client;
+ init();
+ }
+
+ /**
+ * Returns the toolbar.
+ *
+ * @return The toolbar
+ */
+ public JComponent getSwingComponent() {
+ return this.toolbar;
+ }
+
+ private void init() {
+
+ this.toolbar = new JToolBar();
+ this.toolbar.setFloatable(false);
+ Border border = BorderFactory.createEtchedBorder();
+ this.toolbar.setBorder(border);
+
+ JButton addNodeButton = new JButton("Add Node");
+ addNodeButton.addActionListener(new AbstractAction() {
+ private static final long serialVersionUID = 1L;
+
+ public void actionPerformed(ActionEvent event) {
+ try {
+ XBayaToolBar.this.engine.getGUI().addNode();
+ } catch (RuntimeException e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+ });
+
+ JButton removeNodeButton = new JButton("Remove Node");
+ removeNodeButton.addActionListener(new AbstractAction() {
+ private static final long serialVersionUID = 1L;
+
+ public void actionPerformed(ActionEvent event) {
+ try {
+ XBayaToolBar.this.engine.getGUI().getGraphCanvas().removeSelectedNode();
+ } catch (GraphException e) {
+ // Should not happen
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (RuntimeException e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+ });
+
+ JButton connectEdgeButton = new JButton("Connect/Disconnect");
+ connectEdgeButton.addActionListener(new AbstractAction() {
+ private static final long serialVersionUID = 1L;
+
+ public void actionPerformed(ActionEvent event) {
+ try {
+ XBayaToolBar.this.engine.getGUI().getGraphCanvas().addOrRemoveEdge();
+ } catch (RuntimeException e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+ });
+
+ this.play = new JButton();
+ PAUSE_ICON = SwingUtil.createImageIcon(IMAGES_PAUSE_JPEG);
+ PLAY_ICON = SwingUtil.createImageIcon(IMAGES_PLAY_JPEG);
+ this.playAction = new AbstractAction(null, PAUSE_ICON) {
+ /**
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent e1) {
+ try {
+ Workflow workflow = engine.getGUI().getWorkflow();
+ WorkflowExecutionState executionState = workflow.getExecutionState();
+ if (executionState == WorkflowExecutionState.RUNNING || executionState == WorkflowExecutionState.STEP) {
+ workflow.setExecutionState(WorkflowExecutionState.PAUSED);
+ play.setIcon(PLAY_ICON);
+ } else if (executionState == WorkflowExecutionState.PAUSED) {
+ workflow.setExecutionState(WorkflowExecutionState.RUNNING);
+ play.setIcon(PAUSE_ICON);
+ } else {
+ throw new IllegalStateException("Unknown state :" + executionState);
+ }
+ } catch (RuntimeException e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+
+ }
+ };
+ this.play.setAction(this.playAction);
+
+ this.step = new JButton();
+ this.stepAction = new AbstractAction(null, SwingUtil.createImageIcon(IMAGES_STEP_JPEG)) {
+ /**
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent e2) {
+ try {
+ if (engine.getGUI().getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
+ engine.getGUI().getWorkflow().setExecutionState(WorkflowExecutionState.STEP);
+ } else {
+ throw new IllegalStateException("Unknown state :" + engine.getGUI().getWorkflow().getExecutionState());
+ }
+ } catch (RuntimeException e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+
+ }
+ };
+ this.step.setAction(stepAction);
+
+ this.stop = new JButton();
+ this.stopAction = new AbstractAction(null, SwingUtil.createImageIcon(IMAGES_STOP_JPEG)) {
+ /**
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent e1) {
+ try {
+ if (engine.getGUI().getWorkflow().getExecutionState() != WorkflowExecutionState.NONE
+ || engine.getGUI().getWorkflow().getExecutionState() != WorkflowExecutionState.STOPPED) {
+ engine.getGUI().getWorkflow().setExecutionState(WorkflowExecutionState.STOPPED);
+ } else {
+ throw new IllegalStateException("Unknown state :" + engine.getGUI().getWorkflow().getExecutionState());
+ }
+ } catch (RuntimeException e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ XBayaToolBar.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+
+ }
+ };
+ this.stop.setAction(stopAction);
+
+// this.toolbar.add(addNodeButton);
+// this.toolbar.add(removeNodeButton);
+// this.toolbar.addSeparator();
+// this.toolbar.add(connectEdgeButton);
+
+ }
+
+ public ToolbarButton addToolbarButton(String group, String caption, Icon icon, String description, ActionListener onClick, int order){
+ ToolbarButton toolbarButton = new ToolbarButton(icon, caption, description, order);
+ toolbarButton.setButtonClickListener(onClick);
+ getToolBarButtonList(group).add(toolbarButton);
+ rearrangeToolbarButtons();
+ return toolbarButton;
+ }
+
+ private void sortButtons(List<ToolbarButton> buttons){
+ ToolbarButton[] buttonList=buttons.toArray(new ToolbarButton[]{});
+ ToolbarButton temp;
+ for (int i=0;i<buttonList.length-1;i++) {
+ for(int j=i+1;j<buttonList.length;j++){
+ if (buttonList[i].getOrder()!=-1){
+ if (buttonList[i].getOrder()>buttonList[j].getOrder()){
+ temp=buttonList[i];
+ buttonList[i]=buttonList[j];
+ buttonList[j]=temp;
+ }
+ }
+ }
+ }
+ buttons.clear();
+ buttons.addAll(Arrays.asList(buttonList));
+ }
+
+ private void rearrangeToolbarButtons(){
+ toolbar.removeAll();
+ String[] groupIds = getSortedGroupIdList();
+ Map<String, List<ToolbarButton>> tempToolbarButtons=new HashMap<String, List<ToolbarButton>>();
+ tempToolbarButtons.putAll(toolbarButtons);
+ for (String groupId : groupIds) {
+ tempToolbarButtons.remove(groupId);
+ if (toolbarButtons.containsKey(groupId) && toolbarButtons.get(groupId)!=null) {
+ List<ToolbarButton> buttons = toolbarButtons.get(groupId);
+ addButtonsToToolbar(buttons);
+ }
+ }
+ for (String groupId : tempToolbarButtons.keySet()) {
+ List<ToolbarButton> buttons = tempToolbarButtons.get(groupId);
+ addButtonsToToolbar(buttons);
+ }
+ }
+
+ private void addButtonsToToolbar(List<ToolbarButton> buttons) {
+ sortButtons(buttons);
+ for (ToolbarButton button : buttons) {
+ toolbar.add(button);
+ }
+ toolbar.addSeparator();
+ }
+
+ private String[] getSortedGroupIdList() {
+ String[] groupIds = getGroupOrder().keySet().toArray(new String[]{});
+ for(int i=0;i<groupIds.length-1;i++){
+ for(int j=i+1;j<groupIds.length;j++){
+ if (getGroupOrder().get(groupIds[i])>getGroupOrder().get(groupIds[j])){
+ String temp=groupIds[i];
+ groupIds[i]=groupIds[j];
+ groupIds[j]=temp;
+ }
+ }
+ }
+ return groupIds;
+ }
+
+
+ /**
+ * Returns the playAction.
+ *
+ * @return The playAction
+ */
+ public AbstractAction getPlayAction() {
+ return this.playAction;
+ }
+
+ /**
+ * Returns the stepAction.
+ *
+ * @return The stepAction
+ */
+ public AbstractAction getStepAction() {
+ return this.stepAction;
+ }
+
+ /**
+ * Returns the stopAction.
+ *
+ * @return The stopAction
+ */
+ public AbstractAction getStopAction() {
+ return this.stopAction;
+ }
+
+ private List<ToolbarButton> getToolBarButtonList(String group){
+ if (!toolbarButtons.containsKey(group)){
+ toolbarButtons.put(group, new ArrayList<ToolbarButton>());
+ }
+ return toolbarButtons.get(group);
+ }
+
+ public static void setGroupOrder(String groupId, int order){
+ getGroupOrder().put(groupId, order);
+ }
+
+ public static Map<String,Integer> getGroupOrder() {
+ if (groupOrder==null){
+ groupOrder=new HashMap<String, Integer>();
+ }
+ return groupOrder;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XbayaEnhancedList.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XbayaEnhancedList.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XbayaEnhancedList.java
new file mode 100644
index 0000000..edac352
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/XbayaEnhancedList.java
@@ -0,0 +1,308 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets;
+
+import java.awt.Dimension;
+import java.awt.event.MouseAdapter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.DefaultTableModel;
+
+
+/**
+ * @param <T>
+ */
+public class XbayaEnhancedList<T extends TableRenderable> implements XBayaComponent {
+
+ private static final int DEFAULT_WIDTH = 400;
+
+ private static final int DEFAULT_HEIGHT = 200;
+
+ private boolean checkbox;
+
+ private DefaultTableModel model;
+
+ private JTable table;
+
+ private JScrollPane scrollPane;
+
+ private Vector<T> tableList;
+
+ /**
+ * Constructs a XbayaEnhancedList.
+ *
+ */
+ public XbayaEnhancedList() {
+ this(true);
+ }
+
+ /**
+ *
+ * Constructs a XbayaEnhancedList.
+ *
+ * @param checkbox
+ */
+ public XbayaEnhancedList(boolean checkbox) {
+ this.checkbox = checkbox;
+ init();
+ }
+
+ /**
+ * Init XbayaEnhancedList
+ */
+ private void init() {
+
+ this.tableList = new Vector<T>();
+
+ this.table = new JTable(new DefaultTableModel());
+ this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ this.table.setRowSelectionAllowed(true);
+
+ this.scrollPane = new JScrollPane(this.table);
+ this.scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+ setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ }
+
+ /**
+ * @return The swing component.
+ */
+ public JScrollPane getSwingComponent() {
+ return getScrollPane();
+ }
+
+ /**
+ * @return The scroll pane.
+ */
+ public JScrollPane getScrollPane() {
+ return this.scrollPane;
+ }
+
+ /**
+ * @param width
+ * @param height
+ */
+ public void setSize(int width, int height) {
+ Dimension size = new Dimension(width, height);
+ this.scrollPane.setMinimumSize(size);
+ this.scrollPane.setPreferredSize(size);
+ }
+
+ /**
+ * @return table
+ */
+ public JTable getTable() {
+ return this.table;
+ }
+
+ /**
+ * @param tableData
+ * @param listData
+ */
+ public void setListData(Iterable<T> tableData) {
+
+ /*
+ * Create a model for the table for the first time
+ */
+ if (this.model == null) {
+
+ this.model = new DefaultTableModel() {
+ /*
+ * JTable uses this method to determine the default renderer/ editor for each cell. If we didn't
+ * implement this method, then the last column would contain text ("true"/"false"), rather than a check
+ * box.
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class getColumnClass(int c) {
+ if (getValueAt(0, c) == null)
+ return String.class;
+ return getValueAt(0, c).getClass();
+ }
+
+ /*
+ * Don't need to implement this method unless your table's editable.
+ */
+ @Override
+ public boolean isCellEditable(int row, int col) {
+ // Note that the data/cell address is constant,
+ // no matter where the cell appears onscreen.
+ if (XbayaEnhancedList.this.checkbox && col > 0) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ };
+
+ /*
+ * Setup Column Title
+ */
+ boolean noData = true;
+ for (T entry : tableData) {
+ if (this.checkbox) {
+ this.model.addColumn("Selection");
+ }
+
+ for (int i = 0; i < entry.getColumnCount(); i++) {
+ this.model.addColumn(entry.getColumnTitle(i));
+ }
+ noData = false;
+ break;
+ }
+
+ // empty input
+ if (noData) {
+ this.model = null;
+ return;
+ }
+
+ this.table.setModel(this.model);
+ }
+
+ clear();
+
+ ArrayList<Object> objList = new ArrayList<Object>();
+ for (T entry : tableData) {
+
+ // add checkbox if needed
+ if (this.checkbox) {
+ objList.add(Boolean.FALSE);
+ }
+
+ for (int i = 0; i < entry.getColumnCount(); i++) {
+ objList.add(entry.getValue(i));
+ }
+ this.model.addRow(objList.toArray());
+ this.tableList.add(entry);
+
+ // clear list
+ objList.clear();
+ }
+ }
+
+ /**
+ * @return T
+ */
+ public T getSelectedValue() {
+ int result = getSelectedIndex();
+ if (result < 0) {
+ return null;
+ }
+ return this.tableList.get(result);
+ }
+
+ /**
+ * @return selected values
+ */
+ public List<T> getSelectedValues() {
+ List<T> resultList = new ArrayList<T>();
+ for (Integer i : getSelectedIndices()) {
+ resultList.add(this.tableList.get(i.intValue()));
+ }
+ return resultList;
+ }
+
+ /**
+ * remove rows selected This method must be called at the last step
+ */
+ public void removeSelectedRows() {
+ int count = 0;
+ for (Integer i : getSelectedIndices()) {
+ this.model.removeRow(i.intValue() - count);
+ this.tableList.remove(i.intValue() - count);
+ count++;
+ }
+ }
+
+ /**
+ * Clear the list contents
+ */
+ public void clear() {
+ if (this.model != null) {
+ for (int i = this.model.getRowCount() - 1; i >= 0; i--) {
+ this.model.removeRow(i);
+ }
+ }
+ this.tableList.clear();
+ }
+
+ /**
+ * @param enabled
+ */
+ public void setEnabled(boolean enabled) {
+ this.table.setEnabled(enabled);
+ }
+
+ /**
+ * Returns the first selected index; returns -1 if there is no selected item.
+ *
+ * @return The first selected index; -1 if there is no selected item.
+ */
+ public int getSelectedIndex() {
+ List<Integer> intList = getSelectedIndices();
+ if (intList.size() > 1) {
+ return -2;
+ } else if (intList.size() == 0) {
+ return -1;
+ }
+ return intList.get(0).intValue();
+ }
+
+ /**
+ * @return selected indices
+ */
+ public List<Integer> getSelectedIndices() {
+ List<Integer> intList = new ArrayList<Integer>();
+
+ if (!this.checkbox) {
+ intList.add(new Integer(this.table.getSelectedRow()));
+ } else {
+ for (int i = 0; i < this.getTable().getModel().getRowCount(); i++) {
+ if (((Boolean) this.getTable().getModel().getValueAt(i, 0)).booleanValue()) {
+ intList.add(new Integer(i));
+ }
+ }
+ }
+ return intList;
+ }
+
+ /**
+ * @param listener
+ */
+ public void addListSelectionListener(ListSelectionListener listener) {
+ this.table.getSelectionModel().addListSelectionListener(listener);
+ }
+
+ /**
+ * @param adapter
+ */
+ public void addMouseListener(MouseAdapter adapter) {
+ this.table.addMouseListener(adapter);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/amazon/S3Tree.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/amazon/S3Tree.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/amazon/S3Tree.java
new file mode 100644
index 0000000..4f6abbb
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/amazon/S3Tree.java
@@ -0,0 +1,133 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets.amazon;
+
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+public class S3Tree extends JTree {
+
+ /**
+ *
+ * Constructs a S3Tree.
+ *
+ */
+ public S3Tree() {
+ this.setModel(S3TreeModel.getInstance());
+ this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ this.setShowsRootHandles(true);
+ }
+
+ /**
+ *
+ */
+ public void clean() {
+ this.setModel(S3TreeModel.getInstance().clean());
+ }
+
+ /**
+ *
+ */
+ public void refresh() {
+ repaint();
+ }
+
+ /**
+ *
+ * @param child
+ * @return
+ */
+ public DefaultMutableTreeNode addObject(Object child) {
+ DefaultMutableTreeNode parentNode = null;
+ TreePath parentPath = this.getSelectionPath().getParentPath();
+
+ if (parentPath == null) {
+ parentNode = (DefaultMutableTreeNode) S3TreeModel.getInstance().getRoot();
+ } else {
+ parentNode = (DefaultMutableTreeNode) (parentPath.getLastPathComponent());
+ }
+
+ return addObject(parentNode, child, true);
+ }
+
+ /**
+ *
+ * @param parent
+ * @param child
+ * @return DefaultMutableTreeNode
+ */
+ public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child) {
+ return addObject(parent, child, false);
+ }
+
+ /**
+ * @param parentName
+ * @param child
+ * @return
+ */
+ public DefaultMutableTreeNode addObject(String parentName, Object child) {
+ if (parentName.contains("/")) {
+ parentName = parentName.substring(0, parentName.indexOf('/'));
+ }
+ DefaultMutableTreeNode root = (DefaultMutableTreeNode) S3TreeModel.getInstance().getRoot();
+ int count = root.getChildCount();
+ for (int i = 0; i < count; i++) {
+ Object name = ((DefaultMutableTreeNode) root.getChildAt(i)).getUserObject();
+ if (parentName.equals(name)) {
+ return this.addObject((DefaultMutableTreeNode) root.getChildAt(i), child, true);
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param parent
+ * @param child
+ * @param shouldBeVisible
+ * @return DefaultMutableTreeNode
+ */
+ public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible) {
+ DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
+
+ if (parent == null) {
+ parent = (DefaultMutableTreeNode) S3TreeModel.getInstance().getRoot();
+ }
+
+ S3TreeModel.getInstance().insertNodeInto(childNode, parent, parent.getChildCount());
+
+ if (shouldBeVisible) {
+ this.scrollPathToVisible(new TreePath(childNode.getPath()));
+ }
+ return childNode;
+ }
+
+ /**
+ *
+ * @return DefaultMutableTreeNode
+ */
+ public DefaultMutableTreeNode getSelectedNode() {
+ return (DefaultMutableTreeNode) this.getLastSelectedPathComponent();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/amazon/S3TreeModel.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/amazon/S3TreeModel.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/amazon/S3TreeModel.java
new file mode 100644
index 0000000..f3168b9
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/amazon/S3TreeModel.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets.amazon;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+
+public class S3TreeModel extends DefaultTreeModel {
+
+ private static S3TreeModel instance;
+ private static DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("S3 Contents");
+
+ private boolean connected;
+
+ /**
+ * Constructs a S3TreeModel.
+ *
+ * @param root
+ */
+ private S3TreeModel() {
+ super(rootNode);
+ }
+
+ public static S3TreeModel getInstance() {
+ if (instance == null) {
+ instance = new S3TreeModel();
+ }
+ return instance;
+ }
+
+ public S3TreeModel clean() {
+ rootNode.removeAllChildren();
+ setRoot(rootNode);
+ connected = false;
+ return instance;
+ }
+
+ public void connect() {
+ this.connected = true;
+ }
+
+ public boolean isConnected() {
+ return this.connected;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelector.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelector.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelector.java
new file mode 100644
index 0000000..2d641bb
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelector.java
@@ -0,0 +1,530 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets.component;
+
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DragSourceAdapter;
+import java.awt.dnd.DragSourceListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.swing.AbstractAction;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.ToolTipManager;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.TreeNode;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+import org.apache.airavata.common.utils.SwingUtil;
+import org.apache.airavata.workflow.model.component.Component;
+import org.apache.airavata.workflow.model.component.ComponentException;
+import org.apache.airavata.workflow.model.component.ComponentOperationReference;
+import org.apache.airavata.workflow.model.component.ComponentReference;
+import org.apache.airavata.workflow.model.component.ComponentRegistry;
+import org.apache.airavata.workflow.model.component.ComponentRegistryException;
+import org.apache.airavata.workflow.model.component.ws.WSComponent;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.component.registry.ComponentController;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.apache.airavata.xbaya.ui.widgets.XBayaComponent;
+import org.apache.airavata.xbaya.ui.widgets.component.ComponentSelectorEvent.ComponentSelectorEventType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The ComponentTreeViewer class shows the selectedComponent tree.
+ *
+ */
+public class ComponentSelector implements XBayaComponent {
+
+ /**
+ * The title.
+ */
+ public static final String TITLE = "Component List";
+
+ private static final Logger logger = LoggerFactory.getLogger(ComponentSelector.class);
+
+ private XBayaEngine engine;
+
+ private JTree tree;
+
+ private ComponentTreeModel treeModel;
+
+ private ComponentReference selectedComponentReference;
+
+ private Component selectedComponent;
+
+ private List<ComponentSelectorListener> listeners;
+
+ private DragSourceListener dragSourceListener;
+
+ private JPopupMenu popup;
+
+ /**
+ * @param engine
+ */
+ public ComponentSelector(XBayaEngine engine) {
+ this.engine = engine;
+ this.listeners = new LinkedList<ComponentSelectorListener>();
+ initGUI();
+ }
+
+ /**
+ * @return the Pane
+ */
+ public JTree getSwingComponent() {
+ return this.tree;
+ }
+
+ /**
+ * Adds a new selectedComponent registry to the end of the tree.
+ *
+ * @param componentTree
+ */
+ public void addComponentTree(ComponentTreeNode componentTree) {
+ addComponentTree(-1, componentTree);
+ }
+
+ public void removeComponentTree(final ComponentTreeNode componentTree) {
+ ComponentSelector.this.treeModel.removeNodeFromParent(componentTree);
+// SwingUtilities.invokeLater(new Runnable() {
+// public void run() {
+// ComponentSelector.this.treeModel.removeNodeFromParent(componentTree);
+// }
+//
+// });
+ }
+
+ public synchronized void removeComponentRegistry(final String componentRegistryName) {
+ ComponentTreeNode root = ComponentSelector.this.treeModel.getRoot();
+ ComponentTreeNode[] treeNodes = root.getChildren().toArray(new ComponentTreeNode[]{});
+ for(ComponentTreeNode treeNode:treeNodes){
+ if (treeNode.getComponentRegistry().getName().equals(componentRegistryName)){
+ root.remove(treeNode);
+ }
+ }
+ treeModel.reload();
+ }
+
+ /**
+ * Adds a new selectedComponent registry to the specified location.
+ *
+ * @param index
+ * The index to ineart a new selectedComponent registry
+ * @param componentTree
+ */
+ public void addComponentTree(final int index, final ComponentTreeNode componentTree) {
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ ComponentTreeNode root = ComponentSelector.this.treeModel.getRoot();
+ if (index < 0) {
+ // Have to go through DefaultTreeModol to dynamically
+ // add a node
+ ComponentSelector.this.treeModel.addNodeInto(componentTree, root);
+ } else {
+ // Have to go through DefaultTreeModol to dynamically
+ // add a node
+ ComponentSelector.this.treeModel.insertNodeInto(componentTree, root, index);
+ }
+ makeVisible(componentTree);
+ }
+
+ });
+ }
+
+ /**
+ * Removes a registry currently selected.
+ */
+ public void removeSelectedRegistry() {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ TreePath selectionPath = ComponentSelector.this.tree.getSelectionPath();
+ ComponentTreeNode selectedNode = (ComponentTreeNode) selectionPath.getLastPathComponent();
+ if (selectedNode.getLevel() == 1) {
+ ComponentSelector.this.treeModel.removeNodeFromParent(selectedNode);
+ }
+ }
+ });
+ }
+
+ /**
+ * @throws ComponentRegistryException
+ */
+ public void updateSelectedRegistry() throws ComponentRegistryException {
+ final TreePath[] selectionPathHolder = new TreePath[1];
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ selectionPathHolder[0] = ComponentSelector.this.tree.getSelectionPath();
+ }
+ });
+ } catch (InterruptedException e) {
+ // Should not happen.
+ throw new WorkflowRuntimeException(e);
+ } catch (InvocationTargetException e) {
+ // Should not happen.
+ throw new WorkflowRuntimeException(e);
+ }
+
+ TreePath selectionPath = selectionPathHolder[0];
+ if (selectionPath == null) {
+ // TODO this case should be handled in the menu before comming here.
+ return;
+ }
+
+ if (selectionPath.getPathCount() >= 2) {
+ final ComponentTreeNode selectedNode = (ComponentTreeNode) selectionPath.getPath()[1];
+ reloadComponentRegistryNode(selectedNode);
+ }
+ }
+
+ private void reloadComponentRegistryNode(
+ final ComponentTreeNode selectedNode)
+ throws ComponentRegistryException {
+ ComponentRegistry registry = selectedNode.getComponentRegistry();
+ final ComponentTreeNode componentTree = ComponentController.getComponentTree(registry);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ ComponentTreeNode root = ComponentSelector.this.treeModel.getRoot();
+ int index = root.getIndex(selectedNode);
+ ComponentSelector.this.treeModel.removeNodeFromParent(selectedNode);
+ ComponentSelector.this.treeModel.insertNodeInto(componentTree, root, index);
+ }
+ });
+ }
+
+ /**
+ * Updates all the registry entries.
+ *
+ * @throws ComponentRegistryException
+ */
+ public void update() throws ComponentRegistryException {
+ final List<ComponentRegistry> registries = new ArrayList<ComponentRegistry>();
+ if (SwingUtilities.isEventDispatchThread()) {
+ getRegistries(registries);
+ } else {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ getRegistries(registries);
+ }
+ });
+ } catch (InterruptedException e) {
+ // Should not happen.
+ throw new WorkflowRuntimeException(e);
+ } catch (InvocationTargetException e) {
+ // Should not happen.
+ throw new WorkflowRuntimeException(e);
+ }
+ }
+
+ final List<ComponentTreeNode> newSubTrees = new ArrayList<ComponentTreeNode>();
+ for (ComponentRegistry registry : registries) {
+ ComponentTreeNode componentTree = ComponentController.getComponentTree(registry);
+ newSubTrees.add(componentTree);
+ }
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ ComponentTreeNode root = ComponentSelector.this.treeModel.getRoot();
+ ComponentSelector.this.treeModel.removeChildren(root);
+ logger.debug("Removed all");
+ for (ComponentTreeNode subTree : newSubTrees) {
+ ComponentSelector.this.treeModel.addNodeInto(subTree, root);
+ }
+ makeVisible((ComponentTreeNode) root.getFirstChild());
+ }
+ });
+
+ }
+
+ /**
+ * Returns the selectedComponent.
+ *
+ * @return The selectedComponent
+ */
+ public Component getSelectedComponent() {
+ return this.selectedComponent;
+ }
+
+ /**
+ * @param listener
+ */
+ public synchronized void addComponentSelectorListener(ComponentSelectorListener listener) {
+ this.listeners.add(listener);
+ }
+
+ /**
+ * @param listener
+ */
+ public synchronized void removeComponentSelectorListener(ComponentSelectorListener listener) {
+ this.listeners.remove(listener);
+ }
+
+ private void dragGestureRecognized(DragGestureEvent event) {
+ if (this.selectedComponentReference != null) {
+ event.startDrag(DragSource.DefaultCopyDrop,
+ new ComponentSourceTransferable(this.selectedComponentReference), this.dragSourceListener);
+ }
+ }
+
+ private List<ComponentRegistry> getRegistries(List<ComponentRegistry> registries) {
+ ComponentTreeNode root = this.treeModel.getRoot();
+ for (ComponentTreeNode componentTree : root.getChildren()) {
+ registries.add(componentTree.getComponentRegistry());
+ }
+ return registries;
+ }
+
+ private void makeVisible(ComponentTreeNode node) {
+ // Make sure the user can see the new node, but don't scroll to
+ // right.
+ TreePath treePath = new TreePath(node.getPath());
+ Rectangle bounds = ComponentSelector.this.tree.getPathBounds(treePath);
+ if (bounds != null) {
+ // Prevent right scroll.
+ bounds.x = 0;
+ bounds.width = 0;
+ this.tree.scrollRectToVisible(bounds);
+ } else {
+ // null during the initialization.
+ this.tree.scrollPathToVisible(treePath);
+ }
+ }
+
+ /**
+ * This method is called when a component is selected. It reads the component information from the server and set
+ * the selectedComponent.
+ *
+ * @param treePath
+ * The path of the selected selectedComponent.
+ */
+ private void select(TreePath treePath) {
+ final ComponentTreeNode selectedNode = (ComponentTreeNode) treePath.getLastPathComponent();
+ final ComponentReference componentReference = selectedNode.getComponentReference();
+ selectComponent(null);
+ this.selectedComponentReference = null;
+ if (componentReference != null) {
+ this.selectedComponentReference = componentReference;
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ // get all components and check the number of
+ // components. If there are multiple, expand the tree.
+ final List<? extends Component> components = componentReference.getComponents();
+ if (components.size() == 1) {
+ selectComponent(components.get(0));
+ } else {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ expandTreeLeaf(selectedNode, components);
+ }
+ });
+ }
+
+ } catch (ComponentException e) {
+ selectComponent(null);
+ ComponentSelector.this.engine.getGUI().getErrorWindow().error(ErrorMessages.COMPONENT_FORMAT_ERROR, e);
+ } catch (ComponentRegistryException e) {
+ selectComponent(null);
+ ComponentSelector.this.engine.getGUI().getErrorWindow().error(ErrorMessages.COMPONENT_LOAD_ERROR, e);
+ } catch (RuntimeException e) {
+ selectComponent(null);
+ ComponentSelector.this.engine.getGUI().getErrorWindow().error(ErrorMessages.COMPONENT_LOAD_ERROR, e);
+ } catch (Exception e) {
+ selectComponent(null);
+ ComponentSelector.this.engine.getGUI().getErrorWindow().error(ErrorMessages.COMPONENT_LOAD_ERROR, e);
+ }
+ }
+ }.start();
+
+ }
+ }
+
+ private void expandTreeLeaf(ComponentTreeNode selectedNode, List<? extends Component> components) {
+ ComponentReference componentReference = selectedNode.getComponentReference();
+ ComponentTreeNode newNode = new ComponentTreeNode(componentReference.getName());
+
+ ComponentTreeNode parent = (ComponentTreeNode) selectedNode.getParent();
+ int index = this.treeModel.getIndexOfChild(parent, selectedNode);
+ this.treeModel.removeNodeFromParent(selectedNode);
+ this.treeModel.insertNodeInto(newNode, parent, index);
+
+ for (Component component : components) {
+ WSComponent wsComponent = (WSComponent) component;
+ String operationName = wsComponent.getOperationName();
+ ComponentOperationReference reference = new ComponentOperationReference(operationName, wsComponent);
+ ComponentTreeNode child = new ComponentTreeNode(reference);
+ this.treeModel.addNodeInto(child, newNode);
+ }
+ // expand
+ TreeNode[] path = newNode.getPath();
+ this.tree.expandPath(new TreePath(path));
+ }
+
+ private void selectComponent(Component component) {
+ this.selectedComponent = component;
+ notifyListeners(new ComponentSelectorEvent(ComponentSelectorEventType.COMPONENT_SELECTED, this, component));
+ }
+
+ private void showPopupIfNecessary(MouseEvent event) {
+ Point point = event.getPoint();
+ TreePath path = this.tree.getClosestPathForLocation(point.x, point.y);
+ this.tree.setSelectionPath(path);
+
+ if (path.getPathCount() >= 2) {
+ this.popup.show(event.getComponent(), point.x, point.y);
+ }
+ }
+
+ private void notifyListeners(ComponentSelectorEvent event) {
+ for (ComponentSelectorListener listener : this.listeners) {
+ listener.componentSelectorChanged(event);
+ }
+ }
+
+ private void initGUI() {
+ this.treeModel = new ComponentTreeModel(new ComponentTreeNode("Components"));
+ this.tree = new JTree(this.treeModel);
+
+ // Add a tool tip.
+ ToolTipManager.sharedInstance().registerComponent(this.tree);
+ DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
+ @Override
+ public java.awt.Component getTreeCellRendererComponent(JTree t, Object value, boolean sel,
+ boolean expanded, boolean leaf, int row, boolean focus) {
+ super.getTreeCellRendererComponent(t, value, sel, expanded, leaf, row, focus);
+
+ ComponentTreeNode node = (ComponentTreeNode) value;
+ if (node.getComponentReference() == null) {
+ setToolTipText(null);
+ } else {
+ setToolTipText("Drag a component to the composer to add");
+ }
+ return this;
+ }
+ };
+
+ // Change icons
+ try {
+ renderer.setOpenIcon(SwingUtil.createImageIcon("opened.gif"));
+ renderer.setClosedIcon(SwingUtil.createImageIcon("closed.gif"));
+ renderer.setLeafIcon(SwingUtil.createImageIcon("leaf.gif"));
+ } catch (RuntimeException e) {
+ logger.warn("Failed to load image icons. " + "It will use the default icons instead.", e);
+ }
+
+ this.tree.setCellRenderer(renderer);
+ this.tree.setShowsRootHandles(true);
+ this.tree.setEditable(false);
+ this.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+
+ this.tree.addTreeSelectionListener(new TreeSelectionListener() {
+ public void valueChanged(TreeSelectionEvent event) {
+ // Doesn't do anything if deselected, which happens during the
+ // update.
+ if (event.isAddedPath()) {
+ TreePath path = event.getPath();
+ select(path);
+ }
+ }
+ });
+
+ // Drag and dtop
+ DragGestureListener dragGestureListener = new DragGestureListener() {
+ public void dragGestureRecognized(DragGestureEvent event) {
+ ComponentSelector.this.dragGestureRecognized(event);
+ }
+ };
+ DragSource dragSource = DragSource.getDefaultDragSource();
+ dragSource.createDefaultDragGestureRecognizer(this.tree, DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
+
+ this.dragSourceListener = new DragSourceAdapter() {
+ // Overwrite some methods when needed.
+ };
+
+ // Popup
+ this.tree.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent event) {
+ if (event.isPopupTrigger()) {
+ showPopupIfNecessary(event);
+ }
+ }
+ });
+ createNodePopupMenu();
+ }
+
+ private void createNodePopupMenu() {
+ this.popup = new JPopupMenu();
+ JMenuItem refreshItem = new JMenuItem("Refresh Registry");
+ refreshItem.addActionListener(new AbstractAction() {
+ public void actionPerformed(ActionEvent event) {
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ updateSelectedRegistry();
+ } catch (ComponentRegistryException e) {
+ ComponentSelector.this.engine.getGUI().getErrorWindow().error(
+ ErrorMessages.COMPONENT_LIST_LOAD_ERROR, e);
+ } catch (RuntimeException e) {
+ ComponentSelector.this.engine.getGUI().getErrorWindow().error(
+ ErrorMessages.COMPONENT_LIST_LOAD_ERROR, e);
+ } catch (Error e) {
+ ComponentSelector.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+ }.start();
+ }
+ });
+ this.popup.add(refreshItem);
+ }
+
+ public void refresh() {
+ this.getSwingComponent().repaint();
+
+ this.tree.repaint();
+ this.treeModel.reload();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelectorEvent.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelectorEvent.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelectorEvent.java
new file mode 100644
index 0000000..7288950
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelectorEvent.java
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets.component;
+
+import org.apache.airavata.workflow.model.component.Component;
+
+public class ComponentSelectorEvent {
+
+ /**
+ * The type of an event.
+ */
+ public enum ComponentSelectorEventType {
+ /**
+ * A component was selected.
+ */
+ COMPONENT_SELECTED,
+ }
+
+ private ComponentSelectorEventType type;
+
+ private ComponentSelector componentSelector;
+
+ private Component component;
+
+ /**
+ * Constructs a ComponentSelectorEvent.
+ *
+ * @param type
+ * @param componentSelector
+ * @param component
+ */
+ public ComponentSelectorEvent(ComponentSelectorEventType type, ComponentSelector componentSelector,
+ Component component) {
+ this.type = type;
+ this.componentSelector = componentSelector;
+ this.component = component;
+ }
+
+ /**
+ * Returns the type.
+ *
+ * @return The type
+ */
+ public ComponentSelectorEventType getType() {
+ return this.type;
+ }
+
+ /**
+ * Returns the componentSelector.
+ *
+ * @return The componentSelector
+ */
+ public ComponentSelector getComponentSelector() {
+ return this.componentSelector;
+ }
+
+ /**
+ * Returns the component.
+ *
+ * @return The component
+ */
+ public Component getComponent() {
+ return this.component;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelectorListener.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelectorListener.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelectorListener.java
new file mode 100644
index 0000000..b5eab7c
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSelectorListener.java
@@ -0,0 +1,32 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets.component;
+
+public interface ComponentSelectorListener {
+
+ /**
+ * Called when a component selector changes
+ *
+ * @param event
+ */
+ public void componentSelectorChanged(ComponentSelectorEvent event);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSourceTransferable.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSourceTransferable.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSourceTransferable.java
new file mode 100644
index 0000000..62b706c
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentSourceTransferable.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.airavata.xbaya.ui.widgets.component;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+
+import org.apache.airavata.workflow.model.component.ComponentReference;
+
+/**
+ * To transfer ComponentSource by drag-and-drop. This is really over-spec, but this is the only way.
+ *
+ */
+public class ComponentSourceTransferable implements Transferable {
+
+ /**
+ * FLAVOR
+ */
+ public static final DataFlavor FLAVOR = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType,
+ ComponentReference.class.toString());
+
+ private ComponentReference componentReference;
+
+ /**
+ * Constructs a ComponentSourceTransferable.
+ *
+ * @param componentReference
+ */
+ public ComponentSourceTransferable(ComponentReference componentReference) {
+ this.componentReference = componentReference;
+ }
+
+ /**
+ * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
+ */
+ public DataFlavor[] getTransferDataFlavors() {
+ return new DataFlavor[] { FLAVOR };
+ }
+
+ /**
+ * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
+ */
+ public boolean isDataFlavorSupported(DataFlavor flavor) {
+ return flavor.equals(FLAVOR);
+ }
+
+ /**
+ * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
+ */
+ public ComponentReference getTransferData(DataFlavor flavor) {
+ return this.componentReference;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentTreeModel.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentTreeModel.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentTreeModel.java
new file mode 100644
index 0000000..52e9f51
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/widgets/component/ComponentTreeModel.java
@@ -0,0 +1,71 @@
+/*
+ *
+ * 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.airavata.xbaya.ui.widgets.component;
+
+import javax.swing.tree.DefaultTreeModel;
+
+public class ComponentTreeModel extends DefaultTreeModel {
+
+ private ComponentTreeNode root;
+
+ /**
+ * Constructs a ComponentTreeModel.
+ *
+ * @param root
+ */
+ public ComponentTreeModel(ComponentTreeNode root) {
+ super(root);
+ this.root = root;
+ }
+
+ /**
+ * @see javax.swing.tree.DefaultTreeModel#getRoot()
+ */
+ @Override
+ public ComponentTreeNode getRoot() {
+ return this.root;
+ }
+
+ /**
+ * @param newChild
+ * @param parent
+ */
+ public void addNodeInto(ComponentTreeNode newChild, ComponentTreeNode parent) {
+ insertNodeInto(newChild, parent, parent.getChildCount());
+ }
+
+ /**
+ * @param parent
+ */
+ public void removeChildren(ComponentTreeNode parent) {
+ int numChild = parent.getChildCount();
+ int[] childIndices = new int[numChild];
+ Object[] removedChildren = new Object[numChild];
+ for (int i = numChild - 1; i >= 0; i--) {
+ childIndices[i] = i;
+ removedChildren[i] = parent.getChildAt(i);
+ parent.remove(i);
+ }
+ nodesWereRemoved(parent, childIndices, removedChildren);
+ }
+
+}
\ No newline at end of file