You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2011/07/13 08:09:04 UTC

svn commit: r1145872 [2/4] - in /oodt/trunk/app/weditor: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/oodt/ src/main/java/org/apache/oodt/cas/ src/main/java/org/apache/oodt/cas/workflow/ src/mai...

Added: oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/ViewState.java
URL: http://svn.apache.org/viewvc/oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/ViewState.java?rev=1145872&view=auto
==============================================================================
--- oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/ViewState.java (added)
+++ oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/ViewState.java Wed Jul 13 06:09:02 2011
@@ -0,0 +1,260 @@
+/**
+ * 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.oodt.cas.workflow.gui.perspective.view;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.gui.model.ModelGraph;
+import org.apache.oodt.cas.workflow.gui.model.repo.XmlWorkflowModelRepository.ConfigGroup;
+import org.apache.oodt.cas.workflow.gui.perspective.view.View.Mode;
+import org.apache.oodt.cas.workflow.gui.util.GuiUtils;
+
+//JDK imports
+import java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+import java.util.UUID;
+import java.util.Vector;
+
+/**
+ * 
+ * The current state of a particular Workflow GUI editor view.
+ * 
+ * @author bfoster
+ * @author mattmann
+ * 
+ */
+public class ViewState {
+
+  private static final HashMap<String, Stack<ViewState>> undoHistory = new HashMap<String, Stack<ViewState>>();
+
+  private ModelGraph selected;
+  private List<ModelGraph> graphs;
+  private String id;
+  private String currentMetGroup;
+  private Metadata properties;
+  private Mode mode;
+  private File file;
+  private boolean change = false;
+  private Map<String, ConfigGroup> globalConfigGroups;
+
+  public ViewState(File file, ModelGraph selected, List<ModelGraph> graphs,
+      Map<String, ConfigGroup> globalConfigGroups) {
+    this.selected = selected;
+    this.graphs = new Vector<ModelGraph>(graphs);
+    this.id = UUID.randomUUID().toString();
+    this.currentMetGroup = null;
+    this.properties = new Metadata();
+    this.mode = Mode.EDIT;
+    this.file = file;
+    this.globalConfigGroups = globalConfigGroups;
+  }
+
+  public Map<String, ConfigGroup> getGlobalConfigGroups() {
+    return this.globalConfigGroups;
+  }
+
+  public void addGlobalConfigGroup(String groupName, ConfigGroup configGroup) {
+    this.globalConfigGroups.put(groupName, configGroup);
+  }
+
+  public void removeGlobalConfigGroup(String groupName) {
+    this.globalConfigGroups.remove(groupName);
+  }
+
+  public File getFile() {
+    return this.file;
+  }
+
+  public String getId() {
+    return this.id;
+  }
+
+  public boolean containsProperty(String key) {
+    return this.properties.containsGroup(key);
+  }
+
+  public void setProperty(String key, String value) {
+    Vector<String> values = new Vector<String>();
+    values.add(value);
+    this.setProperty(key, values);
+  }
+
+  public void setProperty(String key, List<String> values) {
+    this.properties.replaceMetadata(key, values);
+    this.change = true;
+  }
+
+  public String getFirstPropertyValue(String key) {
+    List<String> values = this.getProperty(key);
+    if (values == null || values.size() == 0)
+      return null;
+    return values.get(0);
+  }
+
+  public List<String> getProperty(String key) {
+    return this.properties.getAllMetadata(key);
+  }
+
+  public void removeProperty(String key) {
+    this.properties.removeMetadata(key);
+    this.change = true;
+  }
+
+  public List<String> getKeysRecur(String subGroup) {
+    Vector<String> keys = new Vector<String>();
+    for (String key : this.properties.getAllKeys())
+      if (key.contains(subGroup))
+        keys.add(key);
+    return keys;
+  }
+
+  public void setSelected(ModelGraph selected) {
+    if (this.selected == null || selected == null
+        || !this.selected.equals(selected)) {
+      this.currentMetGroup = null;
+      this.selected = selected;
+      this.change = true;
+    }
+  }
+
+  public ModelGraph getSelected() {
+    if (this.mode.equals(Mode.EDIT))
+      return this.selected;
+    else
+      return null;
+  }
+
+  public Set<String> getGraphIds() {
+    HashSet<String> graphIds = new HashSet<String>();
+    for (ModelGraph graph : this.getGraphs())
+      graphIds.add(graph.getModel().getModelId());
+    return graphIds;
+  }
+
+  public List<ModelGraph> getGraphs() {
+    return this.graphs;
+  }
+
+  public void removeGraph(ModelGraph graph) {
+    this.graphs.remove(graph);
+  }
+
+  public void addGraph(ModelGraph graph) {
+    this.graphs.add(graph);
+  }
+
+  public void setMode(Mode mode) {
+    this.mode = mode;
+    this.change = true;
+  }
+
+  public Mode getMode() {
+    return this.mode;
+  }
+
+  public void setCurrentMetGroup(String currentMetGroup) {
+    this.currentMetGroup = currentMetGroup;
+    this.change = true;
+  }
+
+  public String getCurrentMetGroup() {
+    return this.currentMetGroup;
+  }
+
+  public boolean hasChanged() {
+    return this.change;
+  }
+
+  public void save() {
+    if (this.change) {
+      Stack<ViewState> stack = undoHistory.get(this.id);
+      if (stack == null)
+        stack = new Stack<ViewState>();
+      if (stack.size() >= 100)
+        stack.remove(stack.size() - 1);
+      stack.push(this.clone());
+      undoHistory.put(this.id, stack);
+      this.change = false;
+    }
+  }
+
+  public void undo() {
+    Stack<ViewState> stack = undoHistory.get(this.id);
+    if (stack != null && !stack.empty()) {
+      this.clone(stack.pop());
+      System.out.println(this.getGraphIds());
+      this.change = false;
+    }
+  }
+
+  public void clone(ViewState state) {
+    this.graphs = null;
+    this.selected = null;
+    if (state.graphs != null) {
+      this.graphs = new Vector<ModelGraph>();
+      for (ModelGraph graph : state.graphs)
+        this.graphs.add(graph.clone());
+      if (state.selected != null)
+        this.selected = GuiUtils.find(this.graphs, state.selected.getModel()
+            .getModelId());
+    }
+    this.properties = new Metadata(state.properties);
+    this.id = state.id;
+    this.currentMetGroup = state.currentMetGroup;
+    this.mode = state.mode;
+  }
+
+  public ViewState clone() {
+    List<ModelGraph> cloneGraphs = null;
+    ModelGraph selected = null;
+    if (this.graphs != null) {
+      cloneGraphs = new Vector<ModelGraph>();
+      for (ModelGraph graph : this.graphs)
+        cloneGraphs.add(graph.clone());
+      if (this.selected != null)
+        selected = GuiUtils.find(cloneGraphs, this.selected.getModel()
+            .getModelId());
+    }
+    ViewState clone = new ViewState(this.file, selected, cloneGraphs,
+        this.globalConfigGroups);
+    clone.id = this.id;
+    clone.file = this.file;
+    clone.currentMetGroup = this.currentMetGroup;
+    clone.properties = new Metadata(this.properties);
+    clone.mode = this.mode;
+    return clone;
+  }
+
+  public int hashCode() {
+    return this.id.hashCode();
+  }
+
+  public boolean equals(Object obj) {
+    return obj instanceof ViewState && this.id.equals(((ViewState) obj).id);
+  }
+
+  public String toString() {
+    return this.getId();
+  }
+
+}

