View Javadoc

1   /*
2    * Copyright (c) 2005, The K-Wf Grid Consortium
3    * Fraunhofer Institute for Computer Architecture and Software Technology
4    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
5    */
6   package net.kwfgrid.gwui.gui;
7   
8   import net.kwfgrid.gworkflowdl.protocol.structure.ProtocolWorkflow;
9   import net.kwfgrid.gworkflowdl.protocol.structure.IStructureObject;
10  import net.kwfgrid.gworkflowdl.protocol.structure.IStructureListener;
11  
12  import org.glassbox.gui.Visible;
13  
14  import java.util.List;
15  import javax.swing.border.*;
16  import java.awt.Color;
17  
18  /***
19     Abstract super class for a view of a workflow element.
20   */
21  public abstract class AbstractWorkflowElementView implements Visible, IStructureListener {
22      private boolean _enabled;
23      private ProtocolWorkflow _workflow;
24      private IStructureObject _element;
25  
26      protected static final Border createBorder(String title) {
27  	return new TitledBorder(title);
28      }
29  
30      /***
31         Constructor.
32         Adds this view as a <code>IStructureListener</code> to the specified workflow.
33         @param target The document containing the displayed element.
34         @param element The displayed element.
35       */
36      protected AbstractWorkflowElementView(ProtocolWorkflow target, IStructureObject element) {
37  	_workflow = target;
38  	_element = element;
39  	_enabled = true;
40  	_workflow.addStructureListener(this);
41      }
42  
43      /***
44         Get the element displayed by this view.
45       */
46      protected IStructureObject getElement() {
47  	return _element;
48      }
49  
50      /***
51         Get the <code>Workflow</code> which contains the element displayed by this view.
52       */
53      protected ProtocolWorkflow getWorkflow() {
54  	return _workflow;
55      }
56  
57      /***
58         Update the state of this view.
59       */
60      protected abstract void updateState();
61  
62      /***
63         Updates this view.
64      */
65      protected abstract void updateView();
66  
67      /***
68         Dispose this editor.
69         Removes this view from the list of <code>IStructureListeners</code> from the workflow.
70       */
71      public void dispose() {
72  	_workflow.removeStructureListener(this);
73      }
74  
75      /***
76         Set if this view is enabled.
77         Calls <code>updateState()</code> after changing the enabled state.
78       */
79      public void setEnabled(boolean enabled) {
80  	_enabled = enabled;
81  	updateState();
82      }
83  
84      public boolean isEnabled() {
85  	return _enabled;
86      }
87      
88      public void objectsAdded(IStructureObject parent, String namespace, String name, List objects) {
89      }
90      
91      public void objectsRemoved(IStructureObject parent, String namespace, String name, List objects) {
92  	// FIXME: if (objects.contains(getElement())) invalidate();
93      }
94      
95      public void propertyChanged(IStructureObject parent, String namespace, String name, Object newvalue) {
96      }    
97  }