001: package com.opensymphony.workflow.designer;
002:
003: import java.util.List;
004: import java.util.ArrayList;
005: import javax.swing.*;
006: import javax.swing.event.*;
007:
008: /**
009: * User: Hani Suleiman
010: * Date: Jan 9, 2004
011: * Time: 1:22:46 PM
012: */
013: public class GraphTabbedPane extends JTabbedPane {
014: private List graphs = new ArrayList();
015:
016: public GraphTabbedPane() {
017: // register a change listener
018: addChangeListener(new ChangeListener() {
019: // this method is called whenever the selected tab changes
020: public void stateChanged(ChangeEvent evt) {
021: WorkflowDesigner.INSTANCE.showSelectedCellDetails();
022: }
023: });
024: }
025:
026: public WorkflowGraph getCurrentGraph() {
027: int index = getSelectedIndex();
028: if (index == -1 || index >= graphs.size())
029: return null;
030: return (WorkflowGraph) graphs.get(index);
031: }
032:
033: public boolean selectWorkflow(String workflowName) {
034: for (int i = 0; i < getTabCount(); i++) {
035: String name = getTitleAt(i);
036: if (name.equals(workflowName)) {
037: setSelectedIndex(i);
038: getCurrentGraph().getSelectionModel().clearSelection();
039: return true;
040: }
041: }
042: return false;
043: }
044:
045: public void addGraph(WorkflowGraph graph) {
046: graphs.add(graph);
047: add(graph.getName(), new JScrollPane(graph));
048: setSelectedIndex(getComponentCount() - 1);
049: }
050:
051: public void removeAll() {
052: super .removeAll();
053: graphs.clear();
054: }
055:
056: public WorkflowGraph[] getGraphs() {
057: WorkflowGraph[] g = new WorkflowGraph[graphs.size()];
058: graphs.toArray(g);
059: return g;
060: }
061:
062: public WorkflowGraph getGraph(String workflowName) {
063: for (int i = 0; i < graphs.size(); i++) {
064: WorkflowGraph graph = (WorkflowGraph) graphs.get(i);
065: if (graph.getName().equals(workflowName)) {
066: return graph;
067: }
068: }
069: return null;
070: }
071:
072: public void renameGraph(String name, String newName) {
073: for (int i = 0; i < graphs.size(); i++) {
074: WorkflowGraph graph = (WorkflowGraph) graphs.get(i);
075: if (graph.getName().equals(name)) {
076: graph.setName(newName);
077: setTitleAt(i, newName);
078: return;
079: }
080: }
081: }
082:
083: public void removeGraph(String name) {
084: for (int i = 0; i < graphs.size(); i++) {
085: WorkflowGraph graph = (WorkflowGraph) graphs.get(i);
086: if (graph.getName().equals(name)) {
087: removeTabAt(i);
088: graphs.remove(i);
089: revalidate();
090: return;
091: }
092: }
093: }
094:
095: public void removeGraph(WorkflowGraph graph) {
096: for (int i = 0; i < graphs.size(); i++) {
097: WorkflowGraph g = (WorkflowGraph) graphs.get(i);
098: if (graph == g) {
099: removeTabAt(i);
100: graphs.remove(i);
101: revalidate();
102: return;
103: }
104: }
105: }
106: }
|