001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.project.ui.wizards;
043:
044: import java.awt.BorderLayout;
045:
046: import javax.swing.JPanel;
047:
048: import org.netbeans.modules.uml.project.UMLProject;
049: import org.netbeans.modules.uml.project.ui.common.ReferencedJavaProjectPanel;
050: import org.openide.WizardDescriptor;
051: import org.openide.WizardValidationException;
052:
053: /**
054: *
055: * @author Mike Frisino
056: */
057: public class PanelOptionsVisual extends SettingsPanel {
058: private static boolean lastMainClassCheck = true; // XXX Store somewhere
059: private PanelConfigureProject panelConfigureProject;
060: private boolean valid;
061: private int wizardType = NewUMLProjectWizardIterator.TYPE_UML;
062: private ReferencedJavaProjectPanel javaProjectPanel;
063: // private RoseImportProjectPanel roseImportProjectPanel;
064:
065: public final static String MODE_CHANGED_PROP = "MODE_CHANGED"; // NOI18N
066:
067: public PanelOptionsVisual(PanelConfigureProject panel, int type) {
068: initComponents();
069: this .panelConfigureProject = panel;
070: this .wizardType = type;
071:
072: switch (type) {
073: case NewUMLProjectWizardIterator.TYPE_UML:
074: case NewUMLProjectWizardIterator.TYPE_UML_JAVA:
075: hideJavaProjectPanel();
076: // hideRoseImportProjectPanel();
077: break;
078:
079: case NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER:
080: createJavaProjectPanel();
081: showJavaProjectPanel();
082: // hideRoseImportProjectPanel();
083: break;
084:
085: // case NewUMLProjectWizardIterator.TYPE_ROSE_IMPORT:
086: // createRoseImportProjectPanel();
087: // showRoseImportProjectPanel();
088: // hideJavaProjectPanel();
089: // break;
090: }
091: }
092:
093: private void createJavaProjectPanel() {
094: if (javaProjectPanel == null) {
095: javaProjectPanel = new ReferencedJavaProjectPanel(
096: panelConfigureProject, wizardType);
097: add(javaProjectPanel, BorderLayout.CENTER);
098: }
099: }
100:
101: // private void createRoseImportProjectPanel()
102: // {
103: // if (roseImportProjectPanel == null)
104: // {
105: // // roseImportProjectPanel = new PanelRoseImport(panelConfigureProject, wizardType);
106: // roseImportProjectPanel = new RoseImportProjectPanel();
107: // add(roseImportProjectPanel, BorderLayout.CENTER);
108: // }
109: // }
110:
111: private void showJavaProjectPanel() {
112: javaProjectPanel.setVisible(true);
113:
114: javaProjectPanel.addPropertyChangeListener(
115: ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP,
116: panelConfigureProject);
117:
118: javaProjectPanel.addPropertyChangeListener(
119: ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP,
120: panelConfigureProject);
121: }
122:
123: // private void showRoseImportProjectPanel()
124: // {
125: // roseImportProjectPanel.setVisible(true);
126: //
127: // roseImportProjectPanel.addPropertyChangeListener(
128: // RoseImportProjectPanel.ROSE_MODEL_PROP,
129: // panelConfigureProject);
130: // }
131:
132: private void hideJavaProjectPanel() {
133: // if never instatiated, then it doesn't need to be hidden
134: // this is just defensive code and shouldn't happen
135: if (javaProjectPanel == null)
136: return;
137:
138: javaProjectPanel.setVisible(false);
139:
140: javaProjectPanel.removePropertyChangeListener(
141: ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP,
142: panelConfigureProject);
143:
144: javaProjectPanel.removePropertyChangeListener(
145: ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP,
146: panelConfigureProject);
147: }
148:
149: // private void hideRoseImportProjectPanel()
150: // {
151: // // if never instatiated, then it doesn't need to be hidden
152: // // this is just defensive code and shouldn't happen
153: // if (roseImportProjectPanel == null)
154: // return;
155: //
156: // roseImportProjectPanel.setVisible(false);
157: //
158: // roseImportProjectPanel.removePropertyChangeListener(
159: // RoseImportProjectPanel.ROSE_MODEL_PROP,
160: // panelConfigureProject);
161: // }
162:
163: boolean valid(WizardDescriptor settings) {
164: /* MCF - TODO - this is sample of bulletproofing code from the
165: * j2se project or wherever i copied it from. We may need to do similar
166: * here
167: *
168: if (mainClassTextField.isVisible () && mainClassTextField.isEnabled ())
169: {
170: if (!valid)
171: {
172: settings.putProperty(
173: NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, // NOI18N
174: NbBundle.getMessage(PanelOptionsVisual.class,
175: "ERROR_IllegalMainClassName")); //NOI18N
176: }
177:
178: return this.valid;
179: }
180:
181: else
182: return true;
183: */
184:
185: if (javaProjectPanel != null)
186: return javaProjectPanel.valid(settings);
187:
188: // else if (roseImportProjectPanel != null)
189: // return roseImportProjectPanel.valid(settings);
190:
191: else
192: return true;
193: }
194:
195: void read(WizardDescriptor wizDesc) {
196: // TODO: do we need to do anything?
197: }
198:
199: void validate(WizardDescriptor wizDesc)
200: throws WizardValidationException {
201: // nothing to validate
202: if (wizardType == NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER) {
203: // TODO - make sure they have selected a target
204: // otherwise there is nothing to rev engineer
205: if (javaProjectPanel.getSelectedProject() == null) {
206: // TODO set message and throw except
207: }
208: }
209: }
210:
211: void store(WizardDescriptor wizDesc) {
212: wizDesc.putProperty(
213: NewUMLProjectWizardIterator.PROP_SET_AS_MAIN,
214: Boolean.FALSE);
215:
216: if (wizardType == NewUMLProjectWizardIterator.TYPE_UML) {
217: wizDesc.putProperty(
218: NewUMLProjectWizardIterator.PROP_MODELING_MODE,
219: UMLProject.PROJECT_MODE_ANALYSIS_STR);
220: }
221:
222: else if (wizardType == NewUMLProjectWizardIterator.TYPE_UML_JAVA) {
223: wizDesc.putProperty(
224: NewUMLProjectWizardIterator.PROP_MODELING_MODE,
225: UMLProject.PROJECT_MODE_DESIGN_STR);
226: }
227:
228: if (wizardType == NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER) {
229: wizDesc.putProperty(
230: NewUMLProjectWizardIterator.PROP_MODELING_MODE,
231: UMLProject.PROJECT_MODE_IMPL_STR);
232:
233: wizDesc
234: .putProperty(
235: NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_PROJECT,
236: javaProjectPanel.getSelectedProject());
237:
238: wizDesc
239: .putProperty(
240: NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_ROOTS_MODEL,
241: javaProjectPanel.getJavaSourceRootsModel());
242: }
243:
244: // if (wizardType == NewUMLProjectWizardIterator.TYPE_ROSE_IMPORT)
245: // {
246: // wizDesc.putProperty(
247: // NewUMLProjectWizardIterator.PROP_ROSE_FILE,
248: // roseImportProjectPanel.getRoseFile());
249: //
250: // wizDesc.putProperty(
251: // NewUMLProjectWizardIterator.PROP_MODELING_MODE,
252: // roseImportProjectPanel.getModelingMode());
253: // }
254: }
255:
256: /** This method is called from within the constructor to
257: * initialize the form.
258: * WARNING: Do NOT modify this code. The content of this method is
259: * always regenerated by the Form Editor.
260: */
261: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
262: private void initComponents() {
263:
264: setLayout(new BorderLayout());
265:
266: getAccessibleContext().setAccessibleName("");
267: getAccessibleContext().setAccessibleDescription("");
268: }// </editor-fold>//GEN-END:initComponents
269:
270: // public void propertyChange(PropertyChangeEvent evt)
271: // {
272: // if (evt.getPropertyName().equals(
273: // NewUMLProjectWizardIterator.PROP_WIZARD_TYPE))
274: // {
275: // if (((Integer)evt.getNewValue()).intValue() ==
276: // NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER)
277: // {
278: // showJavaProjectPanel();
279: // }
280: //
281: // else
282: // hideJavaProjectPanel();
283: // }
284: // }
285:
286: // This panelConfigureProject is added at the bottom of the container to
287: // just pushes the other items up so the layout is as intended.
288: // MCF - this was needed when we were using the grid bag layout
289: // but is not needed if we stick with border
290: // private void addBottomPanel() {
291: //
292: // jPanel1 = new javax.swing.JPanel();
293: // //jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 255, 0)));
294: // java.awt.GridBagConstraints gridBagConstraints;
295: // gridBagConstraints = new java.awt.GridBagConstraints();
296: // gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
297: // gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
298: // gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
299: // gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
300: // gridBagConstraints.weightx = 1.0;
301: // gridBagConstraints.weighty = 1.0;
302: // add(jPanel1, gridBagConstraints);
303: // jPanel1.getAccessibleContext().setAccessibleName(
304: // java.util.ResourceBundle.getBundle(
305: // "org/netbeans/modules/uml/project/ui/wizards/Bundle").getString("ACSN_jPanel1"));
306: // jPanel1.getAccessibleContext().setAccessibleDescription(
307: // java.util.ResourceBundle.getBundle(
308: // "org/netbeans/modules/uml/project/ui/wizards/Bundle").getString("ASCD_jPanel1"));
309: // }
310:
311: // Variables declaration - do not modify//GEN-BEGIN:variables
312: // End of variables declaration//GEN-END:variables
313:
314: }
|