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.Component;
053: import java.awt.event.ActionEvent;
054: import java.awt.event.ActionListener;
055: import java.lang.reflect.InvocationTargetException;
056:
057: import javax.swing.DefaultCellEditor;
058: import javax.swing.DefaultComboBoxModel;
059: import javax.swing.JCheckBox;
060: import javax.swing.JComboBox;
061: import javax.swing.JComponent;
062: import javax.swing.JLabel;
063: import javax.swing.JScrollPane;
064: import javax.swing.JTable;
065: import javax.swing.UIManager;
066: import javax.swing.plaf.UIResource;
067: import javax.swing.table.AbstractTableModel;
068: import javax.swing.table.DefaultTableCellRenderer;
069: import javax.swing.table.DefaultTableColumnModel;
070: import javax.swing.table.JTableHeader;
071: import javax.swing.table.TableColumn;
072:
073: import org.apache.commons.beanutils.BeanUtils;
074:
075: import com.jgoodies.forms.builder.DefaultFormBuilder;
076: import com.jgoodies.forms.layout.CellConstraints;
077: import com.jgoodies.forms.layout.FormLayout;
078: import com.projity.configuration.Settings;
079: import com.projity.exchange.ResourceMappingForm;
080: import com.projity.help.HelpUtil;
081: import com.projity.strings.Messages;
082:
083: public final class ResourceMappingDialog extends AbstractDialog {
084: private static final long serialVersionUID = 1L;
085:
086: private ResourceMappingForm form;
087:
088: protected AssociationTable associationTable;
089: protected JComboBox field1, editorCombo;
090: protected JLabel field1Label;
091: protected JCheckBox localProject;
092: protected JCheckBox masterProject = null;
093: protected JComboBox accessControl;
094:
095: public static ResourceMappingDialog getInstance(
096: ResourceMappingForm form) {
097: return new ResourceMappingDialog(form);
098: }
099:
100: private ResourceMappingDialog(ResourceMappingForm form) {
101: super (
102: form.getOwner(),
103: Messages
104: .getString("ResourceMappingDialog.ResourceMerging"), true); //$NON-NLS-1$
105: this .form = form;
106: addDocHelp("Merge_Dialog");
107: }
108:
109: // Component Creation and Initialization **********************************
110:
111: public void setForm(ResourceMappingForm form) {
112: this .form = form;
113: }
114:
115: /**
116: * Creates, intializes and configures the UI components. Real applications
117: * may further bind the components to underlying models.
118: */
119: protected void initControls() {
120: editorCombo = new JComboBox();
121: associationTable = new AssociationTable();
122:
123: // field1=new JComboBox(form.getMergeFields());
124: // field1.setSelectedItem(form.getMergeField());
125: field1 = new JComboBox();
126:
127: field1.addActionListener(new ActionListener() {
128: public void actionPerformed(ActionEvent e) {
129: form
130: .setMergeField((ResourceMappingForm.MergeField) field1
131: .getSelectedItem());
132: ((AssociationTableModel) associationTable.getModel())
133: .update();
134: }
135: });
136: field1Label = new JLabel(
137: Messages
138: .getString("ResourceMappingDialog.MergeResourcesUsingField")); //$NON-NLS-1$
139: localProject = new JCheckBox(
140: Messages
141: .getString("ResourceMappingDialog.DontMergeOpenProjectReadOnly")); //$NON-NLS-1$
142: accessControl = new JComboBox(
143: new Object[] {
144: Messages
145: .getString("ResourceMappingDialog.AllResourcesExceptCustomerPartner"), Messages.getString("ResourceMappingDialog.BasedOnProjectRoleInResourcesView") }); //$NON-NLS-1$ //$NON-NLS-2$
146: HelpUtil.addDocHelp(accessControl, "Project_Team");
147: // localProject.addItemListener(new ItemListener(){
148: // public void itemStateChanged(ItemEvent e) {
149: // accessControl.setEnabled(!accessControl.isEnabled());
150: // }
151: // });
152: //
153: localProject.addActionListener(new ActionListener() {
154: public void actionPerformed(ActionEvent e) {
155: setLocal(localProject.isSelected());
156: if (masterProject != null && localProject.isSelected()) {
157: form.setMaster(false);
158: masterProject.setSelected(false);
159: }
160:
161: }
162: });
163:
164: }
165:
166: private void setLocal(boolean local) {
167: form.setLocal(local);
168: field1Label.setEnabled(!local);
169: field1.setEnabled(!local);
170: associationTable.setEnabled(!local);
171: accessControl.setEnabled(!accessControl.isEnabled());
172: }
173:
174: public boolean bind(boolean get) {
175: if (form == null)
176: return false;
177: if (get) {
178: field1.setModel(new DefaultComboBoxModel(form
179: .getMergeFields()));
180: field1.setSelectedItem(form.getMergeField());
181: editorCombo.setModel(new DefaultComboBoxModel(form
182: .getResources()));
183: editorCombo.setSelectedIndex(0);
184: //associationTable.setModel(new AssociationTableModel());
185: AssociationTableModel tableModel = (AssociationTableModel) associationTable
186: .getModel();
187: tableModel.update();
188: } else {
189: form.setAccessControlType(accessControl.getSelectedIndex());
190: //associationTable.finishCurrentOperations();
191: }
192: return true;
193: }
194:
195: // Building *************************************************************
196:
197: /**
198: * Builds the panel. Initializes and configures components first, then
199: * creates a FormLayout, configures the layout, creates a builder, sets a
200: * border, and finally adds the components.
201: *
202: * @return the built panel
203: */
204:
205: public JComponent createContentPanel() {
206: initControls();
207: //TODO set minimum size
208: FormLayout layout = new FormLayout(
209: "310dlu:grow", // cols //$NON-NLS-1$
210: (masterProject == null) ? "p,3dlu,p,3dlu,p,3dlu,p" : "p,3dlu,p,3dlu,p,3dlu,p,3dlu,p"); // rows //$NON-NLS-1$ //$NON-NLS-2$
211:
212: // Create a builder that assists in adding components to the container.
213: // Wrap the panel with a standardized border.
214: DefaultFormBuilder builder = new DefaultFormBuilder(layout);
215: builder.setDefaultDialogBorder();
216: CellConstraints cc = new CellConstraints();
217: builder.append(createFieldPanel());
218: builder.nextLine(2);
219: builder.add(new JScrollPane(associationTable));
220: if (masterProject != null) {
221: builder.nextLine(2);
222: builder.append(masterProject);
223: }
224: builder.nextLine(2);
225: builder.append(localProject);
226: builder.nextLine(2);
227: builder.append(createFooterPanel());
228: return builder.getPanel();
229: }
230:
231: public JComponent createFieldPanel() {
232: FormLayout layout = new FormLayout("p,3dlu,p",// cols //$NON-NLS-1$
233: "p"); // rows //$NON-NLS-1$
234: DefaultFormBuilder builder = new DefaultFormBuilder(layout);
235: builder.setDefaultDialogBorder();
236: CellConstraints cc = new CellConstraints();
237: builder.append(field1Label);
238: builder.append(field1);
239: return builder.getPanel();
240: }
241:
242: public JComponent createFooterPanel() {
243: FormLayout layout = new FormLayout("p,3dlu,p",// cols //$NON-NLS-1$
244: "p"); // rows //$NON-NLS-1$
245: DefaultFormBuilder builder = new DefaultFormBuilder(layout);
246: builder.setDefaultDialogBorder();
247: CellConstraints cc = new CellConstraints();
248:
249: builder.append(Messages
250: .getString("ResourceMappingDialog.ProjectTeam")); //$NON-NLS-1$
251: builder.add(accessControl, cc.xy(builder.getColumn(), builder
252: .getRow(), "left,default")); //$NON-NLS-1$
253:
254: return builder.getPanel();
255: }
256:
257: /**
258: * @return Returns the form.
259: */
260: public ResourceMappingForm getForm() {
261: return form;
262: }
263:
264: public Object getBean() {
265: return form;
266: }
267:
268: // private void mapResources(String mpxFieldName){
269: // Map fieldMap=new HashMap();
270: // for (Iterator i=form.getImportedResources().iterator();i.hasNext();){
271: //
272: // }
273: // for (Iterator i=form.getImportedResources().iterator();i.hasNext();){
274: //
275: // }
276: //
277: // }
278:
279: private class AssociationTable extends JTable {
280: public AssociationTable() {
281: super (new AssociationTableModel(),
282: new AssociationTableColumnModel());
283: setCellSelectionEnabled(true);
284:
285: getTableHeader().setDefaultRenderer(new HeaderRenderer());
286:
287: registerEditors();
288: createDefaultColumnsFromModel();
289: }
290:
291: protected void registerEditors() {
292: //setDefaultEditor(Date.class,new DateEditor());
293: }
294:
295: public void setEnabled(boolean enabled) {
296: // TODO Auto-generated method stub
297: super .setEnabled(enabled);
298: getTableHeader().setEnabled(enabled);
299:
300: }
301:
302: // public void finishCurrentOperations(){
303: // if (isEditing()){
304: // CellEditor editor=getCellEditor();
305: // if (editor!=null){
306: // editor.stopCellEditing();
307: //
308: // }
309: // }
310: // }
311:
312: }
313:
314: private static class HeaderRenderer extends
315: DefaultTableCellRenderer implements UIResource {
316: public HeaderRenderer() {
317: super ();
318: setHorizontalAlignment(JLabel.CENTER);
319: }
320:
321: public Component getTableCellRendererComponent(JTable table,
322: Object value, boolean isSelected, boolean hasFocus,
323: int row, int column) {
324:
325: setEnabled(table == null || table.isEnabled());
326:
327: if (table != null) {
328: JTableHeader header = table.getTableHeader();
329: if (header != null) {
330: setForeground(header.getForeground());
331: setBackground(header.getBackground());
332: setFont(header.getFont());
333: }
334: }
335:
336: setText((value == null) ? "" : value.toString()); //$NON-NLS-1$
337: setBorder(UIManager.getBorder("TableHeader.cellBorder")); //$NON-NLS-1$
338: return this ;
339: }
340: }
341:
342: private class AssociationTableModel extends AbstractTableModel {
343:
344: public int getColumnCount() {
345: return 2;
346: }
347:
348: public int getRowCount() {
349: return form.getImportedResources().size();
350: }
351:
352: public Object getValueAt(int rowIndex, int columnIndex) {
353: if (columnIndex == 0) {
354: try {
355: return BeanUtils.getProperty(form
356: .getImportedResources().get(rowIndex),
357: "name"); //$NON-NLS-1$
358: } catch (IllegalAccessException e) {
359: // TODO Auto-generated catch block
360: e.printStackTrace();
361: } catch (InvocationTargetException e) {
362: // TODO Auto-generated catch block
363: e.printStackTrace();
364: } catch (NoSuchMethodException e) {
365: // TODO Auto-generated catch block
366: e.printStackTrace();
367: }
368: } else if (columnIndex == 1) {
369: return form.getSelectedResources().get(rowIndex);
370: }
371: return null;
372: }
373:
374: public boolean isCellEditable(int rowIndex, int columnIndex) {
375: return columnIndex == 1;
376: }
377:
378: public void setValueAt(Object value, int rowIndex,
379: int columnIndex) {
380: if (columnIndex == 1) {
381: form.getSelectedResources().set(rowIndex, value);
382: }
383: }
384:
385: public void update() {
386: fireTableDataChanged();
387: }
388:
389: }
390:
391: private class AssociationTableColumnModel extends
392: DefaultTableColumnModel {
393: protected int columnIndex = 0;
394:
395: public AssociationTableColumnModel() {
396: super ();
397: }
398:
399: public void addColumn(TableColumn tc) {
400: if (columnIndex == 0) {
401: tc
402: .setHeaderValue(Messages
403: .getString("ResourceMappingDialog.ImportedResources")); //$NON-NLS-1$
404: tc.setPreferredWidth(150);
405: } else {
406: tc
407: .setHeaderValue(Messages
408: .getString("ResourceMappingDialog.ServerResources")); //$NON-NLS-1$
409: tc.setPreferredWidth(150);
410:
411: // tc.setCellEditor(new ListComboBoxCellEditor(new DefaultComboBoxModel(form.getResources())));
412: tc.setCellEditor(new DefaultCellEditor(editorCombo));
413: }
414: tc.setCellRenderer(new DefaultTableCellRenderer() {
415: public Component getTableCellRendererComponent(
416: JTable table, Object value, boolean selected,
417: boolean focused, int row, int column) {
418: setEnabled(table == null || table.isEnabled());
419: super .getTableCellRendererComponent(table, value,
420: selected, focused, row, column);
421: return this ;
422: }
423: });
424: super .addColumn(tc);
425: columnIndex++;
426: }
427:
428: //no move
429: public void moveColumn(int columnIndex, int newIndex) {
430: }
431:
432: }
433:
434: }
|