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.dialog;
051:
052: import java.awt.Frame;
053: import java.awt.event.ActionEvent;
054: import java.text.ParseException;
055:
056: import javax.swing.AbstractAction;
057: import javax.swing.JButton;
058: import javax.swing.JComboBox;
059: import javax.swing.JComponent;
060: import javax.swing.JLabel;
061: import javax.swing.JOptionPane;
062: import javax.swing.JTextField;
063:
064: import com.jgoodies.forms.builder.DefaultFormBuilder;
065: import com.jgoodies.forms.layout.CellConstraints;
066: import com.jgoodies.forms.layout.FormLayout;
067: import com.projity.association.InvalidAssociationException;
068: import com.projity.configuration.Configuration;
069: import com.projity.datatype.Duration;
070: import com.projity.datatype.DurationFormat;
071: import com.projity.field.Field;
072: import com.projity.pm.dependency.Dependency;
073: import com.projity.pm.dependency.DependencyService;
074: import com.projity.pm.dependency.DependencyType;
075: import com.projity.strings.Messages;
076: import com.projity.util.Alert;
077:
078: /**
079: *
080: */
081: public class DependencyDialog extends AbstractDialog {
082: private static final long serialVersionUID = 1L;
083: protected JLabel preLabel, sucLabel;
084: protected JComboBox typeCombo;
085: protected JTextField lagTextField;
086: protected JButton removeButton;
087: Field dependencyTypeField = Configuration
088: .getFieldFromId("Field.dependencyType");
089: boolean remove = false;
090: Dependency dependency;
091:
092: public static boolean doDialog(DependencyDialog dialog,
093: Dependency dependency) {
094: dialog.setDependency(dependency);
095: boolean result;
096: if (result = dialog.doModal()) {
097: if (dialog.remove) {
098: DependencyService.getInstance().remove(dependency,
099: dialog, true);
100: } else {
101: DependencyService.getInstance().update(dependency,
102: dialog);
103: }
104: }
105: dialog.dependency = null;
106: return result;
107: }
108:
109: public DependencyDialog(Frame frame, Dependency dependency) {
110: super (frame, Messages.getString("Text.TaskDependency"), true);
111: initControls();
112: setDependency(dependency);
113: addDocHelp("Task_Dependency_Dialog");
114: }
115:
116: public void setDependency(Dependency dependency) {
117: remove = false;
118: this .dependency = dependency;
119: if (dependency.isExternal()) {
120: if (dependency.isDisabled())
121: setTitle(Messages
122: .getString("Text.DisabledExternalTaskDependency"));
123: else
124: setTitle(Messages
125: .getString("Text.ExternalTaskDependency"));
126: } else {
127: setTitle(Messages.getString("Text.TaskDependency"));
128: }
129: bind(true);
130:
131: }
132:
133: protected void initComponents() {
134: if (contentPanel != null) // if already shown once
135: return;
136: super .initComponents();
137: }
138:
139: protected void initControls() {
140: preLabel = new JLabel();
141: sucLabel = new JLabel();
142: Object[] options = dependencyTypeField.getOptions(null);
143: typeCombo = new JComboBox(options);
144: lagTextField = new JTextField();
145: bind(true);
146: }
147:
148: public ButtonPanel createButtonPanel() {
149: AbstractAction action = new AbstractAction(Messages
150: .getString("Text.Remove")) {
151: public void actionPerformed(ActionEvent e) {
152: delete();
153: }
154: };
155: removeButton = new JButton(action);
156:
157: createOkCancelButtons();
158: ButtonPanel buttonPanel = new ButtonPanel();
159: buttonPanel.addButton(removeButton);
160: buttonPanel.addButton(ok);
161: buttonPanel.addButton(cancel);
162: return buttonPanel;
163: }
164:
165: public JComponent createContentPanel() {
166: // Separating the component initialization and configuration
167: // from the layout code makes both parts easier to read.
168: initControls();
169: //TODO set minimum size
170: FormLayout layout = new FormLayout(
171: "50dlu,3dlu,50dlu,3dlu,50dlu,3dlu,50dlu", // cols
172: "p,3dlu,p,3dlu,p,3dlu,p,3dlu"); // rows
173:
174: // Create a builder that assists in adding components to the container.
175: // Wrap the panel with a standardized border.
176: DefaultFormBuilder builder = new DefaultFormBuilder(layout);
177: builder.setDefaultDialogBorder();
178: CellConstraints cc = new CellConstraints();
179: builder.append(Messages.getString("Text.From") + ":");
180: builder.add(preLabel, cc.xyw(builder.getColumn(), builder
181: .getRow(), 5));
182: builder.nextLine(2);
183: builder.append(Messages.getString("Text.To") + ":");
184: builder.add(sucLabel, cc.xyw(builder.getColumn(), builder
185: .getRow(), 5));
186:
187: builder.nextLine(2);
188: builder
189: .append(Messages.getString("Text.Type") + ":",
190: typeCombo);
191:
192: builder.addLabel(Messages.getString("Text.Lag") + ":");
193: builder.nextColumn(2);
194: builder.add(lagTextField);
195:
196: return builder.getPanel();
197: }
198:
199: // void ok() {
200: // Integer type = DependencyType.mapStringToValue((String) typeCombo
201: // .getSelectedItem());
202: // model.modifyEdge(edge, type.intValue(), -1);
203: // edge = null;
204: // setDialogResult(RESULT_AFFIRMED);
205: // setVisible(false);
206: // }
207: //
208:
209: void delete() {
210: remove = true;
211: setDialogResult(JOptionPane.OK_OPTION);
212: setVisible(false);
213: }
214:
215: protected boolean bind(boolean get) {
216: if (dependency == null)
217: return false;
218: if (get) {
219: preLabel.setText(dependency.getQualifiedPredecessorName());
220: sucLabel.setText(dependency.getQualifiedSuccessorName());
221: String stype = DependencyType.mapValueToString(new Integer(
222: dependency.getDependencyType()));
223: typeCombo.setSelectedItem(stype);
224: lagTextField.setText(DurationFormat.format(dependency
225: .getLag()));
226: } else {
227: try {
228: Duration duration = (Duration) DurationFormat
229: .getInstance().parseObject(
230: lagTextField.getText());
231: int type = ((Number) DependencyType
232: .mapStringToValue(typeCombo.getSelectedItem()
233: .toString())).intValue();
234:
235: // dependency.setLag(duration.getEncodedMillis());
236: // dependency.setDependencyType(type);
237: DependencyService.getInstance().setFields(dependency,
238: duration.getEncodedMillis(), type, this );
239: } catch (ParseException e) {
240: Alert.warn(Messages
241: .getString("Message.invalidDuration"), this );
242: return false;
243: } catch (InvalidAssociationException e) {
244: Alert.warn(e.getMessage(), this );
245: return false;
246: }
247: }
248: return true;
249: }
250:
251: // public void init(GanttModel model, GanttEdge edge) {
252: // this.edge = edge;
253: // this.model = model;
254: // Dependency dep = edge.getDependency();
255: // Task preTask = (Task) dep.getPredecessor();
256: // preLabel.setText(preTask.getName());
257: // Task sucTask = (Task) dep.getSuccessor();
258: // sucLabel.setText(sucTask.getName());
259: // int type = dep.getDependencyType();
260: // String stype = DependencyType.mapValueToString(new Integer(type));
261: // typeCombo.setSelectedItem(stype);
262: // }
263:
264: /**
265: * @return Returns the remove.
266: */
267: public boolean isRemove() {
268: return remove;
269: }
270: }
|