Added: oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/DefaultPropView.java
URL: http://svn.apache.org/viewvc/oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/DefaultPropView.java?rev=1145872&view=auto
==============================================================================
--- oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/DefaultPropView.java (added)
+++ oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/DefaultPropView.java Wed Jul 13 06:09:02 2011
@@ -0,0 +1,796 @@
+/**
+ * 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.oodt.cas.workflow.gui.perspective.view.impl;
+
+//JDK imports
+import java.awt.BorderLayout;
+import java.awt.Checkbox;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.text.DecimalFormat;
+import java.text.Format;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Vector;
+import javax.swing.BoxLayout;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JSlider;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.ListSelectionModel;
+import javax.swing.border.EtchedBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.TableModelEvent;
+import javax.swing.event.TableModelListener;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+
+//Apache imports
+import org.apache.commons.lang.StringUtils;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.gui.model.ModelGraph;
+import org.apache.oodt.cas.workflow.gui.perspective.view.View;
+import org.apache.oodt.cas.workflow.gui.perspective.view.ViewState;
+import org.apache.oodt.cas.workflow.gui.util.GuiUtils;
+
+/**
+ * 
+ * 
+ * The default view displaying a workflow property (for a task, or a condition,
+ * or set of workflows).
+ * 
+ * @author bfoster
+ * @author mattmann
+ * 
+ */
+public class DefaultPropView extends View {
+
+  private static final long serialVersionUID = -5521047300551974898L;
+
+  private JTable table;
+  private JPopupMenu tableMenu;
+  private JMenuItem override;
+  private JMenuItem delete;
+  private static final String OVERRIDE = "Override";
+  private static final String DELETE = "Delete";
+  private int DEFAULT_PRIORITY = 5;
+
+  public DefaultPropView(String name) {
+    super(name);
+    this.setLayout(new BorderLayout());
+  }
+
+  private JTable createTable(final ViewState state) {
+    JTable table = null;
+    final ModelGraph selected = state.getSelected();
+    if (selected != null) {
+      final Vector<Vector<String>> rows = new Vector<Vector<String>>();
+      HashMap<String, String> keyToGroupMap = new HashMap<String, String>();
+      Metadata staticMet = selected.getModel().getStaticMetadata();
+      Metadata inheritedMet = selected.getInheritedStaticMetadata(state);
+      Metadata completeMet = new Metadata();
+      if (staticMet != null) {
+        completeMet.replaceMetadata(staticMet.getSubMetadata(state
+            .getCurrentMetGroup()));
+      }
+      if (selected.getModel().getExtendsConfig() != null) {
+        for (String configGroup : selected.getModel().getExtendsConfig()) {
+          Metadata extendsMetadata = state.getGlobalConfigGroups()
+              .get(configGroup).getMetadata()
+              .getSubMetadata(state.getCurrentMetGroup());
+          for (String key : extendsMetadata.getAllKeys()) {
+            if (!completeMet.containsKey(key)) {
+              keyToGroupMap.put(key, configGroup);
+              completeMet.replaceMetadata(key,
+                  extendsMetadata.getAllMetadata(key));
+            }
+          }
+        }
+      }
+      if (inheritedMet != null) {
+        Metadata inheritedMetadata = inheritedMet.getSubMetadata(state
+            .getCurrentMetGroup());
+        for (String key : inheritedMetadata.getAllKeys()) {
+          if (!completeMet.containsKey(key)) {
+            keyToGroupMap.put(key, "__inherited__");
+            completeMet.replaceMetadata(key,
+                inheritedMetadata.getAllMetadata(key));
+          }
+        }
+      }
+      List<String> keys = completeMet.getAllKeys();
+      Collections.sort(keys);
+      for (String key : keys) {
+        if (key.endsWith("/envReplace"))
+          continue;
+        String values = StringUtils.join(completeMet.getAllMetadata(key), ",");
+        Vector<String> row = new Vector<String>();
+        row.add(keyToGroupMap.get(key));
+        row.add(key);
+        row.add(values);
+        row.add(Boolean.toString(Boolean.parseBoolean(completeMet
+            .getMetadata(key + "/envReplace"))));
+        rows.add(row);
+      }
+      table = new JTable();// rows, new Vector<String>(Arrays.asList(new
+                           // String[] { "key", "values", "envReplace" })));
+      table.setModel(new AbstractTableModel() {
+        public String getColumnName(int col) {
+          switch (col) {
+          case 0:
+            return "group";
+          case 1:
+            return "key";
+          case 2:
+            return "values";
+          case 3:
+            return "envReplace";
+          default:
+            return null;
+          }
+        }
+
+        public int getRowCount() {
+          return rows.size() + 1;
+        }
+
+        public int getColumnCount() {
+          return 4;
+        }
+
+        public Object getValueAt(int row, int col) {
+          if (row >= rows.size())
+            return null;
+          String value = rows.get(row).get(col);
+          if (value == null && col == 3)
+            return "false";
+          if (value == null && col == 0)
+            return "__local__";
+          return value;
+        }
+
+        public boolean isCellEditable(int row, int col) {
+          if (row >= rows.size()) {
+            if (selected.getModel().getStaticMetadata()
+                .containsGroup(state.getCurrentMetGroup()))
+              return true;
+            else
+              return false;
+          }
+          if (col == 0)
+            return false;
+          String key = rows.get(row).get(1);
+          if (key == null
+              || (selected.getModel().getStaticMetadata() != null && selected
+                  .getModel().getStaticMetadata()
+                  .containsKey(getKey(key, state))))
+            return true;
+          return false;
+        }
+
+        public void setValueAt(Object value, int row, int col) {
+          if (row >= rows.size()) {
+            Vector<String> newRow = new Vector<String>(Arrays
+                .asList(new String[] { null, null, null, null }));
+            newRow.add(col, (String) value);
+            rows.add(newRow);
+          } else {
+            Vector<String> rowValues = rows.get(row);
+            rowValues.add(col, (String) value);
+            rowValues.remove(col + 1);
+          }
+          this.fireTableCellUpdated(row, col);
+        }
+
+      });
+      MyTableListener tableListener = new MyTableListener(state);
+      table.getModel().addTableModelListener(tableListener);
+      table.getSelectionModel().addListSelectionListener(tableListener);
+    } else {
+      table = new JTable(new Vector<Vector<String>>(), new Vector<String>(
+          Arrays.asList(new String[] { "key", "values", "envReplace" })));
+    }
+
+    // table.setFillsViewportHeight(true);
+    table.setSelectionBackground(Color.cyan);
+    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+    TableCellRenderer cellRenderer = new TableCellRenderer() {
+
+      public Component getTableCellRendererComponent(JTable table,
+          Object value, boolean isSelected, boolean hasFocus, int row,
+          int column) {
+        JLabel field = new JLabel((String) value);
+        if (column == 0) {
+          field.setForeground(Color.gray);
+        } else {
+          if (isSelected)
+            field.setBorder(new EtchedBorder(1));
+          if (table.isCellEditable(row, 1))
+            field.setForeground(Color.black);
+          else
+            field.setForeground(Color.gray);
+        }
+        return field;
+      }
+
+    };
+    TableColumn groupCol = table.getColumnModel().getColumn(0);
+    groupCol.setPreferredWidth(75);
+    groupCol.setCellRenderer(cellRenderer);
+    TableColumn keyCol = table.getColumnModel().getColumn(1);
+    keyCol.setPreferredWidth(200);
+    keyCol.setCellRenderer(cellRenderer);
+    TableColumn valuesCol = table.getColumnModel().getColumn(2);
+    valuesCol.setPreferredWidth(300);
+    valuesCol.setCellRenderer(cellRenderer);
+    TableColumn envReplaceCol = table.getColumnModel().getColumn(3);
+    envReplaceCol.setPreferredWidth(75);
+    envReplaceCol.setCellRenderer(cellRenderer);
+
+    table.addMouseListener(new MouseListener() {
+      public void mouseClicked(MouseEvent e) {
+        if (e.getButton() == MouseEvent.BUTTON3
+            && DefaultPropView.this.table.getSelectedRow() != -1) {
+          int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
+          String key = getKey(
+              (String) DefaultPropView.this.table.getValueAt(row, 1), state);
+          Metadata staticMet = state.getSelected().getModel()
+              .getStaticMetadata();
+          override.setVisible(staticMet == null || !staticMet.containsKey(key));
+          delete.setVisible(staticMet != null && staticMet.containsKey(key));
+          tableMenu.show(DefaultPropView.this.table, e.getX(), e.getY());
+        }
+      }
+
+      public void mouseEntered(MouseEvent e) {
+      }
+
+      public void mouseExited(MouseEvent e) {
+      }
+
+      public void mousePressed(MouseEvent e) {
+      }
+
+      public void mouseReleased(MouseEvent e) {
+      }
+    });
+
+    return table;
+  }
+
+  @Override
+  public void refreshView(final ViewState state) {
+    this.removeAll();
+
+    tableMenu = new JPopupMenu("TableMenu");
+    this.add(tableMenu);
+    override = new JMenuItem(OVERRIDE);
+    override.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) {
+        int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
+        String key = getKey(
+            (String) DefaultPropView.this.table.getValueAt(row, 1), state);
+        Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
+        if (staticMet == null)
+          staticMet = new Metadata();
+        if (e.getActionCommand().equals(OVERRIDE)) {
+          if (!staticMet.containsKey(key)) {
+            staticMet.addMetadata(key,
+                (String) DefaultPropView.this.table.getValueAt(row, 2));
+            String envReplace = (String) DefaultPropView.this.table.getValueAt(
+                row, 3);
+            if (Boolean.valueOf(envReplace))
+              staticMet.addMetadata(key + "/envReplace", envReplace);
+            state.getSelected().getModel().setStaticMetadata(staticMet);
+            DefaultPropView.this.notifyListeners();
+          }
+        }
+      }
+    });
+    delete = new JMenuItem(DELETE);
+    delete.addActionListener(new ActionListener() {
+
+      public void actionPerformed(ActionEvent e) {
+        int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
+        String key = getKey(
+            (String) DefaultPropView.this.table.getValueAt(row, 1), state);
+        Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
+        if (staticMet == null)
+          staticMet = new Metadata();
+        staticMet.removeMetadata(key);
+        staticMet.removeMetadata(key + "/envReplace");
+        state.getSelected().getModel().setStaticMetadata(staticMet);
+        DefaultPropView.this.notifyListeners();
+      }
+
+    });
+    tableMenu.add(override);
+    tableMenu.add(delete);
+
+    if (state.getSelected() != null) {
+      JPanel masterPanel = new JPanel();
+      masterPanel.setLayout(new BoxLayout(masterPanel, BoxLayout.Y_AXIS));
+      masterPanel.add(this.getModelIdPanel(state.getSelected(), state));
+      masterPanel.add(this.getModelNamePanel(state.getSelected(), state));
+      if (!state.getSelected().getModel().isParentType())
+        masterPanel.add(this.getInstanceClassPanel(state.getSelected(), state));
+      masterPanel.add(this.getExecutionTypePanel(state.getSelected(), state));
+      masterPanel.add(this.getPriorityPanel(state));
+      masterPanel.add(this.getExecusedIds(state.getSelected()));
+      JScrollPane scrollPane = new JScrollPane(table = this.createTable(state),
+          JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
+          JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
+      scrollPane.getHorizontalScrollBar().setUnitIncrement(10);
+      scrollPane.getVerticalScrollBar().setUnitIncrement(10);
+      JPanel panel = new JPanel();
+      panel.setLayout(new BorderLayout());
+      panel.setBorder(new EtchedBorder());
+      final JLabel metLabel = new JLabel("Static Metadata");
+      metLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
+      final JLabel extendsLabel = new JLabel("<extends>");
+      extendsLabel.setFont(new Font("Serif", Font.PLAIN, 10));
+      extendsLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
+      extendsLabel.addMouseListener(new MouseListener() {
+
+        private JScrollPane availableScroller;
+        private JScrollPane mineScroller;
+        private JList mineList;
+        private JList availableList;
+        private DefaultListModel mineModel;
+        private DefaultListModel availableModel;
+
+        public void mouseClicked(MouseEvent e) {
+          final JPopupMenu popup = new JPopupMenu();
+          popup.setLayout(new BorderLayout());
+
+          JPanel main = new JPanel();
+          main.setLayout(new BoxLayout(main, BoxLayout.X_AXIS));
+
+          JPanel mine = new JPanel();
+          mine.setBorder(new EtchedBorder());
+          mine.setLayout(new BorderLayout());
+          JLabel mineLabel = new JLabel("Mine");
+          mineScroller = new JScrollPane(mineList = createJList(
+              mineModel = new DefaultListModel(), state.getSelected()
+                  .getModel().getExtendsConfig()));
+          mineScroller.setPreferredSize(new Dimension(250, 80));
+          mine.add(mineLabel, BorderLayout.NORTH);
+          mine.add(mineScroller, BorderLayout.CENTER);
+
+          JPanel available = new JPanel();
+          available.setBorder(new EtchedBorder());
+          available.setLayout(new BorderLayout());
+          JLabel availableLabel = new JLabel("Available");
+          Vector<String> availableGroups = new Vector<String>(state
+              .getGlobalConfigGroups().keySet());
+          availableGroups.removeAll(state.getSelected().getModel()
+              .getExtendsConfig());
+          availableScroller = new JScrollPane(availableList = this.createJList(
+              availableModel = new DefaultListModel(), availableGroups));
+          availableScroller.setPreferredSize(new Dimension(250, 80));
+          available.add(availableLabel, BorderLayout.NORTH);
+          available.add(availableScroller, BorderLayout.CENTER);
+
+          JPanel buttons = new JPanel();
+          buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS));
+          JButton addButton = new JButton("<---");
+          addButton.addMouseListener(new MouseListener() {
+
+            public void mouseClicked(MouseEvent e) {
+              String selected = availableList.getSelectedValue().toString();
+              Vector<String> extendsConfig = new Vector<String>(state
+                  .getSelected().getModel().getExtendsConfig());
+              extendsConfig.add(selected);
+              state.getSelected().getModel().setExtendsConfig(extendsConfig);
+              availableModel.remove(availableList.getSelectedIndex());
+              mineModel.addElement(selected);
+              popup.revalidate();
+              DefaultPropView.this.notifyListeners();
+            }
+
+            public void mouseEntered(MouseEvent e) {
+            }
+
+            public void mouseExited(MouseEvent e) {
+            }
+
+            public void mousePressed(MouseEvent e) {
+            }
+
+            public void mouseReleased(MouseEvent e) {
+            }
+
+          });
+          JButton removeButton = new JButton("--->");
+          removeButton.addMouseListener(new MouseListener() {
+
+            public void mouseClicked(MouseEvent e) {
+              String selected = mineList.getSelectedValue().toString();
+              Vector<String> extendsConfig = new Vector<String>(state
+                  .getSelected().getModel().getExtendsConfig());
+              extendsConfig.remove(selected);
+              state.getSelected().getModel().setExtendsConfig(extendsConfig);
+              mineModel.remove(mineList.getSelectedIndex());
+              availableModel.addElement(selected);
+              popup.revalidate();
+              DefaultPropView.this.notifyListeners();
+            }
+
+            public void mouseEntered(MouseEvent e) {
+            }
+
+            public void mouseExited(MouseEvent e) {
+            }
+
+            public void mousePressed(MouseEvent e) {
+            }
+
+            public void mouseReleased(MouseEvent e) {
+            }
+
+          });
+          buttons.add(addButton);
+          buttons.add(removeButton);
+
+          main.add(mine);
+          main.add(buttons);
+          main.add(available);
+          popup.add(main, BorderLayout.CENTER);
+          popup.show(extendsLabel, e.getX(), e.getY());
+        }
+
+        public void mouseEntered(MouseEvent e) {
+          extendsLabel.setForeground(Color.blue);
+        }
+
+        public void mouseExited(MouseEvent e) {
+          extendsLabel.setForeground(Color.black);
+        }
+
+        public void mousePressed(MouseEvent e) {
+        }
+
+        public void mouseReleased(MouseEvent e) {
+        }
+
+        private JList createJList(DefaultListModel model,
+            final List<String> list) {
+          for (String value : list)
+            model.addElement(value);
+          JList jList = new JList(model);
+          jList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
+          jList.setLayoutOrientation(JList.VERTICAL);
+          return jList;
+        }
+      });
+      JLabel metGroupLabel = new JLabel("(Sub-Group: "
+          + (state.getCurrentMetGroup() != null ? state.getCurrentMetGroup()
+              : "<base>") + ")");
+      metGroupLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
+      JPanel labelPanel = new JPanel();
+      labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
+      JPanel top = new JPanel();
+      top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS));
+      top.add(extendsLabel);
+      top.add(metLabel);
+      labelPanel.add(top);
+      labelPanel.add(metGroupLabel);
+      panel.add(labelPanel, BorderLayout.NORTH);
+      panel.add(scrollPane, BorderLayout.CENTER);
+      masterPanel.add(panel);
+      this.add(masterPanel);
+    } else {
+      this.add(new JPanel());
+    }
+    this.revalidate();
+  }
+
+  private JPanel getModelIdPanel(final ModelGraph graph, final ViewState state) {
+    JPanel panel = new JPanel();
+    panel.setLayout(new BorderLayout());
+    panel.setBorder(new EtchedBorder());
+    panel.add(new JLabel("ModelId:"), BorderLayout.NORTH);
+    JTextField field = new JTextField(graph.getModel().getModelId(), 50);
+    field.addActionListener(new ActionListener() {
+
+      public void actionPerformed(ActionEvent e) {
+        if (!graph.getModel().getModelId().equals(e.getActionCommand())) {
+          GuiUtils.updateGraphModelId(state, graph.getModel().getId(),
+              e.getActionCommand());
+          DefaultPropView.this.notifyListeners();
+          DefaultPropView.this.refreshView(state);
+        }
+      }
+
+    });
+    panel.add(field, BorderLayout.CENTER);
+    return panel;
+  }
+
+  private JPanel getModelNamePanel(final ModelGraph graph, final ViewState state) {
+    JPanel panel = new JPanel();
+    panel.setLayout(new BorderLayout());
+    panel.setBorder(new EtchedBorder());
+    panel.add(new JLabel("ModelName:"), BorderLayout.NORTH);
+    JTextField field = new JTextField(graph.getModel().getModelName(), 50);
+    field.addActionListener(new ActionListener() {
+
+      public void actionPerformed(ActionEvent e) {
+        if (!graph.getModel().getModelName().equals(e.getActionCommand())) {
+          // GuiUtils.updateGraphModelName(getState(),
+          // graph.getModel().getModelId(), e.getActionCommand());
+          graph.getModel().setModelName(e.getActionCommand());
+          DefaultPropView.this.notifyListeners();
+          DefaultPropView.this.refreshView(state);
+        }
+      }
+
+    });
+    panel.add(field, BorderLayout.CENTER);
+    return panel;
+  }
+
+  private JPanel getInstanceClassPanel(final ModelGraph graph,
+      final ViewState state) {
+    JPanel panel = new JPanel();
+    panel.setLayout(new BorderLayout());
+    panel.setBorder(new EtchedBorder());
+    panel.add(new JLabel("InstanceClass:"), BorderLayout.NORTH);
+    JTextField field = new JTextField(graph.getModel().getInstanceClass(), 50);
+    field.addActionListener(new ActionListener() {
+
+      public void actionPerformed(ActionEvent e) {
+        if (graph.getModel().getInstanceClass() == null
+            || !graph.getModel().getInstanceClass()
+                .equals(e.getActionCommand())) {
+          graph.getModel().setInstanceClass(e.getActionCommand());
+          DefaultPropView.this.notifyListeners();
+          DefaultPropView.this.refreshView(state);
+        }
+      }
+
+    });
+    panel.add(field, BorderLayout.CENTER);
+    return panel;
+  }
+
+  private JPanel getPriorityPanel(final ViewState state) {
+    JPanel panel = new JPanel();
+    panel.setBorder(new EtchedBorder());
+    panel.setLayout(new BorderLayout());
+    panel.add(new JLabel("Priority:  "), BorderLayout.WEST);
+    final JLabel priorityLabel = new JLabel(String.valueOf(DEFAULT_PRIORITY));
+    panel.add(priorityLabel, BorderLayout.CENTER);
+    JSlider slider = new JSlider(0, 100, (int) 5 * 10);
+    slider.setMajorTickSpacing(10);
+    slider.setMinorTickSpacing(1);
+    slider.setPaintLabels(true);
+    slider.setPaintTicks(true);
+    slider.setSnapToTicks(false);
+    Format f = new DecimalFormat("0.0");
+    Hashtable<Integer, JComponent> labels = new Hashtable<Integer, JComponent>();
+    for (int i = 0; i <= 10; i += 2) {
+      JLabel label = new JLabel(f.format(i));
+      label.setFont(label.getFont().deriveFont(Font.PLAIN));
+      labels.put(i * 10, label);
+    }
+    slider.setLabelTable(labels);
+    slider.addChangeListener(new ChangeListener() {
+
+      public void stateChanged(ChangeEvent e) {
+        double value = ((JSlider) e.getSource()).getValue() / 10.0;
+        priorityLabel.setText(value + "");
+        priorityLabel.revalidate();
+        if (!((JSlider) e.getSource()).getValueIsAdjusting()) {
+          // FIXME: deal with priorities
+          DefaultPropView.this.notifyListeners();
+        }
+      }
+
+    });
+
+    panel.add(slider, BorderLayout.SOUTH);
+    return panel;
+  }
+
+  private JPanel getExecutionTypePanel(final ModelGraph graph,
+      final ViewState state) {
+    JPanel panel = new JPanel();
+    panel.setBorder(new EtchedBorder());
+    panel.setLayout(new BorderLayout());
+    panel.add(new JLabel("ExecutionType:"), BorderLayout.WEST);
+    JComboBox comboBox = new JComboBox();
+    if (graph.hasChildren()) {
+      comboBox.addItem("parallel");
+      comboBox.addItem("sequential");
+    } else if (graph.getModel().getExecutionType().equals("task")) {
+      comboBox.addItem("parallel");
+      comboBox.addItem("sequential");
+      comboBox.addItem("task");
+    } else if (graph.isCondition()
+        || graph.getModel().getExecutionType().equals("condition")) {
+      comboBox.addItem("parallel");
+      comboBox.addItem("sequential");
+      comboBox.addItem("condition");
+    } else {
+      comboBox.addItem("parallel");
+      comboBox.addItem("sequential");
+      comboBox.addItem("task");
+    }
+    comboBox.setSelectedItem(graph.getModel().getExecutionType());
+    comboBox.addItemListener(new ItemListener() {
+      public void itemStateChanged(ItemEvent e) {
+        if (!graph.getModel().getExecutionType().equals(e.getItem())) {
+          graph.getModel().setExecutionType((String) e.getItem());
+          DefaultPropView.this.notifyListeners();
+          DefaultPropView.this.refreshView(state);
+        }
+      }
+    });
+    panel.add(comboBox, BorderLayout.CENTER);
+    return panel;
+  }
+
+  private JPanel getExecusedIds(final ModelGraph graph) {
+    JPanel panel = new JPanel();
+    panel.setLayout(new BorderLayout());
+    panel.setBorder(new EtchedBorder());
+    panel.add(new JLabel("ExcusedSubProcessorIds:"), BorderLayout.NORTH);
+    JPanel checkBoxes = new JPanel();
+    checkBoxes.setLayout(new GridLayout(graph.getChildren().size(), 1));
+    if (graph.hasChildren()) {
+      for (ModelGraph childGraph : graph.getChildren()) {
+        final String modelId = childGraph.getModel().getModelId();
+        Checkbox checkbox = new Checkbox(modelId, graph.getModel()
+            .getExcusedSubProcessorIds().contains(modelId));
+        checkBoxes.add(checkbox);
+        checkbox.addItemListener(new ItemListener() {
+
+          public void itemStateChanged(ItemEvent e) {
+            if (e.getStateChange() == ItemEvent.DESELECTED)
+              graph.getModel().getExcusedSubProcessorIds().remove(modelId);
+            else if (e.getStateChange() == ItemEvent.SELECTED)
+              graph.getModel().getExcusedSubProcessorIds().add(modelId);
+            else
+              return;
+            DefaultPropView.this.notifyListeners();
+          }
+
+        });
+      }
+    }
+    panel.add(checkBoxes, BorderLayout.CENTER);
+    return panel;
+  }
+
+  public class MyTableListener implements TableModelListener,
+      ListSelectionListener {
+
+    String oldKey, oldValue, oldEnvReplace;
+
+    private ViewState state;
+
+    public MyTableListener(ViewState state) {
+      this.state = state;
+    }
+
+    public void tableChanged(TableModelEvent e) {
+      System.out.println(oldKey + " " + oldValue + " " + oldEnvReplace);
+      if (e.getType() == TableModelEvent.UPDATE) {
+        Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
+        if (staticMet == null)
+          staticMet = new Metadata();
+        if (e.getColumn() == 1) {
+          String newGrouplessKey = (String) table.getValueAt(e.getFirstRow(),
+              e.getColumn());
+          if (newGrouplessKey.equals("")
+              || (newGrouplessKey.equals("envReplace") && !state.getSelected()
+                  .getModel().getStaticMetadata()
+                  .containsGroup(state.getCurrentMetGroup()))) {
+            notifyListeners();
+            return;
+          }
+          String newKey = getKey(newGrouplessKey, state);
+          System.out.println("newKey: " + newKey);
+          if (oldKey != null) {
+            staticMet.replaceMetadata(newKey, staticMet.getAllMetadata(oldKey));
+            if (staticMet.containsKey(oldKey + "/envReplace"))
+              staticMet.replaceMetadata(newKey,
+                  staticMet.getAllMetadata(oldKey + "/envReplace"));
+            if (!newKey.equals(oldKey))
+              staticMet.removeMetadata(oldKey);
+            notifyListeners();
+          } else {
+            staticMet.replaceMetadata(oldKey = newKey, (String) null);
+          }
+        } else if (e.getColumn() == 2) {
+          if (oldKey != null) {
+            String newValue = (String) table.getValueAt(e.getFirstRow(),
+                e.getColumn());
+            if (oldKey.endsWith("/envReplace")) {
+              newValue = newValue.toLowerCase();
+              if (newValue.equals("false"))
+                staticMet.removeMetadata(oldKey);
+              else
+                staticMet.replaceMetadata(oldKey,
+                    Arrays.asList(newValue.split(",")));
+            } else {
+              staticMet.replaceMetadata(oldKey,
+                  Arrays.asList(newValue.split(",")));
+            }
+            notifyListeners();
+          }
+        } else if (e.getColumn() == 3) {
+          if (oldKey != null) {
+            String newEnvReplace = ((String) table.getValueAt(e.getFirstRow(),
+                e.getColumn())).toLowerCase();
+            if (newEnvReplace.equals("true"))
+              staticMet.replaceMetadata(oldKey + "/envReplace", newEnvReplace);
+            else
+              staticMet.removeMetadata(oldKey + "/envReplace");
+            notifyListeners();
+          }
+        }
+        state.getSelected().getModel().setStaticMetadata(staticMet);
+      }
+
+    }
+
+    public void valueChanged(ListSelectionEvent e) {
+      oldKey = getKey((String) table.getValueAt(e.getFirstIndex(), 1), state);
+      oldValue = (String) table.getValueAt(e.getFirstIndex(), 2);
+      oldEnvReplace = (String) table.getValueAt(e.getFirstIndex(), 3);
+    }
+
+  }
+
+  private String getKey(String key, ViewState state) {
+    if (key != null && state.getCurrentMetGroup() != null)
+      return state.getCurrentMetGroup() + "/" + key;
+    else
+      return key;
+  }
+
+}

