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.taskframework;
7   
8   import net.kwfgrid.gworkflowdl.protocol.structure.*;
9   import net.kwfgrid.gwui.*;
10  
11  import java.awt.event.*;
12  import javax.swing.*;
13  import java.awt.*;
14  import java.util.HashMap;
15  import java.util.LinkedList;
16  import java.util.Collection;
17  import java.util.Iterator;
18  import java.util.List;
19  
20  import org.glassbox.Theme;
21  import org.glassbox.gui.*;
22  
23  import org.apache.log4j.Logger;
24  
25  public class UserTaskList extends UserTaskHandler implements VisibleMember {
26      private static final Logger logger = Logger.getLogger(UserTaskList.class);
27  
28      public static final String IDENTIFIER = "kwfgrid.UserTaskList";
29  
30      private static final String SIZE_KEY = "kwfgrid.UserTaskList.size";
31      private static final Dimension SIZE = Theme.getSize(SIZE_KEY);
32      private static final String TASK_DONE_ICON_KEY = "kwfgrid.UserTaskList.task-done.icon";
33      private static final Icon TASK_DONE_ICON = Theme.getIcon(TASK_DONE_ICON_KEY);
34  
35      private JScrollPane _view;
36      private JPanel _panel;
37      private JLabel _idleview;
38      private HashMap _taskbuttonsbytask;
39  
40      public UserTaskList() {
41  	super();
42  	_taskbuttonsbytask = new HashMap();
43  	_view = null;
44  	_idleview = null;
45  	_panel = null;
46      }
47  
48      ///
49      /// Public API
50      /// ....................................................................................................
51  
52      public void setActiveDocument(ProtocolWorkflow doc) {	
53  	super.setActiveDocument(doc);
54  	updateView();
55      }
56  
57      ///
58      /// Protected API
59      /// ....................................................................................................
60  
61      protected void addTask(final UserTask task) {
62  	super.addTask(task);
63  	JButton button = org.glassbox.SwingFactory.createLinkButton(task.getIcon(), task.getTitle());
64  	button.setToolTipText(task.getToolTipText());
65  	button.addActionListener(new ActionListener() {
66  		public void actionPerformed(ActionEvent e) {
67  		    task.execute();
68  		}
69  	    });
70  	_taskbuttonsbytask.put(task, button);
71  	_panel.add(button);
72      }
73  
74      protected void taskInvalid(UserTask task, Iterator tasks) {
75   	super.taskInvalid(task, tasks);
76  	LinkButton button = (LinkButton)_taskbuttonsbytask.remove(task);
77  	_panel.remove(button);
78      }
79  
80      protected void taskDone(UserTask task, Iterator tasks) {
81   	super.taskDone(task, tasks);
82  	LinkButton button = (LinkButton)_taskbuttonsbytask.get(task);
83  	button.setIcon(TASK_DONE_ICON);
84  	button.setDisabledIcon(TASK_DONE_ICON);
85  	button.setEnabled(false);
86      }
87  
88      ///
89      /// Private API
90      /// ....................................................................................................
91  
92      private void updateView() {
93  	if (_taskbuttonsbytask.isEmpty()) {
94  	    _view.setViewportView(_idleview);
95  	} else {
96  	    _view.setViewportView(_panel);
97  	}
98  	_view.revalidate();
99  	_view.repaint();	
100 	if (getGroup() != null) {
101 	    ((VisibleGroup)getGroup()).memberViewUpdated(this);
102 	}
103     }
104 
105     ///
106     /// Implementation of IStructureListner
107     /// ----------------------------------------------------------------------------------------------------
108 
109     public void objectsAdded(IStructureObject parent, String namespace, String name, List objects) {
110 	super.objectsAdded(parent, namespace, name, objects);
111 	updateView();
112     }
113 
114     public void objectsRemoved(IStructureObject parent, String namespace, String name, List objects) {
115 	super.objectsRemoved(parent, namespace, name, objects);
116 	updateView();
117     }
118 
119     public void propertyChanged(IStructureObject parent, String namespace, String name, Object newvalue) {
120 	super.propertyChanged(parent, namespace, name, newvalue);
121 	updateView();
122     }
123 
124     ///
125     /// Implementation of Member
126     /// ....................................................................................................
127 
128     public String getIdentifier() {
129 	return IDENTIFIER;
130     }
131 
132     public JComponent getView() {
133 	if (_view == null) {
134 	    _panel= new JPanel();
135 	    _panel.setLayout(new BoxLayout(_panel, BoxLayout.Y_AXIS));
136 	    _view = new JScrollPane(_panel);
137 	    _idleview = new JLabel("No pending tasks.");
138 
139 	    updateView();
140 	}
141 	return _view;
142     }
143 }
144