001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright © 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.pm.graphic.frames.workspace;
051:
052: import java.awt.Component;
053: import java.awt.Container;
054: import java.awt.Dimension;
055: import java.awt.event.ActionEvent;
056: import java.awt.event.ActionListener;
057: import java.util.AbstractList;
058: import java.util.Iterator;
059: import java.util.LinkedList;
060:
061: import javax.swing.DefaultComboBoxModel;
062: import javax.swing.JComboBox;
063: import javax.swing.JLabel;
064: import javax.swing.JPanel;
065: import javax.swing.RootPaneContainer;
066: import javax.swing.border.LineBorder;
067:
068: import com.projity.pm.graphic.frames.DocumentFrame;
069: import com.projity.pm.graphic.frames.GraphicManager;
070: import com.projity.pm.task.Project;
071: import com.projity.pm.task.ProjectFactory;
072: import com.projity.session.LoadOptions;
073: import com.projity.strings.Messages;
074: import com.projity.util.Environment;
075: import com.projity.workspace.WorkspaceSetting;
076:
077: public class DefaultFrameManager implements FrameManager {
078: private static final long serialVersionUID = -1835326043838730651L;
079: public static final int SPLIT_EAST_WEST_SOUTH_NORTH = 0;
080: RootPaneContainer root;
081: Container emptyPanel;
082:
083: JComboBox projectComboBox;
084: JPanel projectComboPanel;
085: NamedFrame previous = null;
086: GraphicManager graphicManager;
087: private FrameWorkspace workspace;
088:
089: public DefaultFrameManager(RootPaneContainer root,
090: Container emptyPanel, GraphicManager graphicManager) {
091: this .root = root;
092: this .emptyPanel = emptyPanel;
093: this .graphicManager = graphicManager;
094: projectComboPanel = new JPanel();
095: projectComboPanel.setVisible(false);
096: projectComboPanel.add(new JLabel(Messages
097: .getString("DefaultFrameManager.Project"))); //$NON-NLS-1$ //$NON-NLS-2$
098: GraphicManager.getInstance().getLafManager().setColorScheme(
099: projectComboPanel);
100: }
101:
102: protected void finalize() throws Throwable {
103: super .finalize();
104: }
105:
106: public void cleanUp() {
107: Iterator i = getAllFrames().iterator();
108: while (i.hasNext()) {
109: ((DocumentFrame) i.next()).cleanUp();
110: }
111: projectComboBox.removeAll();
112: root = null;
113: emptyPanel = null;
114: previous = null;
115: workspace = null;
116: NamedFrame previous = null;
117: graphicManager = null;
118: }
119:
120: protected class FrameComboBoxModel extends DefaultComboBoxModel {
121: public FrameComboBoxModel() {
122: super ();
123: }
124:
125: public void update() {
126: fireContentsChanged(this , -1, -1);
127: }
128:
129: public void addElement(Object anObject) {
130: super .addElement(anObject);
131: }
132: }
133:
134: private final JComboBox getProjectComboBox() {
135: if (projectComboBox == null) {
136: projectComboBox = new JComboBox(new FrameComboBoxModel());
137: projectComboBox.setToolTipText(Messages
138: .getString("DefaultFrameManager.Project")); //$NON-NLS-1$
139: projectComboBox.setMinimumSize(new Dimension(300, 28));
140: projectComboBox.setMaximumSize(new Dimension(300, 28));
141: projectComboPanel.setVisible(false);
142: // projectComboBox.setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4,Color.WHITE));
143: // projectComboBox.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
144:
145: projectComboBox.addActionListener(new ActionListener() {
146: public void actionPerformed(ActionEvent e) {
147: NamedFrame frame = (NamedFrame) projectComboBox
148: .getSelectedItem();
149: if (frame == null || frame == previous)
150: return;
151: activateFrame(frame);
152: frame.fireNamedFrameActivated(new NamedFrameEvent(
153: frame));
154: }
155: });
156: projectComboPanel.add(projectComboBox);
157:
158: }
159: return projectComboBox;
160: }
161:
162: public void activateFrame(NamedFrame frame) {
163: getProjectComboBox().setSelectedItem(frame);
164: if (previous != null) {
165: root.getContentPane().remove(previous);
166: previous.setActive(false);
167: previous.setVisible(false);
168: } else {
169: if (root != null && root.getContentPane() != null)
170: root.getContentPane().remove(emptyPanel);
171: }
172: previous = frame;
173: if (frame == null) // happens when closing all
174: return;
175: root.getContentPane().add(frame, "Center");
176: frame.setActive(true);
177: frame.setVisible(true);
178:
179: }
180:
181: public NamedFrame getFrame(String id) {
182: for (int i = 0; i < getProjectComboBox().getItemCount(); i++) {
183: NamedFrame frame = (NamedFrame) getProjectComboBox()
184: .getItemAt(i);
185: if (frame.getId().equals(id))
186: return frame;
187: }
188: return null;
189: }
190:
191: public void addFrame(NamedFrame frame) {
192: getProjectComboBox().addItem(frame);
193: frame.setManager(this );
194: activateFrame(frame);
195: projectComboPanel.setVisible(true);
196:
197: }
198:
199: public AbstractList getAllFrames() {
200: LinkedList list = new LinkedList();
201: for (int i = 0; i < getProjectComboBox().getItemCount(); i++) {
202: NamedFrame frame = (NamedFrame) getProjectComboBox()
203: .getItemAt(i);
204: list.add(frame);
205: }
206: return list;
207: }
208:
209: public Component getSelectedFrame() {
210: return (Component) getProjectComboBox().getSelectedItem();
211: }
212:
213: public void removeFrame(NamedFrame frame) {
214: if (frame == null) // in case of subproject for example, it didn't have its own frame
215: return;
216: getProjectComboBox().removeItem(frame);
217: root.getContentPane().remove(frame);
218: ((DocumentFrame) frame).cleanUp();
219: if (getProjectComboBox().getItemCount() == 0) {
220: previous = null;
221: root.getContentPane().add(emptyPanel, "Center");
222: projectComboPanel.setVisible(false);
223:
224: } else {
225: if (previous != null) {
226: activateFrame(previous); // try to activate last activated
227: } else {
228: activateFrame((NamedFrame) getProjectComboBox()
229: .getItemAt(0)); // activate first one otherwise
230: }
231: }
232:
233: }
234:
235: public void showFrame(NamedFrame frame) {
236: getProjectComboBox().setSelectedItem(frame);
237: }
238:
239: public void update() {
240: FrameComboBoxModel model = (FrameComboBoxModel) getProjectComboBox()
241: .getModel();
242: model.update();
243: }
244:
245: public void setTabTitle(NamedFrame frame, String tabTitle) {
246: // TODO Auto-generated method stub
247:
248: }
249:
250: public com.projity.pm.graphic.frames.workspace.Workspace getWorkspace() {
251: return new com.projity.pm.graphic.frames.workspace.Workspace();
252: }
253:
254: final Container getEmptyPanel() {
255: return emptyPanel;
256: }
257:
258: final RootPaneContainer getRoot() {
259: return root;
260: }
261:
262: public void restoreWorkspace(WorkspaceSetting w, int context) {
263: FrameWorkspace ws = (FrameWorkspace) w;
264: workspace = ws;
265: Iterator i = ws.list.iterator();
266: while (i.hasNext()) {
267: DocumentFrame.Workspace documentFrameWorkspace = (DocumentFrame.Workspace) i
268: .next();
269: long projectId = documentFrameWorkspace.getProjectId();
270: Project project = ProjectFactory.getInstance().findFromId(
271: projectId);
272: if (project == null) {
273: LoadOptions opt = new LoadOptions();
274: opt.setId(projectId);
275: opt.setSync(true);
276: ProjectFactory.getInstance().openProject(opt);
277: }
278: DocumentFrame documentFrame = graphicManager
279: .addProjectFrame(project); // will add to combo
280: documentFrame.restoreWorkspace(documentFrameWorkspace,
281: context); // a little ugly, in that the worspace is used above to create the frame
282: }
283: getProjectComboBox().setSelectedIndex(ws.getSelectedIndex());
284: }
285:
286: public WorkspaceSetting createWorkspace(int context) {
287: FrameWorkspace ws = new FrameWorkspace();
288: ws.list = new LinkedList();
289: for (int i = 0; i < getProjectComboBox().getItemCount(); i++) {
290: DocumentFrame frame = (DocumentFrame) getProjectComboBox()
291: .getItemAt(i);
292: ws.list.add(frame.createWorkspace(context));
293: }
294: ws.selectedIndex = getProjectComboBox().getSelectedIndex();
295: return ws;
296: }
297:
298: public static class FrameWorkspace implements WorkspaceSetting { // named FrameWorkspace to avoid conflict
299: private static final long serialVersionUID = -4029197146082617077L;
300: LinkedList list;
301: int selectedIndex;
302:
303: public final LinkedList getList() {
304: return list;
305: }
306:
307: public final void setList(LinkedList list) {
308: this .list = list;
309: }
310:
311: public final int getSelectedIndex() {
312: return selectedIndex;
313: }
314:
315: public final void setSelectedIndex(int selectedIndex) {
316: this .selectedIndex = selectedIndex;
317: }
318: }
319:
320: final GraphicManager getGraphicManager() {
321: return graphicManager;
322: }
323:
324: public JPanel getProjectComboPanel() {
325: return projectComboPanel;
326: }
327:
328: }
|