Added: oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/DefaultTreeView.java
URL: http://svn.apache.org/viewvc/oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/DefaultTreeView.java?rev=1145872&view=auto
==============================================================================
--- oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/DefaultTreeView.java (added)
+++ oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/DefaultTreeView.java Wed Jul 13 06:09:02 2011
@@ -0,0 +1,483 @@
+/**
+ * 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.oodt.cas.workflow.gui.perspective.view.impl;
+
+//JDK imports
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.MenuItem;
+import java.awt.PopupMenu;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Stack;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTree;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreeCellRenderer;
+import javax.swing.tree.TreePath;
+
+//Apache imports
+import org.apache.commons.lang.StringUtils;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.gui.model.ModelGraph;
+import org.apache.oodt.cas.workflow.gui.perspective.view.View;
+import org.apache.oodt.cas.workflow.gui.perspective.view.ViewChange;
+import org.apache.oodt.cas.workflow.gui.perspective.view.ViewState;
+import org.apache.oodt.cas.workflow.gui.util.GuiUtils;
+
+/**
+ * 
+ * The default Workflow GUI editor view shell.
+ * 
+ * @author bfoster
+ * @author mattmann
+ * 
+ */
+public class DefaultTreeView extends View {
+
+  private static final long serialVersionUID = -8295070597651190576L;
+
+  private JTree tree;
+  private PopupMenu actionsMenu, orderSubMenu;
+  private JScrollPane scrollPane;
+
+  private static final String EXPAND_STATIC_METADATA = "DefaultTreeView/expand/static-metadata";
+  private static final String EXPAND_PRECONDITIONS = "DefaultTreeView/expand/pre-conditions";
+  private static final String EXPAND_POSTCONDITIONS = "DefaultTreeView/expand/post-conditions";
+
+  public DefaultTreeView(String name) {
+    super(name);
+    this.setLayout(new BorderLayout());
+  }
+
+  public TreePath getTreePath(DefaultMutableTreeNode node, ModelGraph graph) {
+    if (node.getUserObject().equals(graph)) {
+      return new TreePath(node.getPath());
+    } else {
+      for (int i = 0; i < node.getChildCount(); i++) {
+        // System.out.println("i: " + ((DefaultMutableTreeNode)
+        // node.getChildAt(i)).getUserObject());
+        TreePath treePath = this.getTreePath(
+            (DefaultMutableTreeNode) node.getChildAt(i), graph);
+        if (treePath != null)
+          return treePath;
+      }
+      return null;
+    }
+  }
+
+  private TreePath getTreePath(TreePath currentPath, ViewState state) {
+    String lookingForPath = state.getCurrentMetGroup();
+    Stack<DefaultMutableTreeNode> stack = new Stack<DefaultMutableTreeNode>();
+    DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) currentPath
+        .getLastPathComponent();
+    for (int i = 0; i < baseNode.getChildCount(); i++)
+      stack.push((DefaultMutableTreeNode) baseNode.getChildAt(i));
+    while (!stack.empty()) {
+      DefaultMutableTreeNode node = stack.pop();
+      if (node.getUserObject().equals("static-metadata")) {
+        for (int i = 0; i < node.getChildCount(); i++)
+          stack.push((DefaultMutableTreeNode) node.getChildAt(i));
+      } else if (node.getUserObject() instanceof HashMap) {
+        String key = (String) ((HashMap<String, String>) node.getUserObject())
+            .keySet().iterator().next();
+        if (lookingForPath.equals(key)) {
+          return new TreePath(node.getPath());
+        } else if (lookingForPath.startsWith(key + "/")) {
+          lookingForPath = lookingForPath
+              .substring(lookingForPath.indexOf("/") + 1);
+          stack.clear();
+          for (int i = 0; i < node.getChildCount(); i++)
+            stack.add((DefaultMutableTreeNode) node.getChildAt(i));
+        }
+      }
+    }
+    return currentPath;
+  }
+
+  private void resetProperties(ViewState state) {
+    state.setProperty(EXPAND_STATIC_METADATA, "false");
+    state.setProperty(EXPAND_PRECONDITIONS, "false");
+    state.setProperty(EXPAND_POSTCONDITIONS, "false");
+  }
+
+  @Override
+  public void refreshView(final ViewState state) {
+    Rectangle visibleRect = null;
+    if (this.tree != null)
+      visibleRect = this.tree.getVisibleRect();
+
+    this.removeAll();
+
+    this.actionsMenu = this.createPopupMenu(state);
+
+    DefaultMutableTreeNode root = new DefaultMutableTreeNode("WORKFLOWS");
+    for (ModelGraph graph : state.getGraphs())
+      root.add(this.buildTree(graph, state));
+    tree = new JTree(root);
+    tree.setShowsRootHandles(true);
+    tree.setRootVisible(false);
+    tree.add(this.actionsMenu);
+
+    if (state.getSelected() != null) {
+      // System.out.println("SELECTED: " + state.getSelected());
+      TreePath treePath = this.getTreePath(root, state.getSelected());
+      if (state.getCurrentMetGroup() != null) {
+        treePath = this.getTreePath(treePath, state);
+      } else if (Boolean.parseBoolean(state
+          .getFirstPropertyValue(EXPAND_STATIC_METADATA))) {
+        DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath
+            .getLastPathComponent();
+        for (int i = 0; i < baseNode.getChildCount(); i++) {
+          if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject()
+              .equals("static-metadata")) {
+            treePath = new TreePath(
+                ((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath());
+            break;
+          }
+        }
+      } else if (Boolean.parseBoolean(state
+          .getFirstPropertyValue(EXPAND_PRECONDITIONS))) {
+        if (treePath == null)
+          treePath = this.getTreePath(root, state.getSelected()
+              .getPreConditions());
+        DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath
+            .getLastPathComponent();
+        for (int i = 0; i < baseNode.getChildCount(); i++) {
+          if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject()
+              .equals("pre-conditions")) {
+            treePath = new TreePath(
+                ((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath());
+            break;
+          }
+        }
+      } else if (Boolean.parseBoolean(state
+          .getFirstPropertyValue(EXPAND_POSTCONDITIONS))) {
+        if (treePath == null)
+          treePath = this.getTreePath(root, state.getSelected()
+              .getPostConditions());
+        DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath
+            .getLastPathComponent();
+        for (int i = 0; i < baseNode.getChildCount(); i++) {
+          if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject()
+              .equals("post-conditions")) {
+            treePath = new TreePath(
+                ((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath());
+            break;
+          }
+        }
+      }
+      this.tree.expandPath(treePath);
+      this.tree.setSelectionPath(treePath);
+    }
+
+    tree.addTreeSelectionListener(new TreeSelectionListener() {
+
+      public void valueChanged(TreeSelectionEvent e) {
+        if (e.getPath().getLastPathComponent() instanceof DefaultMutableTreeNode) {
+          DefaultTreeView.this.resetProperties(state);
+          DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath()
+              .getLastPathComponent();
+          if (node.getUserObject() instanceof ModelGraph) {
+            state.setSelected((ModelGraph) node.getUserObject());
+            state.setCurrentMetGroup(null);
+            DefaultTreeView.this.notifyListeners();
+          } else if (node.getUserObject().equals("static-metadata")
+              || node.getUserObject().equals("pre-conditions")
+              || node.getUserObject().equals("post-conditions")) {
+            state.setSelected((ModelGraph) ((DefaultMutableTreeNode) node
+                .getParent()).getUserObject());
+            state.setCurrentMetGroup(null);
+            state.setProperty(EXPAND_STATIC_METADATA, Boolean.toString(node
+                .getUserObject().equals("static-metadata")));
+            state.setProperty(EXPAND_PRECONDITIONS,
+                Boolean.toString(node.getUserObject().equals("pre-conditions")));
+            state.setProperty(EXPAND_POSTCONDITIONS, Boolean.toString(node
+                .getUserObject().equals("post-conditions")));
+            DefaultTreeView.this.notifyListeners();
+          } else if (node.getUserObject() instanceof HashMap) {
+            DefaultMutableTreeNode metNode = null;
+            String group = null;
+            Object[] path = e.getPath().getPath();
+            for (int i = path.length - 1; i >= 0; i--) {
+              if (((DefaultMutableTreeNode) path[i]).getUserObject() instanceof ModelGraph) {
+                metNode = (DefaultMutableTreeNode) path[i];
+                break;
+              } else if (((DefaultMutableTreeNode) path[i]).getUserObject() instanceof HashMap) {
+                if (group == null)
+                  group = (String) ((HashMap<String, String>) ((DefaultMutableTreeNode) path[i])
+                      .getUserObject()).keySet().iterator().next();
+                else
+                  group = (String) ((HashMap<String, String>) ((DefaultMutableTreeNode) path[i])
+                      .getUserObject()).keySet().iterator().next()
+                      + "/"
+                      + group;
+              }
+            }
+            ModelGraph graph = (ModelGraph) metNode.getUserObject();
+            state.setSelected(graph);
+            state.setCurrentMetGroup(group);
+            DefaultTreeView.this.notifyListeners();
+          } else {
+            state.setSelected(null);
+            DefaultTreeView.this.notifyListeners();
+          }
+        }
+      }
+
+    });
+    tree.setCellRenderer(new TreeCellRenderer() {
+
+      public Component getTreeCellRendererComponent(JTree tree, Object value,
+          boolean selected, boolean expanded, boolean leaf, int row,
+          boolean hasFocus) {
+        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
+        if (node.getUserObject() instanceof String) {
+          JPanel panel = new JPanel();
+          panel.setLayout(new BorderLayout());
+          JLabel label = new JLabel((String) node.getUserObject());
+          label.setForeground(Color.blue);
+          panel.add(label, BorderLayout.CENTER);
+          panel.setBackground(selected ? Color.lightGray : Color.white);
+          return panel;
+        } else if (node.getUserObject() instanceof ModelGraph) {
+          JPanel panel = new JPanel();
+          panel.setLayout(new BorderLayout());
+          JLabel iconLabel = new JLabel(((ModelGraph) node.getUserObject())
+              .getModel().getExecutionType() + ": ");
+          iconLabel.setForeground(((ModelGraph) node.getUserObject())
+              .getModel().getColor());
+          iconLabel.setBackground(Color.white);
+          JLabel idLabel = new JLabel(((ModelGraph) node.getUserObject())
+              .getModel().getModelName());
+          idLabel.setBackground(Color.white);
+          panel.add(iconLabel, BorderLayout.WEST);
+          panel.add(idLabel, BorderLayout.CENTER);
+          panel.setBackground(selected ? Color.lightGray : Color.white);
+          return panel;
+        } else if (node.getUserObject() instanceof HashMap) {
+          JPanel panel = new JPanel();
+          panel.setLayout(new BorderLayout());
+          String group = (String) ((HashMap<String, String>) node
+              .getUserObject()).keySet().iterator().next();
+          JLabel nameLabel = new JLabel(group + " : ");
+          nameLabel.setForeground(Color.blue);
+          nameLabel.setBackground(Color.white);
+          JLabel valueLabel = new JLabel(((HashMap<String, String>) node
+              .getUserObject()).get(group));
+          valueLabel.setForeground(Color.darkGray);
+          valueLabel.setBackground(Color.white);
+          panel.add(nameLabel, BorderLayout.WEST);
+          panel.add(valueLabel, BorderLayout.EAST);
+          panel.setBackground(selected ? Color.lightGray : Color.white);
+          return panel;
+        } else {
+          return new JLabel();
+        }
+      }
+
+    });
+    tree.addMouseListener(new MouseListener() {
+      public void mouseClicked(MouseEvent e) {
+        if (e.getButton() == MouseEvent.BUTTON3
+            && DefaultTreeView.this.tree.getSelectionPath() != null) {
+          DefaultMutableTreeNode node = (DefaultMutableTreeNode) DefaultTreeView.this.tree
+              .getSelectionPath().getLastPathComponent();
+          if (node.getUserObject() instanceof String
+              && !(node.getUserObject().equals("pre-conditions") || node
+                  .getUserObject().equals("post-conditions")))
+            return;
+          orderSubMenu.setEnabled(node.getUserObject() instanceof ModelGraph
+              && !((ModelGraph) node.getUserObject()).isCondition()
+              && ((ModelGraph) node.getUserObject()).getParent() != null);
+          DefaultTreeView.this.actionsMenu.show(DefaultTreeView.this.tree,
+              e.getX(), e.getY());
+        }
+      }
+
+      public void mouseEntered(MouseEvent e) {
+      }
+
+      public void mouseExited(MouseEvent e) {
+      }
+
+      public void mousePressed(MouseEvent e) {
+      }
+
+      public void mouseReleased(MouseEvent e) {
+      }
+    });
+    this.scrollPane = new JScrollPane(tree,
+        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
+        JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
+    this.add(this.scrollPane, BorderLayout.CENTER);
+    if (visibleRect != null)
+      this.tree.scrollRectToVisible(visibleRect);
+
+    this.revalidate();
+  }
+
+  private DefaultMutableTreeNode buildTree(ModelGraph graph, ViewState state) {
+    DefaultMutableTreeNode node = new DefaultMutableTreeNode(graph);
+    DefaultMutableTreeNode metadataNode = new DefaultMutableTreeNode(
+        "static-metadata");
+    Metadata staticMetadata = new Metadata();
+    if (graph.getInheritedStaticMetadata(state) != null)
+      staticMetadata.replaceMetadata(graph.getInheritedStaticMetadata(state));
+    if (graph.getModel().getStaticMetadata() != null)
+      staticMetadata.replaceMetadata(graph.getModel().getStaticMetadata());
+    this.addMetadataNodes(metadataNode, staticMetadata);
+    if (!metadataNode.isLeaf())
+      node.add(metadataNode);
+
+    if (graph.getPreConditions() != null) {
+      DefaultMutableTreeNode preConditions = new DefaultMutableTreeNode(
+          "pre-conditions");
+      List<ModelGraph> leafNodes = graph.getPreConditions().getLeafNodes();
+      for (ModelGraph cond : leafNodes) {
+        DefaultMutableTreeNode condNode = new DefaultMutableTreeNode(cond);
+        preConditions.add(condNode);
+      }
+      node.add(preConditions);
+    }
+    if (graph.getPostConditions() != null) {
+      DefaultMutableTreeNode postConditions = new DefaultMutableTreeNode(
+          "post-conditions");
+      List<ModelGraph> leafNodes = graph.getPostConditions().getLeafNodes();
+      for (ModelGraph cond : leafNodes) {
+        DefaultMutableTreeNode condNode = new DefaultMutableTreeNode(cond);
+        postConditions.add(condNode);
+      }
+      node.add(postConditions);
+    }
+    for (ModelGraph child : graph.getChildren())
+      if (!GuiUtils.isDummyNode(child.getModel()))
+        node.add(this.buildTree(child, state));
+    return node;
+  }
+
+  private void addMetadataNodes(DefaultMutableTreeNode metadataNode,
+      Metadata staticMetadata) {
+    for (String group : staticMetadata.getGroups()) {
+      Object userObj = null;
+      if (staticMetadata.getMetadata(group) != null) {
+        HashMap<String, String> map = new HashMap<String, String>();
+        map.put(group,
+            StringUtils.join(staticMetadata.getAllMetadata(group), ","));
+        userObj = map;
+      } else {
+        HashMap<String, String> map = new HashMap<String, String>();
+        map.put(group, null);
+        userObj = map;
+      }
+      DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode(userObj);
+      metadataNode.add(groupNode);
+      this.addMetadataNodes(groupNode, staticMetadata.getSubMetadata(group));
+    }
+  }
+
+  private PopupMenu createPopupMenu(final ViewState state) {
+    final String ACTIONS_POP_MENU_NAME = "Actions";
+    final String VIEW_CONDITION_MAP = "View...";
+    PopupMenu actionsMenu = new PopupMenu(ACTIONS_POP_MENU_NAME);
+    actionsMenu.add(new MenuItem(VIEW_CONDITION_MAP));
+    actionsMenu.addActionListener(new ActionListener() {
+
+      public void actionPerformed(ActionEvent e) {
+        if (e.getActionCommand().equals(VIEW_CONDITION_MAP)) {
+          DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
+              .getSelectionPath().getLastPathComponent();
+          ModelGraph graphToFocus = null;
+          if (Boolean.parseBoolean(state
+              .getFirstPropertyValue(EXPAND_PRECONDITIONS))
+              || Boolean.parseBoolean(state
+                  .getFirstPropertyValue(EXPAND_POSTCONDITIONS))) {
+            // if (node.getUserObject() instanceof String &&
+            // (node.getUserObject().equals("pre-conditions") ||
+            // node.getUserObject().equals("post-conditions"))) {
+            ModelGraph graph = state.getSelected();
+            if (Boolean.parseBoolean(state
+                .getFirstPropertyValue(EXPAND_PRECONDITIONS)))
+              graphToFocus = graph.getPreConditions();
+            else
+              graphToFocus = graph.getPostConditions();
+          } else if (node.getUserObject() instanceof ModelGraph) {
+            graphToFocus = (ModelGraph) node.getUserObject();
+          }
+          DefaultTreeView.this.notifyListeners(new ViewChange.NEW_VIEW(
+              graphToFocus, DefaultTreeView.this));
+        }
+      }
+
+    });
+
+    final String ORDER_SUB_POP_MENU_NAME = "Order";
+    final String TO_FRONT_ITEM_NAME = "Move To Front";
+    final String TO_BACK_ITEM_NAME = "Move To Back";
+    final String FORWARD_ITEM_NAME = "Move Forward";
+    final String BACKWARDS_ITEM_NAME = "Move Backwards";
+    actionsMenu.add(orderSubMenu = new PopupMenu(ORDER_SUB_POP_MENU_NAME));
+    orderSubMenu.add(new MenuItem(TO_FRONT_ITEM_NAME));
+    orderSubMenu.add(new MenuItem(TO_BACK_ITEM_NAME));
+    orderSubMenu.add(new MenuItem(FORWARD_ITEM_NAME));
+    orderSubMenu.add(new MenuItem(BACKWARDS_ITEM_NAME));
+    orderSubMenu.addActionListener(new ActionListener() {
+
+      public void actionPerformed(ActionEvent e) {
+        ModelGraph graph = state.getSelected();
+        ModelGraph parent = graph.getParent();
+        if (e.getActionCommand().equals(TO_FRONT_ITEM_NAME)) {
+          if (parent.getChildren().remove(graph))
+            parent.getChildren().add(0, graph);
+        } else if (e.getActionCommand().equals(TO_BACK_ITEM_NAME)) {
+          if (parent.getChildren().remove(graph))
+            parent.getChildren().add(graph);
+        } else if (e.getActionCommand().equals(FORWARD_ITEM_NAME)) {
+          int index = parent.getChildren().indexOf(graph);
+          if (index != -1) {
+            parent.getChildren().remove(index);
+            parent.getChildren().add(Math.max(0, index + 1), graph);
+          }
+        } else if (e.getActionCommand().equals(BACKWARDS_ITEM_NAME)) {
+          int index = parent.getChildren().indexOf(graph);
+          if (index != -1) {
+            parent.getChildren().remove(index);
+            parent.getChildren().add(Math.max(0, index - 1), graph);
+          }
+        }
+        DefaultTreeView.this.notifyListeners();
+        DefaultTreeView.this.refreshView(state);
+      }
+
+    });
+    return actionsMenu;
+  }
+
+}
\ No newline at end of file

Added: oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/GlobalConfigView.java
URL: http://svn.apache.org/viewvc/oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/GlobalConfigView.java?rev=1145872&view=auto
==============================================================================
--- oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/GlobalConfigView.java (added)
+++ oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/perspective/view/impl/GlobalConfigView.java Wed Jul 13 06:09:02 2011
@@ -0,0 +1,267 @@
+/**
+ * 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.oodt.cas.workflow.gui.perspective.view.impl;
+
+//JDK imports
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Rectangle;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JTree;
+import javax.swing.border.EtchedBorder;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreeCellRenderer;
+
+//Apache imports
+import org.apache.commons.lang.StringUtils;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.gui.model.repo.XmlWorkflowModelRepository.ConfigGroup;
+import org.apache.oodt.cas.workflow.gui.perspective.view.View;
+import org.apache.oodt.cas.workflow.gui.perspective.view.ViewState;
+
+/**
+ * 
+ * Displays information about global config properties loaded from the
+ * Workflows.
+ * 
+ * @author bfoster
+ * @author mattmann
+ * 
+ */
+public class GlobalConfigView extends View {
+
+  private static final long serialVersionUID = 3899104909278232407L;
+  private JTree tree;
+  private JTabbedPane tabbedPane;
+  private Map<String, ConfigGroup> globalConfig;
+
+  public GlobalConfigView(String name) {
+    super(name);
+    this.setLayout(new BorderLayout());
+  }
+
+  @Override
+  public void refreshView(ViewState state) {
+
+    Rectangle visibleRect = null;
+    if (this.tree != null)
+      visibleRect = this.tree.getVisibleRect();
+
+    DefaultMutableTreeNode root = new DefaultMutableTreeNode("GlobalConfig");
+
+    if (state != null && state.getGlobalConfigGroups() != null) {
+      if (globalConfig != null
+          && globalConfig.keySet().equals(
+              state.getGlobalConfigGroups().keySet())
+          && globalConfig.values().equals(
+              state.getGlobalConfigGroups().values()))
+        return;
+
+      this.removeAll();
+
+      for (ConfigGroup group : (globalConfig = state.getGlobalConfigGroups())
+          .values()) {
+        HashSet<String> keys = new HashSet<String>();
+        DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode(
+            new Group(group.getName()));
+        root.add(groupNode);
+        for (String key : group.getMetadata().getAllKeys()) {
+          keys.add(key);
+          DefaultMutableTreeNode keyNode = new DefaultMutableTreeNode(new Key(
+              key));
+          groupNode.add(keyNode);
+          DefaultMutableTreeNode valueNode = new DefaultMutableTreeNode(
+              new Value(StringUtils.join(group.getMetadata()
+                  .getAllMetadata(key), ",")));
+          keyNode.add(valueNode);
+        }
+        if (group.getExtends() != null) {
+          List<String> extendsGroups = new Vector<String>(group.getExtends());
+          Collections.reverse(extendsGroups);
+          for (String extendsGroup : extendsGroups) {
+            List<String> groupKeys = state.getGlobalConfigGroups()
+                .get(extendsGroup).getMetadata().getAllKeys();
+            groupKeys.removeAll(keys);
+            if (groupKeys.size() > 0) {
+              for (String key : groupKeys) {
+                if (!keys.contains(key)) {
+                  keys.add(key);
+                  DefaultMutableTreeNode keyNode = new DefaultMutableTreeNode(
+                      new ExtendsKey(extendsGroup, key));
+                  groupNode.add(keyNode);
+                  DefaultMutableTreeNode valueNode = new DefaultMutableTreeNode(
+                      new ExtendsValue(StringUtils.join(state
+                          .getGlobalConfigGroups().get(extendsGroup)
+                          .getMetadata().getAllMetadata(key), ",")));
+                  keyNode.add(valueNode);
+                }
+              }
+            }
+          }
+        }
+      }
+
+      tree = new JTree(root);
+      tree.setShowsRootHandles(true);
+      tree.setRootVisible(false);
+
+      tree.setCellRenderer(new TreeCellRenderer() {
+
+        public Component getTreeCellRendererComponent(JTree tree, Object value,
+            boolean selected, boolean expanded, boolean leaf, int row,
+            boolean hasFocus) {
+          DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
+          if (node.getUserObject() instanceof Key) {
+            JPanel panel = new JPanel();
+            panel.setLayout(new BorderLayout());
+            JLabel label = new JLabel(node.getUserObject().toString());
+            label.setForeground(Color.darkGray);
+            panel.add(label, BorderLayout.CENTER);
+            panel.setBackground(selected ? Color.lightGray : Color.white);
+            return panel;
+          } else if (node.getUserObject() instanceof ExtendsKey) {
+            JPanel panel = new JPanel();
+            panel.setLayout(new BorderLayout());
+            ExtendsKey key = (ExtendsKey) node.getUserObject();
+            JLabel groupLabel = new JLabel("(" + key.getGroup() + ") ");
+            groupLabel.setForeground(Color.black);
+            JLabel keyLabel = new JLabel(key.getValue());
+            keyLabel.setForeground(Color.gray);
+            panel.add(groupLabel, BorderLayout.WEST);
+            panel.add(keyLabel, BorderLayout.CENTER);
+            panel.setBackground(selected ? Color.lightGray : Color.white);
+            return panel;
+          } else if (node.getUserObject() instanceof Group) {
+            JPanel panel = new JPanel();
+            panel.setLayout(new BorderLayout());
+            JLabel label = new JLabel(node.getUserObject().toString());
+            label.setForeground(Color.black);
+            label.setBackground(Color.white);
+            panel.add(label, BorderLayout.CENTER);
+            panel.setBackground(selected ? Color.lightGray : Color.white);
+            return panel;
+          } else if (node.getUserObject() instanceof Value) {
+            JPanel panel = new JPanel();
+            panel.setLayout(new BorderLayout());
+            panel.setBorder(new EtchedBorder(1));
+            JLabel label = new JLabel(node.getUserObject().toString());
+            label.setForeground(Color.black);
+            panel.add(label, BorderLayout.CENTER);
+            panel.setBackground(selected ? Color.lightGray : Color.white);
+            return panel;
+          } else if (node.getUserObject() instanceof ExtendsValue) {
+            JPanel panel = new JPanel();
+            panel.setLayout(new BorderLayout());
+            panel.setBorder(new EtchedBorder(1));
+            JLabel label = new JLabel(node.getUserObject().toString());
+            label.setForeground(Color.gray);
+            panel.add(label, BorderLayout.CENTER);
+            panel.setBackground(selected ? Color.lightGray : Color.white);
+            return panel;
+          } else {
+            return new JLabel();
+          }
+        }
+
+      });
+    }
+
+    this.setBorder(new EtchedBorder());
+    JLabel panelName = new JLabel("Global-Config Groups");
+    panelName.setBorder(new EtchedBorder());
+    this.add(panelName, BorderLayout.NORTH);
+    JScrollPane scrollPane = new JScrollPane(tree,
+        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
+        JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
+
+    tabbedPane = new JTabbedPane();
+    tabbedPane.addTab("Tree", scrollPane);
+    tabbedPane.addTab("Table", new JPanel());
+
+    this.add(tabbedPane, BorderLayout.CENTER);
+
+    if (visibleRect != null)
+      this.tree.scrollRectToVisible(visibleRect);
+
+    this.revalidate();
+  }
+
+  public class StringNode {
+    private String value;
+
+    public StringNode(String value) {
+      this.value = value;
+    }
+
+    public String getValue() {
+      return this.value;
+    }
+
+    public String toString() {
+      return this.value;
+    }
+  }
+
+  public class Key extends StringNode {
+    public Key(String value) {
+      super(value);
+    }
+  }
+
+  public class ExtendsKey extends StringNode {
+    private String group;
+
+    public ExtendsKey(String group, String value) {
+      super(value);
+      this.group = group;
+    }
+
+    public String getGroup() {
+      return this.group;
+    }
+  }
+
+  public class ExtendsValue extends StringNode {
+    public ExtendsValue(String value) {
+      super(value);
+    }
+  }
+
+  public class Value extends StringNode {
+    public Value(String value) {
+      super(value);
+    }
+  }
+
+  public class Group extends StringNode {
+    public Group(String group) {
+      super(group);
+    }
+  }
+
+}