This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 187303
Collapse All | Expand All

(-)a/uml.project/src/org/netbeans/modules/uml/project/AssociatedSourceProvider.java (-156 / +109 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
package org.netbeans.modules.uml.project;
44
45
45
package org.netbeans.modules.uml.project;
46
import org.netbeans.modules.uml.project.ui.common.JavaSourceRootsUI;
46
import org.netbeans.modules.uml.project.ui.common.JavaSourceRootsUI;
47
import org.netbeans.modules.uml.project.ui.common.ReferencedJavaProjectModel;
47
import org.netbeans.modules.uml.project.ui.common.ReferencedJavaProjectModel;
48
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
48
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
Lines 62-154 Link Here
62
import org.openide.filesystems.FileUtil;
62
import org.openide.filesystems.FileUtil;
63
import org.openide.filesystems.FileObject;
63
import org.openide.filesystems.FileObject;
64
64
65
public class AssociatedSourceProvider
66
        implements IAssociatedProjectSourceRoots {
65
67
66
public class AssociatedSourceProvider
67
    implements IAssociatedProjectSourceRoots
68
{
69
    
70
    
71
    // we may only need the UMLProject.
68
    // we may only need the UMLProject.
72
    // actually what we need are UMLProjectProperties but I cannot cache
69
    // actually what we need are UMLProjectProperties but I cannot cache
73
    // reference to that.
70
    // reference to that.
74
    private UMLProject umlProj;
71
    private UMLProject umlProj;
75
    private UMLProjectHelper mHelper;
72
    private UMLProjectHelper mHelper;
76
    private PropertyEvaluator mEval;
73
    private PropertyEvaluator mEval;
77
    
74
78
    public AssociatedSourceProvider(
75
    public AssociatedSourceProvider(
79
        UMLProject proj, UMLProjectHelper helper, PropertyEvaluator eval)
76
            UMLProject proj, UMLProjectHelper helper, PropertyEvaluator eval) {
80
    {
81
        this.umlProj = proj;
77
        this.umlProj = proj;
82
        this.mHelper = helper;
78
        this.mHelper = helper;
83
        this.mEval = eval;
79
        this.mEval = eval;
84
    }
80
    }
85
    
81
86
    public boolean hasAssociatedSourceProject()
82
    public boolean hasAssociatedSourceProject() {
87
    {
88
        UMLProjectProperties props = umlProj.getUMLProjectProperties();
83
        UMLProjectProperties props = umlProj.getUMLProjectProperties();
89
        return props.referencedJavaProjectModel.getRefStatus() ==
84
        return props.referencedJavaProjectModel.getRefStatus()
90
            ReferencedJavaProjectModel.ReferenceStatus.REF_STATUS_UNSET;
85
                == ReferencedJavaProjectModel.ReferenceStatus.REF_STATUS_UNSET;
91
    }
86
    }
92
    
87
93
    public Project getAssociatedSourceProject()
88
    public Project getAssociatedSourceProject() {
94
    {
89
95
        
90
        if (hasAssociatedSourceProject()) {
96
        if (hasAssociatedSourceProject())
91
97
        {
98
            
99
            // TODO - is this the right thing to do? Or should we
92
            // TODO - is this the right thing to do? Or should we
100
            // throw exception?
93
            // throw exception?
101
            return null; //NOI18N
94
            return null; //NOI18N
102
        }
95
        }
103
        
96
104
        UMLProjectProperties props = umlProj.getUMLProjectProperties();
97
        UMLProjectProperties props = umlProj.getUMLProjectProperties();
105
        Project proj = props.referencedJavaProjectModel.getProject();
98
        Project proj = props.referencedJavaProjectModel.getProject();
106
        
99
107
        if(proj == null)
100
        if (proj == null) {
108
        {
101
109
            
110
            // This mean project ref is probably broken ...
102
            // This mean project ref is probably broken ...
111
            // TODO - is this the right thing to do? Or should we
103
            // TODO - is this the right thing to do? Or should we
112
            // throw exception?
104
            // throw exception?
113
            return proj; //NOI18N
105
            return proj; //NOI18N
106
        } else {
107
            return proj;
114
        }
108
        }
115
        
116
        else
117
            return proj;
118
    }
109
    }
119
    
110
120
    public Project getCodeGenTargetProject()
111
    public Project getCodeGenTargetProject() {
121
    {        
122
        UMLProjectProperties props = umlProj.getUMLProjectProperties();
112
        UMLProjectProperties props = umlProj.getUMLProjectProperties();
123
        String path = props.getCodeGenFolderLocation();
113
        String path = props.getCodeGenFolderLocation();
124
        
114
125
        if (path == null) 
115
        if (path == null) {
126
        {
127
            return null;
116
            return null;
128
        }
117
        }
129
        FileObject fo;
118
        FileObject fo;
130
        try
119
        try {
131
        {
132
            fo = FileUtil.toFileObject(new File(new File(path).getCanonicalPath()));
120
            fo = FileUtil.toFileObject(new File(new File(path).getCanonicalPath()));
133
        }       
121
        } catch (IOException ex) {
134
        catch (IOException ex)
135
        {
136
            return null;
122
            return null;
137
        }
123
        }
138
        if (fo != null) 
124
        if (fo != null) {
139
        {
140
            return FileOwnerQuery.getOwner(fo);
125
            return FileOwnerQuery.getOwner(fo);
141
        }
126
        }
142
        return null;
127
        return null;
143
    }
128
    }
144
    
129
145
    public File[] getCompileDependencies()
130
    public File[] getCompileDependencies() {
146
    {
147
        File[] retVal = null;
131
        File[] retVal = null;
148
        
132
149
        Project assocProject = getAssociatedSourceProject();
133
        Project assocProject = getAssociatedSourceProject();
150
        if(assocProject != null)
134
        if (assocProject != null) {
151
        {
152
            // In the future we need to find all projects that the associated
135
            // In the future we need to find all projects that the associated
153
            // project depends apon.  Then include those source roots.
136
            // project depends apon.  Then include those source roots.
154
            //
137
            //
Lines 156-360 Link Here
156
            SourceGroup[] groups = getSourceGroups();
139
            SourceGroup[] groups = getSourceGroups();
157
            retVal = new File[groups.length];
140
            retVal = new File[groups.length];
158
            int index = 0;
141
            int index = 0;
159
            for(SourceGroup curObj : groups)
142
            for (SourceGroup curObj : groups) {
160
            {
161
                FileObject fo = curObj.getRootFolder();
143
                FileObject fo = curObj.getRootFolder();
162
                retVal[index] = FileUtil.toFile(fo);
144
                retVal[index] = FileUtil.toFile(fo);
163
                index++;
145
                index++;
164
            }
146
            }
165
        }
147
        }
166
        
148
167
        return retVal;
149
        return retVal;
168
    }
150
    }
169
    
151
170
    
171
    // TODO - bulletproofing edge cases
152
    // TODO - bulletproofing edge cases
172
    // this should probably throw an exception if the associtated project is
153
    // this should probably throw an exception if the associtated project is
173
    // "off line" or "broken"
154
    // "off line" or "broken"
174
    public SourceGroup[] getSourceGroups()
155
    public SourceGroup[] getSourceGroups() {
175
    {
156
        if (hasAssociatedSourceProject()) {
176
        if (hasAssociatedSourceProject())
177
        {
178
            // TODO - is this the right thing to do? Or should we
157
            // TODO - is this the right thing to do? Or should we
179
            // throw exception?
158
            // throw exception?
180
            return null; //NOI18N
159
            return null; //NOI18N
181
        }
160
        }
182
        
161
183
        UMLProjectProperties props = umlProj.getUMLProjectProperties();
162
        UMLProjectProperties props = umlProj.getUMLProjectProperties();
184
        
163
185
        JavaSourceRootsModel model =
164
        JavaSourceRootsModel model =
186
            (JavaSourceRootsModel)props.referencedJavaSourceRootsModel;
165
                (JavaSourceRootsModel) props.referencedJavaSourceRootsModel;
187
        
166
188
        if (model != null)
167
        if (model != null) {
189
        {
190
            ArrayList result = new ArrayList();
168
            ArrayList result = new ArrayList();
191
            
169
192
            // String[] items = new String[ m.getRowCount()];
170
            // String[] items = new String[ m.getRowCount()];
193
            for (int i = 0; i <  model.getRowCount(); i++)
171
            for (int i = 0; i < model.getRowCount(); i++) {
194
            {
172
                Boolean isChecked = (Boolean) model.getValueAt(i, JavaSourceRootsUI.COL_INCLUDE_FLAG);
195
                Boolean isChecked = (Boolean)model
173
196
                    .getValueAt(i, JavaSourceRootsUI.COL_INCLUDE_FLAG);
174
                if (isChecked != null && isChecked) {
197
                
175
                    SourceGroup sg = (SourceGroup) model.getSourceGroup(i);
198
                if (isChecked != null && isChecked)
199
                {
200
                    SourceGroup sg = (SourceGroup)model.getSourceGroup(i);
201
                    result.add(sg);
176
                    result.add(sg);
202
                }
177
                }
203
            }
178
            }
204
            
179
205
            return (SourceGroup[])
180
            return (SourceGroup[]) result.toArray(new SourceGroup[result.size()]);
206
            result.toArray(new SourceGroup[result.size()]);
181
        } else {
182
            return new SourceGroup[0];
207
        }
183
        }
208
        
209
        else
210
            return new SourceGroup[0];
211
    }
184
    }
212
    
185
213
    public String createAbsolutePath(String filename)
186
    public String createAbsolutePath(String filename) {
214
    {
215
        String retVal = "";
187
        String retVal = "";
216
        
188
217
        if (filename.charAt(0) == '{')
189
        if (filename.charAt(0) == '{') {
218
        {
219
            int index = filename.lastIndexOf('}');
190
            int index = filename.lastIndexOf('}');
220
            
191
221
            if (index > 0)
192
            if (index > 0) {
222
            {
223
                String id = filename.substring(1, index);
193
                String id = filename.substring(1, index);
224
                SourceGroup group = getSourceGroupByID(id);
194
                SourceGroup group = getSourceGroupByID(id);
225
                
195
226
                if (group != null)
196
                if (group != null) {
227
                {
228
                    // retVal = group.getDisplayName() + 
197
                    // retVal = group.getDisplayName() + 
229
                    //    "\\" + filename.substring(index + 1);
198
                    //    "\\" + filename.substring(index + 1);
230
                    retVal = getGroupRootPath(group) + filename.substring(index + 1);
199
                    retVal = getGroupRootPath(group) + filename.substring(index + 1);
231
                    
200
232
                    // NetBeans always has the / slashes instead of using the
201
                    // NetBeans always has the / slashes instead of using the
233
                    // platform specific seperator.
202
                    // platform specific seperator.
234
                    retVal = retVal.replace("\\", "/"); // NOI18N
203
                    retVal = retVal.replace("\\", "/"); // NOI18N
235
                }
204
                }
236
            }
205
            }
237
        }
206
        }
238
        
207
239
        return retVal;
208
        return retVal;
240
    }
209
    }
241
    
210
242
    public String createRelativePath(String filename)
211
    public String createRelativePath(String filename) {
243
    {
244
        String retVal = "";
212
        String retVal = "";
245
        
213
246
        // NetBeans always has the / slashes instead of using the
214
        // NetBeans always has the / slashes instead of using the
247
        // platform specific seperator.
215
        // platform specific seperator.
248
        String converted = filename.replace("\\", "/"); // NOI18N
216
        String converted = filename.replace("\\", "/"); // NOI18N
249
        SourceGroup group = getSourceGroupForFile(converted);
217
        SourceGroup group = getSourceGroupForFile(converted);
250
        
218
251
        if (group != null)
219
        if (group != null) {
252
        {
253
            String groupRoot = getGroupRootPath(group);
220
            String groupRoot = getGroupRootPath(group);
254
            //String displayName = group.getDisplayName();
221
            //String displayName = group.getDisplayName();
255
            String idString = annotateAsIdentifier(group.getName());
222
            String idString = annotateAsIdentifier(group.getName());
256
            
223
257
            
224
258
            groupRoot = groupRoot.replace("\\", "/"); // NOI18N
225
            groupRoot = groupRoot.replace("\\", "/"); // NOI18N
259
            retVal = converted.replace(groupRoot, idString);
226
            retVal = converted.replace(groupRoot, idString);
260
        }
227
        }
261
        
228
262
        return retVal;
229
        return retVal;
263
    }
230
    }
264
    
231
265
    public String getSourceRootId(String filename)
232
    public String getSourceRootId(String filename) {
266
    {
267
        String retVal = ""; // NOI18N
233
        String retVal = ""; // NOI18N
268
        
234
269
        SourceGroup group = getSourceGroupForFile(filename);
235
        SourceGroup group = getSourceGroupForFile(filename);
270
        
236
271
        if (group != null)
237
        if (group != null) {
272
            retVal = group.getName();
238
            retVal = group.getName();
273
        
239
        }
240
274
        return retVal;
241
        return retVal;
275
    }
242
    }
276
    
243
277
    protected String getGroupRootPath(SourceGroup group)
244
    protected String getGroupRootPath(SourceGroup group) {
278
    {
279
        String retVal = ""; // NOI18N
245
        String retVal = ""; // NOI18N
280
        
246
281
        FileObject fObj = group.getRootFolder();
247
        FileObject fObj = group.getRootFolder();
282
        
248
283
        if (fObj != null)
249
        if (fObj != null) {
284
            retVal = FileUtil.toFile(fObj).getAbsolutePath();
250
            retVal = FileUtil.toFile(fObj).getAbsolutePath();
285
        
251
        }
252
286
        return retVal;
253
        return retVal;
287
    }
254
    }
288
    
255
289
    protected SourceGroup getSourceGroupForFile(String filename)
256
    protected SourceGroup getSourceGroupForFile(String filename) {
290
    {
291
        SourceGroup retVal = null;
257
        SourceGroup retVal = null;
292
        
258
293
        if (filename != null && filename.length() > 0)
259
        if (filename != null && filename.length() > 0) {
294
        {
295
            SourceGroup[] groups = getSourceGroups();
260
            SourceGroup[] groups = getSourceGroups();
296
            if (groups != null)
261
            if (groups != null) {
297
            {
262
                for (SourceGroup group : groups) {
298
                for (SourceGroup group : groups)
299
                {
300
263
301
		    if (group == null) 
264
                    if (group == null) {
302
			continue;
265
                        continue;
266
                    }
303
                    // TODO: cvc - group has a potential for being null
267
                    // TODO: cvc - group has a potential for being null
304
                    FileObject fobj = group.getRootFolder();
268
                    FileObject fobj = group.getRootFolder();
305
                    
269
306
//                  if(group.contains(fo) == true)
270
//                  if(group.contains(fo) == true)
307
//                  {
271
//                  {
308
//                     retVal = group;
272
//                     retVal = group;
309
//                     break;
273
//                     break;
310
//                  }
274
//                  }
311
                    
275
312
                    try
276
                    try {
313
                    {
277
                        if (fobj.getFileSystem().findResource(filename) != null) {
314
                        if (fobj.getFileSystem().findResource(filename)!=null)
315
                        {
316
                            retVal = group;
278
                            retVal = group;
317
                            break;
279
                            break;
318
                        }
280
                        }
319
                    }
281
                    } catch (FileStateInvalidException e) {
320
                    
321
                    catch (FileStateInvalidException e)
322
                    {
323
                        Log.stackTrace(e);
282
                        Log.stackTrace(e);
324
                    }
283
                    }
325
                }
284
                }
326
            }
285
            }
327
        }
286
        }
328
        
287
329
        return retVal;
288
        return retVal;
330
    }
289
    }
331
    
290
332
    protected SourceGroup getSourceGroupByID(String id)
291
    protected SourceGroup getSourceGroupByID(String id) {
333
    {
334
        SourceGroup retVal = null;
292
        SourceGroup retVal = null;
335
        
293
336
        if (id != null && id.length() > 0)
294
        if (id != null && id.length() > 0) {
337
        {
338
            SourceGroup[] groups = getSourceGroups();
295
            SourceGroup[] groups = getSourceGroups();
339
            
296
340
            if (groups != null)
297
            if (groups != null) {
341
            {
298
                for (SourceGroup group : groups) {
342
                for (SourceGroup group : groups)
299
                    if ((group != null) && (id.equals(group.getName()) == true)) {
343
                {
344
                    if ((group != null) && (id.equals(group.getName()) == true))
345
                    {
346
                        retVal = group;
300
                        retVal = group;
347
                        break;
301
                        break;
348
                    }
302
                    }
349
                }
303
                }
350
            }
304
            }
351
        }
305
        }
352
        
306
353
        return retVal;
307
        return retVal;
354
    }
308
    }
355
    
309
356
    protected String annotateAsIdentifier(String identifier)
310
    protected String annotateAsIdentifier(String identifier) {
357
    {
358
        StringBuffer buffer = new StringBuffer("{"); // NOI18N
311
        StringBuffer buffer = new StringBuffer("{"); // NOI18N
359
        buffer.append(identifier);
312
        buffer.append(identifier);
360
        buffer.append("}"); // NOI18N
313
        buffer.append("}"); // NOI18N
(-)a/uml.project/src/org/netbeans/modules/uml/project/ProjectCellRenderer.java (-32 / +27 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project;
44
package org.netbeans.modules.uml.project;
46
45
47
import java.awt.Component;
46
import java.awt.Component;
Lines 56-94 Link Here
56
 *
55
 *
57
 * @author Sheryl
56
 * @author Sheryl
58
 */
57
 */
59
public class ProjectCellRenderer extends JLabel implements ListCellRenderer
58
public class ProjectCellRenderer extends JLabel implements ListCellRenderer {
60
{
61
59
62
	public ProjectCellRenderer() {
60
    public ProjectCellRenderer() {
63
		setOpaque(true);
61
        setOpaque(true);
64
	}
62
    }
65
63
66
	public Component getListCellRendererComponent(
64
    public Component getListCellRendererComponent(
67
		JList list,
65
            JList list,
68
		Object value,
66
            Object value,
69
		int index,
67
            int index,
70
		boolean isSelected,
68
            boolean isSelected,
71
		boolean cellHasFocus) {
69
            boolean cellHasFocus) {
72
70
73
		if ( value instanceof Project ) {
71
        if (value instanceof Project) {
74
			ProjectInformation pi = ProjectUtils.getInformation((Project)value);
72
            ProjectInformation pi = ProjectUtils.getInformation((Project) value);
75
			setText(pi.getDisplayName());
73
            setText(pi.getDisplayName());
76
			setIcon(pi.getIcon());
74
            setIcon(pi.getIcon());
77
		}
75
        } else {
78
		else {
76
            setText(value == null ? " " : value.toString()); // NOI18N
79
			setText( value == null ? " " : value.toString () ); // NOI18N
77
            setIcon(null);
80
			setIcon( null );
78
        }
81
		}
79
        if (isSelected) {
82
		if ( isSelected ) {
80
            setBackground(list.getSelectionBackground());
83
			setBackground(list.getSelectionBackground());
81
            setForeground(list.getSelectionForeground());
84
			setForeground(list.getSelectionForeground());             
82
        } else {
85
		}
83
            setBackground(list.getBackground());
86
		else {
84
            setForeground(list.getForeground());
87
			setBackground(list.getBackground());
88
			setForeground(list.getForeground());
89
85
90
		}
86
        }
91
		return this;                    
87
        return this;
92
	}
88
    }
93
	
94
}
89
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ProjectUtil.java (-358 / +267 lines)
Lines 51-57 Link Here
51
 * the Source Creation and Management node. Right-click the template and choose
51
 * the Source Creation and Management node. Right-click the template and choose
52
 * Open. You can then make changes to the template in the Source Editor.
52
 * Open. You can then make changes to the template in the Source Editor.
53
 */
53
 */
54
55
package org.netbeans.modules.uml.project;
54
package org.netbeans.modules.uml.project;
56
55
57
import java.beans.PropertyVetoException;
56
import java.beans.PropertyVetoException;
Lines 108-511 Link Here
108
 *
107
 *
109
 * @author Administrator
108
 * @author Administrator
110
 */
109
 */
111
public class ProjectUtil
110
public class ProjectUtil {
112
{
111
113
    public static final Comparator PROJECT_BY_DISPLAYNAME = new ProjectByDisplayNameComparator();
112
    public static final Comparator PROJECT_BY_DISPLAYNAME = new ProjectByDisplayNameComparator();
114
    
113
115
    public static Project findElementOwner(IElement element)
114
    public static Project findElementOwner(IElement element) {
116
    {
117
        Project retVal = null;
115
        Project retVal = null;
118
        if(element != null)
116
        if (element != null) {
119
        {
120
            //IProject project = element.getProject();
117
            //IProject project = element.getProject();
121
            IElement owningElement = element.getOwner();
118
            IElement owningElement = element.getOwner();
122
            if (owningElement != null)
119
            if (owningElement != null) { //JM: Fix an NPE
123
            { //JM: Fix an NPE
124
                IProject project = owningElement.getProject();
120
                IProject project = owningElement.getProject();
125
                
121
126
                retVal = findNetBeansProjectForModel(project);
122
                retVal = findNetBeansProjectForModel(project);
127
            }
123
            } else {
128
            else
129
            {
130
                retVal = findNetBeansProjectForModel(element.getProject());
124
                retVal = findNetBeansProjectForModel(element.getProject());
131
            }
125
            }
132
        }
126
        }
133
        
127
134
        return retVal;
128
        return retVal;
135
    }
129
    }
136
    
130
137
    public static Project findReferencingProject(IElement element)
131
    public static Project findReferencingProject(IElement element) {
138
    {
139
        Project retVal = null;
132
        Project retVal = null;
140
        if(element != null)
133
        if (element != null) {
141
        {
142
            IProject project = element.getProject();
134
            IProject project = element.getProject();
143
            
135
144
            retVal = findNetBeansProjectForModel(project);
136
            retVal = findNetBeansProjectForModel(project);
145
        }
137
        }
146
        
138
147
        return retVal;
139
        return retVal;
148
    }
140
    }
149
    
141
150
    public static Project findNetBeansProjectForModel(IProject project)
142
    public static Project findNetBeansProjectForModel(IProject project) {
151
    {
152
        Project retVal = null;
143
        Project retVal = null;
153
        
144
154
        if(project != null)
145
        if (project != null) {
155
        {
156
            String filename = project.getFileName();
146
            String filename = project.getFileName();
157
            if((filename != null) && (filename.length() > 0))
147
            if ((filename != null) && (filename.length() > 0)) {
158
            {
159
                FileObject fo = FileUtil.toFileObject(new File(filename));
148
                FileObject fo = FileUtil.toFileObject(new File(filename));
160
                if (fo != null) {
149
                if (fo != null) {
161
                    retVal = FileOwnerQuery.getOwner(fo);
150
                    retVal = FileOwnerQuery.getOwner(fo);
162
                }
151
                }
163
            }
152
            }
164
        }
153
        }
165
        
154
166
        return retVal;
155
        return retVal;
167
    }
156
    }
168
    
157
169
    public static boolean findElementInProjectTree(IElement element)
158
    public static boolean findElementInProjectTree(IElement element) {
170
    {
171
        Node selectedNode = findNodeInProjectTree(element);
159
        Node selectedNode = findNodeInProjectTree(element);
172
        if (selectedNode != null)
160
        if (selectedNode != null) {
173
        {
174
            selectNodeAsync(selectedNode);
161
            selectNodeAsync(selectedNode);
175
            return true; 
162
            return true;
176
        }
163
        }
177
        return false;
164
        return false;
178
    }
165
    }
179
    
166
180
    
167
    public static Node findNodeInProjectTree(IElement element) {
181
    public static Node findNodeInProjectTree(IElement element)
182
    {
183
        Project project = findReferencingProject(element);
168
        Project project = findReferencingProject(element);
184
        
169
185
        return findNodeInProjectTree(project, element);
170
        return findNodeInProjectTree(project, element);
186
    }
171
    }
187
    
172
188
    
173
    public static Node findNodeInProjectTree(Project project, IElement element) {
189
    public static Node findNodeInProjectTree(Project project, IElement element)
174
        TopComponent tc = WindowManager.getDefault().findTopComponent("projectTabLogical_tc");
190
    {
175
        if (tc == null) {
191
        TopComponent tc = WindowManager.getDefault().findTopComponent( "projectTabLogical_tc" );
192
        if (tc==null)
193
            return null;
176
            return null;
194
        
177
        }
178
195
        ExplorerManager explorerManager =
179
        ExplorerManager explorerManager =
196
                ((ExplorerManager.Provider)tc).getExplorerManager();
180
                ((ExplorerManager.Provider) tc).getExplorerManager();
197
        Node root = explorerManager.getRootContext();
181
        Node root = explorerManager.getRootContext();
198
        Children c = root.getChildren();
182
        Children c = root.getChildren();
199
        Node[] projectNodes = c.getNodes(true);
183
        Node[] projectNodes = c.getNodes(true);
200
        for (int i=0; i<projectNodes.length; i++)
184
        for (int i = 0; i < projectNodes.length; i++) {
201
        {
202
            Project p = (Project) projectNodes[i].getLookup().lookup(Project.class);
185
            Project p = (Project) projectNodes[i].getLookup().lookup(Project.class);
203
            if (p==project)
186
            if (p == project) {
204
            {
187
                Node selectedNode = findNodeQuick(projectNodes[i], element);
205
                Node selectedNode = findNodeQuick(projectNodes[i],  element);
188
                if (selectedNode == null) {
206
                if (selectedNode == null)
189
                    selectedNode = findNode(projectNodes[i], element);
207
                {
208
                    selectedNode = findNode(projectNodes[i],  element);
209
                }
190
                }
210
                return selectedNode;
191
                return selectedNode;
211
            }
192
            }
212
        }
193
        }
213
        return null;
194
        return null;
214
    }
195
    }
215
    
196
216
    
197
    public static AntProjectHelper getAntProjectHelper(UMLProject umlProject) {
217
    public static AntProjectHelper getAntProjectHelper(UMLProject umlProject)
198
        return (AntProjectHelper) ((UMLProjectHelper) umlProject.getLookup().lookup(UMLProjectHelper.class)).getAntProjectHelper();
218
    {
219
        return (AntProjectHelper)((UMLProjectHelper)umlProject
220
                .getLookup().lookup(UMLProjectHelper.class)).getAntProjectHelper();
221
    }
199
    }
222
    
200
223
    public static String getTargetJavaProjectName(UMLProject umlProject)
201
    public static String getTargetJavaProjectName(UMLProject umlProject) {
224
    {
225
        AntProjectHelper umlAntProjectHelper = getAntProjectHelper(umlProject);
202
        AntProjectHelper umlAntProjectHelper = getAntProjectHelper(umlProject);
226
        
203
227
        EditableProperties editableProperties =
204
        EditableProperties editableProperties =
228
                umlAntProjectHelper.getProperties(
205
                umlAntProjectHelper.getProperties(
229
                AntProjectHelper.PROJECT_PROPERTIES_PATH);
206
                AntProjectHelper.PROJECT_PROPERTIES_PATH);
230
        
207
231
        return (String)editableProperties
208
        return (String) editableProperties.getProperty(UMLProjectProperties.REFERENCED_JAVA_PROJECT);
232
                .getProperty(UMLProjectProperties.REFERENCED_JAVA_PROJECT);
233
    }
209
    }
234
    
210
235
    
211
    private static String getTargetJavaProjectName(IProject iProject) {
236
    private static String getTargetJavaProjectName(IProject iProject)
212
        return ProjectUtil.getTargetJavaProjectName((UMLProject) ProjectUtil.findNetBeansProjectForModel(iProject));
237
    {
238
        return ProjectUtil.getTargetJavaProjectName((UMLProject)ProjectUtil
239
                .findNetBeansProjectForModel(iProject));
240
    }
213
    }
241
    
214
242
    
215
    public static String getTargetJavaProjectName(IElement element) {
243
    public static String getTargetJavaProjectName(IElement element)
244
    {
245
        UMLProject umlProject =
216
        UMLProject umlProject =
246
                (UMLProject)ProjectUtil.findReferencingProject(element);
217
                (UMLProject) ProjectUtil.findReferencingProject(element);
247
        
218
248
        return ProjectUtil.getTargetJavaProjectName(umlProject);
219
        return ProjectUtil.getTargetJavaProjectName(umlProject);
249
    }
220
    }
250
    
221
251
    public static String getTargetJavaProjectName(Node node)
222
    public static String getTargetJavaProjectName(Node node) {
252
    {
223
        IElement element = (IElement) node.getCookie(IElement.class);
253
        IElement element = (IElement)node.getCookie(IElement.class);
224
        if (element == null) {
254
        if (element == null)
255
            return null;
225
            return null;
256
        
226
        }
227
257
        return ProjectUtil.getTargetJavaProjectName(element);
228
        return ProjectUtil.getTargetJavaProjectName(element);
258
    }
229
    }
259
    
230
260
    
231
    public static boolean hasTargetJavaProject(Node node) {
261
    public static boolean hasTargetJavaProject(Node node)
262
    {
263
        String name = ProjectUtil.getTargetJavaProjectName(node);
232
        String name = ProjectUtil.getTargetJavaProjectName(node);
264
        return  name == null || name.length() == 0 ? false : true;
233
        return name == null || name.length() == 0 ? false : true;
265
    }
234
    }
266
    
235
267
    public static boolean hasTargetJavaProject(IProject umlProject)
236
    public static boolean hasTargetJavaProject(IProject umlProject) {
268
    {
269
        String name = ProjectUtil.getTargetJavaProjectName(umlProject);
237
        String name = ProjectUtil.getTargetJavaProjectName(umlProject);
270
        return  name == null || name.length() == 0 ? false : true;
238
        return name == null || name.length() == 0 ? false : true;
271
    }
239
    }
272
    
240
273
    
241
    public static Node findNode(Node root, IElement element) {
274
    public static Node findNode(Node root, IElement element)
242
275
    {
243
        if (root.isLeaf()) {
276
        
277
        if (root.isLeaf())
278
            return null;
244
            return null;
279
        
245
        }
246
280
        Children children = root.getChildren();
247
        Children children = root.getChildren();
281
        
248
282
        Node[] nodes = children.getNodes(true);
249
        Node[] nodes = children.getNodes(true);
283
        for (int j=0; j<nodes.length; j++)
250
        for (int j = 0; j < nodes.length; j++) {
284
        {
251
            IProjectTreeItem item = (IProjectTreeItem) nodes[j].getCookie(IProjectTreeItem.class);
285
            IProjectTreeItem item = (IProjectTreeItem)nodes[j].
252
            if (item != null) {
286
                    getCookie(IProjectTreeItem.class);
287
            if (item != null)
288
            {
289
                IElement modelElement = item.getModelElement();
253
                IElement modelElement = item.getModelElement();
290
                if (modelElement==null) // could be a diagram node
254
                if (modelElement == null) // could be a diagram node
291
                {
255
                {
292
                    if (element instanceof IDiagram)
256
                    if (element instanceof IDiagram) {
293
                    {
294
                        // the unique diagram file name is used to determine
257
                        // the unique diagram file name is used to determine
295
                        // if two diagram objects are same
258
                        // if two diagram objects are same
296
                        if (item.getDiagram()!=null && item.getDescription().
259
                        if (item.getDiagram() != null && item.getDescription().
297
                                equals(((IDiagram)element).getFilename()))
260
                                equals(((IDiagram) element).getFilename())) {
298
                            return nodes[j];
261
                            return nodes[j];
262
                        }
299
                    }
263
                    }
300
                }
264
                }
301
                if (modelElement!=null &&
265
                if (modelElement != null
302
                        element.getXMIID().equals(modelElement.getXMIID()))
266
                        && element.getXMIID().equals(modelElement.getXMIID())) {
303
                {
267
                    if (nodes[j].getCookie(RelationshipCookie.class) != null) {
304
                    if (nodes[j].getCookie(RelationshipCookie.class) != null)
305
                        continue;
268
                        continue;
269
                    }
306
                    return nodes[j];
270
                    return nodes[j];
307
                }
271
                }
308
            }
272
            }
309
        }
273
        }
310
        for (int j=0; j<nodes.length; j++)
274
        for (int j = 0; j < nodes.length; j++) {
311
        {
275
            if (nodes[j].isLeaf()) {
312
            if (nodes[j].isLeaf())
313
                continue;
276
                continue;
314
            Node val = findNode(nodes[j],  element);
277
            }
315
            if (val!=null)
278
            Node val = findNode(nodes[j], element);
316
            {
279
            if (val != null) {
317
                return val;
280
                return val;
318
            }
281
            }
319
        }
282
        }
320
        return null;
283
        return null;
321
    }
284
    }
322
    
285
323
    
286
    private static Node findNodeQuick(Node root, IElement element) {
324
    private static Node findNodeQuick(Node root, IElement element)
287
        if (root.isLeaf()) {
325
    {
326
        if (root.isLeaf())
327
            return null;
328
        
329
        if (element == null)
330
        {
331
            return null;
288
            return null;
332
        }
289
        }
333
        
290
291
        if (element == null) {
292
            return null;
293
        }
294
334
        IElement owner = element.getOwner();
295
        IElement owner = element.getOwner();
335
        if (owner == null)
296
        if (owner == null) {
336
        {
337
            return findNode(root, element);
297
            return findNode(root, element);
338
        }
298
        } else {
339
        else
340
        {
341
            Node ownerNode = findNodeQuick(root, owner);
299
            Node ownerNode = findNodeQuick(root, owner);
342
            if (ownerNode != null)
300
            if (ownerNode != null) {
343
            {
344
                return findNode(ownerNode, element);
301
                return findNode(ownerNode, element);
345
            }
302
            }
346
        }
303
        }
347
        return null;
304
        return null;
348
    }
305
    }
349
    
306
350
    
307
    public static Project[] getSelectedProjects(Class projectClass) {
351
    public static Project[] getSelectedProjects(Class projectClass)
352
    {
353
        Set result = new HashSet();
308
        Set result = new HashSet();
354
        Lookup lruLookupLocal = Utilities.actionsGlobalContext();
309
        Lookup lruLookupLocal = Utilities.actionsGlobalContext();
355
        // First find out whether there is a project directly in the Lookup
310
        // First find out whether there is a project directly in the Lookup
356
        Collection currentProjects = lruLookupLocal.lookup( new Lookup.Template( projectClass ) ).allInstances();
311
        Collection currentProjects = lruLookupLocal.lookup(new Lookup.Template(projectClass)).allInstances();
357
        
312
358
        for( Iterator it = currentProjects.iterator(); it.hasNext(); )
313
        for (Iterator it = currentProjects.iterator(); it.hasNext();) {
359
        {
314
            Project p = (Project) it.next();
360
            Project p = (Project)it.next();
361
            result.add(p);
315
            result.add(p);
362
        }
316
        }
363
        
317
364
        // Now try to guess the project from dataobjects
318
        // Now try to guess the project from dataobjects
365
        Collection currentDataObjects = lruLookupLocal.lookup( new Lookup.Template( DataObject.class ) ).allInstances();
319
        Collection currentDataObjects = lruLookupLocal.lookup(new Lookup.Template(DataObject.class)).allInstances();
366
        for( Iterator it = currentDataObjects.iterator(); it.hasNext(); )
320
        for (Iterator it = currentDataObjects.iterator(); it.hasNext();) {
367
        {
321
368
            
322
            DataObject dObj = (DataObject) it.next();
369
            DataObject dObj = (DataObject)it.next();
370
            FileObject fObj = dObj.getPrimaryFile();
323
            FileObject fObj = dObj.getPrimaryFile();
371
            if (fObj != null) 
324
            if (fObj != null) {
372
            {
373
                Project p = FileOwnerQuery.getOwner(fObj);
325
                Project p = FileOwnerQuery.getOwner(fObj);
374
                if ( p != null )
326
                if (p != null) {
375
                {
327
                    result.add(p);
376
                    result.add( p );
377
                }
328
                }
378
            }
329
            }
379
        }
330
        }
380
        Project[] projects = new Project[ result.size() ];
331
        Project[] projects = new Project[result.size()];
381
        result.toArray( projects );
332
        result.toArray(projects);
382
        Arrays.sort(projects, PROJECT_BY_DISPLAYNAME);
333
        Arrays.sort(projects, PROJECT_BY_DISPLAYNAME);
383
        return projects;
334
        return projects;
384
    }
335
    }
385
    
336
386
    
337
    public static Project[] getOpenUMLProjects() {
387
    public static Project[] getOpenUMLProjects()
388
    {
389
        Project[] projects = OpenProjects.getDefault().getOpenProjects();
338
        Project[] projects = OpenProjects.getDefault().getOpenProjects();
390
        Set result = new HashSet();
339
        Set result = new HashSet();
391
        for (Project p: projects)
340
        for (Project p : projects) {
392
        {
341
            if (p.getLookup().lookup(UMLProjectHelper.class) != null) {
393
            if (p.getLookup().lookup(UMLProjectHelper.class)!=null)
394
                result.add(p);
342
                result.add(p);
343
            }
395
        }
344
        }
396
        
345
397
        Project[] umlprojects = new Project[ result.size() ];
346
        Project[] umlprojects = new Project[result.size()];
398
        result.toArray( umlprojects );
347
        result.toArray(umlprojects);
399
        Arrays.sort(umlprojects, PROJECT_BY_DISPLAYNAME);
348
        Arrays.sort(umlprojects, PROJECT_BY_DISPLAYNAME);
400
        return umlprojects;
349
        return umlprojects;
401
    }
350
    }
402
    
351
403
    
352
    public static Project[] getOpenJavaProjects() {
404
    public static Project[] getOpenJavaProjects()
405
    {
406
        List result = new ArrayList();
353
        List result = new ArrayList();
407
        Project openProjects[] = OpenProjects.getDefault().getOpenProjects();
354
        Project openProjects[] = OpenProjects.getDefault().getOpenProjects();
408
        for (Project p: openProjects)
355
        for (Project p : openProjects) {
409
        {
356
            Sources srcs = (Sources) p.getLookup().lookup(Sources.class);
410
            Sources srcs = (Sources)p.getLookup().lookup(Sources.class);
357
411
            
358
            if (srcs != null) {
412
            if (srcs != null)
413
            {
414
                // now check for Java sources
359
                // now check for Java sources
415
                SourceGroup[] javaSrcGrps =
360
                SourceGroup[] javaSrcGrps =
416
                        srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
361
                        srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
417
                if (javaSrcGrps.length > 0)
362
                if (javaSrcGrps.length > 0) {
418
                {
363
                    ClassPathProvider cpProvider = (ClassPathProvider) p.getLookup().lookup(ClassPathProvider.class);
419
                    ClassPathProvider cpProvider = (ClassPathProvider)
364
                    if (cpProvider != null) {
420
                            p.getLookup().lookup(ClassPathProvider.class);
421
                    if (cpProvider!=null)
422
                        result.add(p);
365
                        result.add(p);
366
                    }
423
                }
367
                }
424
            }
368
            }
425
        }
369
        }
426
        Project[] projects = (Project[])result.toArray(new Project[result.size()]);
370
        Project[] projects = (Project[]) result.toArray(new Project[result.size()]);
427
        Arrays.sort(projects, PROJECT_BY_DISPLAYNAME);
371
        Arrays.sort(projects, PROJECT_BY_DISPLAYNAME);
428
        return projects;
372
        return projects;
429
    }
373
    }
430
    
431
    public final static String DEFAULT_PACKAGE_DISPLAY_NAME =
374
    public final static String DEFAULT_PACKAGE_DISPLAY_NAME =
432
            "<default package>"; // NOI18N
375
            "<default package>"; // NOI18N
433
    
376
434
    
377
    public static void selectInModel(List<Project> projects, DataObject obj) {
435
    public static void selectInModel(List<Project> projects, DataObject obj)
436
    {
437
        String resourceName = "";
378
        String resourceName = "";
438
        String className = "";
379
        String className = "";
439
        String packageName = DEFAULT_PACKAGE_DISPLAY_NAME;
380
        String packageName = DEFAULT_PACKAGE_DISPLAY_NAME;
440
        boolean isPackage = obj instanceof DataFolder;
381
        boolean isPackage = obj instanceof DataFolder;
441
        
382
442
        if (obj==null)
383
        if (obj == null) {
443
            return;
384
            return;
444
        
385
        }
386
445
        FileObject fObj = obj.getPrimaryFile();
387
        FileObject fObj = obj.getPrimaryFile();
446
        ClassPath path = ClassPath.getClassPath(fObj, ClassPath.SOURCE);
388
        ClassPath path = ClassPath.getClassPath(fObj, ClassPath.SOURCE);
447
        if (path!=null)
389
        if (path != null) {
448
            resourceName = path.getResourceName(fObj);
390
            resourceName = path.getResourceName(fObj);
449
        
391
        }
450
        if (resourceName.indexOf(".")!=-1) // it's a class, otherwise package
392
393
        if (resourceName.indexOf(".") != -1) // it's a class, otherwise package
451
        {
394
        {
452
            resourceName = resourceName.substring(0, resourceName.indexOf("."));
395
            resourceName = resourceName.substring(0, resourceName.indexOf("."));
453
            className = resourceName.substring(resourceName.lastIndexOf("/") + 1);
396
            className = resourceName.substring(resourceName.lastIndexOf("/") + 1);
454
            
397
455
            // cvc - CR 6409539
398
            // cvc - CR 6409539
456
            // if class is in default package, the packageName has no slashes
399
            // if class is in default package, the packageName has no slashes
457
            // and therefore, the substring call breaks
400
            // and therefore, the substring call breaks
458
            int lastSlashIndex = resourceName.lastIndexOf("/");
401
            int lastSlashIndex = resourceName.lastIndexOf("/");
459
            if (lastSlashIndex > -1)
402
            if (lastSlashIndex > -1) {
460
                packageName = resourceName.substring(0, lastSlashIndex);
403
                packageName = resourceName.substring(0, lastSlashIndex);
461
        }
404
            }
462
        
405
        } else {
463
        else
464
        {
465
            packageName = resourceName;
406
            packageName = resourceName;
466
        }
407
        }
467
        
408
468
        TopComponent tc = WindowManager.getDefault()
409
        TopComponent tc = WindowManager.getDefault().findTopComponent("projectTabLogical_tc");
469
                .findTopComponent("projectTabLogical_tc");
410
470
        
411
        if (tc == null) {
471
        if (tc==null)
412
            return;
472
            return ;
413
        }
473
        
414
474
        ExplorerManager explorerManager =
415
        ExplorerManager explorerManager =
475
                ((ExplorerManager.Provider)tc).getExplorerManager();
416
                ((ExplorerManager.Provider) tc).getExplorerManager();
476
        
417
477
        Node root = explorerManager.getRootContext();
418
        Node root = explorerManager.getRootContext();
478
        Children c = root.getChildren();
419
        Children c = root.getChildren();
479
        Node[] projectNodes = c.getNodes(true);
420
        Node[] projectNodes = c.getNodes(true);
480
        
421
481
        for (int i=0; i<projectNodes.length; i++)
422
        for (int i = 0; i < projectNodes.length; i++) {
482
        {
423
            Project p = (Project) projectNodes[i].getLookup().lookup(Project.class);
483
            Project p = (Project) projectNodes[i]
424
484
                    .getLookup().lookup(Project.class);
485
            
486
            Node selected = null;
425
            Node selected = null;
487
            
426
488
            if (projects.contains(p))
427
            if (projects.contains(p)) {
489
            {
490
                Node selectedNode = null;
428
                Node selectedNode = null;
491
                
429
492
                StringTokenizer st = new StringTokenizer(packageName, "/");
430
                StringTokenizer st = new StringTokenizer(packageName, "/");
493
                if (st.hasMoreTokens())
431
                if (st.hasMoreTokens()) {
494
                {
495
                    String token = st.nextToken();
432
                    String token = st.nextToken();
496
                    selectedNode = findNodeByName(projectNodes[i],  token, true );
433
                    selectedNode = findNodeByName(projectNodes[i], token, true);
497
                    
434
498
                    while (selectedNode!=null && st.hasMoreTokens())
435
                    while (selectedNode != null && st.hasMoreTokens()) {
499
                    {
436
                        selectedNode = findNodeByName(selectedNode, st.nextToken(), true);
500
                        selectedNode = findNodeByName(selectedNode,  st.nextToken(), true);
501
                    }
437
                    }
502
                }
438
                }
503
                
439
504
                if (!isPackage && selectedNode!=null)
440
                if (!isPackage && selectedNode != null) {
505
                {
506
                    selectedNode = findNodeByName(selectedNode, className, false);
441
                    selectedNode = findNodeByName(selectedNode, className, false);
507
                }
442
                }
508
                
443
509
                final Node node = selectedNode;
444
                final Node node = selectedNode;
510
                if (node != null) {
445
                if (node != null) {
511
                    selectNodeAsync(node);
446
                    selectNodeAsync(node);
Lines 515-704 Link Here
515
        }
450
        }
516
        return;
451
        return;
517
    }
452
    }
518
    
453
519
    
454
    public static Node findNodeByName(Node root, String name, boolean isPackage) {
520
    public static Node findNodeByName(Node root, String name, boolean isPackage)
455
        if (root == null || root.isLeaf()) {
521
    {
522
        if (root == null || root.isLeaf())
523
            return null;
456
            return null;
524
        
457
        }
458
525
        Children children = root.getChildren();
459
        Children children = root.getChildren();
526
        Node[] nodes = children.getNodes(true);
460
        Node[] nodes = children.getNodes(true);
527
        
461
528
        for (int j=0; j<nodes.length; j++)
462
        for (int j = 0; j < nodes.length; j++) {
529
        {
530
            Node curNode = nodes[j];
463
            Node curNode = nodes[j];
531
            
464
532
            if (curNode.getCookie(ModelRootNodeCookie.class) != null)
465
            if (curNode.getCookie(ModelRootNodeCookie.class) != null) {
533
            {
534
                // cvc - CR 6409539
466
                // cvc - CR 6409539
535
                // if the class source is in the default package, the
467
                // if the class source is in the default package, the
536
                // findNodeByName doesn't know that Model root node
468
                // findNodeByName doesn't know that Model root node
537
                // is the default package
469
                // is the default package
538
                if (name.equals(DEFAULT_PACKAGE_DISPLAY_NAME))
470
                if (name.equals(DEFAULT_PACKAGE_DISPLAY_NAME)) {
539
                    return curNode;
471
                    return curNode;
540
                
472
                } else {
541
                else
542
                    return findNodeByName(curNode, name, isPackage);
473
                    return findNodeByName(curNode, name, isPackage);
474
                }
543
            }
475
            }
544
            
476
545
            IElement element = (IElement)curNode.getCookie(IElement.class);
477
            IElement element = (IElement) curNode.getCookie(IElement.class);
546
            
478
547
            if (element == null)
479
            if (element == null) {
548
                continue;
480
                continue;
549
            
481
            }
482
550
            String type = element.getElementType();
483
            String type = element.getElementType();
551
            
484
552
            if (isPackage)
485
            if (isPackage) {
553
            {
486
                if (curNode.getName().equals(name)
554
                if (curNode.getName().equals(name) &&
487
                        && type.equals(AbstractModelElementNode.ELEMENT_TYPE_PACKAGE)) {
555
                        type.equals(AbstractModelElementNode.ELEMENT_TYPE_PACKAGE))
556
                {
557
                    return curNode;
488
                    return curNode;
558
                }
489
                }
559
            }
490
            } else {
560
            
491
                if (curNode.getName().equals(name)
561
            else
492
                        && (type.equals(AbstractModelElementNode.ELEMENT_TYPE_CLASS))
562
            {
493
                        || (type.equals(AbstractModelElementNode.ELEMENT_TYPE_INTERFACE))) {
563
                if (curNode.getName().equals(name) &&
564
                        (type.equals(AbstractModelElementNode.ELEMENT_TYPE_CLASS)) ||
565
                        (type.equals(AbstractModelElementNode.ELEMENT_TYPE_INTERFACE)))
566
                {
567
                    return nodes[j];
494
                    return nodes[j];
568
                }
495
                }
569
            }
496
            }
570
        }
497
        }
571
        
498
572
        return null;
499
        return null;
573
    }
500
    }
574
    
575
    private static final RequestProcessor RP = new RequestProcessor();
501
    private static final RequestProcessor RP = new RequestProcessor();
576
    
502
577
    public static void selectNodeAsync(final Node selectedNode)
503
    public static void selectNodeAsync(final Node selectedNode) {
578
    {
504
579
        
505
        final TopComponent tc = WindowManager.getDefault().findTopComponent("projectTabLogical_tc");
580
        final TopComponent tc = WindowManager.getDefault().findTopComponent( "projectTabLogical_tc" );
506
        if (tc == null) {
581
        if (tc==null)
507
            return;
582
            return ;
508
        }
583
        
509
584
        final ExplorerManager manager =
510
        final ExplorerManager manager =
585
                ((ExplorerManager.Provider)tc).getExplorerManager();
511
                ((ExplorerManager.Provider) tc).getExplorerManager();
586
        tc.setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) );
512
        tc.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
587
        tc.open();
513
        tc.open();
588
        tc.requestActive();
514
        tc.requestActive();
589
        
515
590
        // Do it in different thread than AWT
516
        // Do it in different thread than AWT
591
        RP.post( new Runnable()
517
        RP.post(new Runnable() {
592
        {
518
593
            public void run()
519
            public void run() {
594
            {
520
595
                
596
                // Back to AWT
521
                // Back to AWT
597
                SwingUtilities.invokeLater( new Runnable()
522
                SwingUtilities.invokeLater(new Runnable() {
598
                {
523
599
                    public void run()
524
                    public void run() {
600
                    {
525
                        if (selectedNode != null) {
601
                        if ( selectedNode != null )
526
                            try {
602
                        {
527
                                manager.setSelectedNodes(new Node[]{selectedNode});
603
                            try
528
                                StatusDisplayer.getDefault().setStatusText(""); // NOI18N
604
                            {
529
                            } catch (PropertyVetoException e) {
605
                                manager.setSelectedNodes( new Node[] { selectedNode } );
606
                                StatusDisplayer.getDefault().setStatusText( "" ); // NOI18N
607
                            }
608
                            catch ( PropertyVetoException e )
609
                            {
610
                                // Bad day node found but can't be selected
530
                                // Bad day node found but can't be selected
611
                            }
531
                            }
532
                        } else {
533
                            StatusDisplayer.getDefault().setStatusText(
534
                                    NbBundle.getMessage(ProjectUtil.class, "MSG_NodeNotFound"));
612
                        }
535
                        }
613
                        else
536
                        tc.setCursor(null);
614
                        {
615
                            StatusDisplayer.getDefault().setStatusText(
616
                                    NbBundle.getMessage( ProjectUtil.class,  "MSG_NodeNotFound" ));
617
                        }
618
                        tc.setCursor( null );
619
                    }
537
                    }
620
                } );
538
                });
621
            }
539
            }
622
        } );
540
        });
623
        
541
624
    }
542
    }
625
    
543
626
    public static String createUniqueProjectName(
544
    public static String createUniqueProjectName(
627
            File location, String baseName, boolean tryNoIndexFirst)
545
            File location, String baseName, boolean tryNoIndexFirst) {
628
    {
629
        String projectName = null;
546
        String projectName = null;
630
        
547
631
        if (baseName == null || baseName.length() == 0)
548
        if (baseName == null || baseName.length() == 0) {
632
        {
633
            baseName = NbBundle.getMessage(
549
            baseName = NbBundle.getMessage(
634
                    ProjectUtil.class, "TXT_UMLProject"); // NOI18N
550
                    ProjectUtil.class, "TXT_UMLProject"); // NOI18N
635
        }
551
        }
636
        
552
637
        int baseCount =
553
        int baseCount =
638
                UMLProjectSettings.getDefault().getNewProjectCount() + 1;
554
                UMLProjectSettings.getDefault().getNewProjectCount() + 1;
639
        
555
640
        if (tryNoIndexFirst)
556
        if (tryNoIndexFirst) {
641
            projectName = validFreeProjectName(location, baseName, -1);
557
            projectName = validFreeProjectName(location, baseName, -1);
642
        
558
        }
643
        while (projectName == null)
559
644
        {
560
        while (projectName == null) {
645
            projectName = validFreeProjectName(
561
            projectName = validFreeProjectName(
646
                    location, baseName+"{0}", baseCount);
562
                    location, baseName + "{0}", baseCount);
647
            
563
648
            baseCount++;
564
            baseCount++;
649
        }
565
        }
650
        
566
651
        return projectName;
567
        return projectName;
652
    }
568
    }
653
    
569
654
    private static String validFreeProjectName(
570
    private static String validFreeProjectName(
655
            final File parentFolder,
571
            final File parentFolder,
656
            final String formatter,
572
            final String formatter,
657
            final int index)
573
            final int index) {
658
    {
659
        String name = "";
574
        String name = "";
660
        
575
661
        if (index == -1)
576
        if (index == -1) {
662
            name = formatter;
577
            name = formatter;
663
        
578
        } else {
664
        else
665
        {
666
            name = MessageFormat.format(
579
            name = MessageFormat.format(
667
                    formatter, new Object[]{new Integer(index)});
580
                    formatter, new Object[]{new Integer(index)});
668
        }
581
        }
669
        
582
670
        File file = new File(parentFolder, name);
583
        File file = new File(parentFolder, name);
671
        return file.exists() ? null : name;
584
        return file.exists() ? null : name;
672
    }
585
    }
673
    
586
674
    public static IProject getOwningProjectOfImportedElement(IElement imported)
587
    public static IProject getOwningProjectOfImportedElement(IElement imported) {
675
    {
676
        IElement owner = imported.getOwner();
588
        IElement owner = imported.getOwner();
677
        if (!(owner instanceof IProject))
589
        if (!(owner instanceof IProject)) {
678
            return getOwningProjectOfImportedElement(owner);
590
            return getOwningProjectOfImportedElement(owner);
679
        return (IProject)owner;
591
        }
592
        return (IProject) owner;
680
    }
593
    }
681
    
594
682
    public static class ProjectByDisplayNameComparator implements Comparator
595
    public static class ProjectByDisplayNameComparator implements Comparator {
683
    {
596
684
        
685
        private static Comparator COLLATOR = Collator.getInstance();
597
        private static Comparator COLLATOR = Collator.getInstance();
686
        
598
687
        public int compare(Object o1, Object o2)
599
        public int compare(Object o1, Object o2) {
688
        {
600
689
            
601
            if (!(o1 instanceof Project)) {
690
            if ( !( o1 instanceof Project ) )
691
            {
692
                return 1;
602
                return 1;
693
            }
603
            }
694
            if ( !( o2 instanceof Project ) )
604
            if (!(o2 instanceof Project)) {
695
            {
696
                return -1;
605
                return -1;
697
            }
606
            }
698
            
607
699
            Project p1 = (Project)o1;
608
            Project p1 = (Project) o1;
700
            Project p2 = (Project)o2;
609
            Project p2 = (Project) o2;
701
            
610
702
            return COLLATOR.compare(ProjectUtils.getInformation(p1).getDisplayName(), ProjectUtils.getInformation(p2).getDisplayName());
611
            return COLLATOR.compare(ProjectUtils.getInformation(p1).getDisplayName(), ProjectUtils.getInformation(p2).getDisplayName());
703
        }
612
        }
704
    }
613
    }
(-)a/uml.project/src/org/netbeans/modules/uml/project/SaveProjectsDialog.java (-118 / +91 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on April 10, 2005, 7:31 AM
48
 * Created on April 10, 2005, 7:31 AM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project;
50
package org.netbeans.modules.uml.project;
52
51
53
import java.awt.Component;
52
import java.awt.Component;
Lines 86-197 Link Here
86
 *
85
 *
87
 * @author  Administrator
86
 * @author  Administrator
88
 */
87
 */
89
public class SaveProjectsDialog extends JCenterDialog
88
public class SaveProjectsDialog extends JCenterDialog {
90
{
89
91
    private DefaultListModel mModel = new DefaultListModel();
90
    private DefaultListModel mModel = new DefaultListModel();
92
    private boolean mIsCanceled = true;
91
    private boolean mIsCanceled = true;
93
    
92
94
    /** Creates new form SaveProjectsDialog */
93
    /** Creates new form SaveProjectsDialog */
95
    public SaveProjectsDialog(Frame parent, boolean modal)
94
    public SaveProjectsDialog(Frame parent, boolean modal) {
96
    {
97
        super(parent, modal);
95
        super(parent, modal);
98
        initComponents();
96
        initComponents();
99
        //initDirtyProjectList();
97
        //initDirtyProjectList();
100
        
98
101
        mProjectsList.setCellRenderer(new UMLProjectRender());
99
        mProjectsList.setCellRenderer(new UMLProjectRender());
102
        mProjectsList.setModel(mModel);
100
        mProjectsList.setModel(mModel);
103
    }
101
    }
104
    
102
105
    /**
103
    /**
106
     * Adds all the UML projects that are marked as being dirty to list model.
104
     * Adds all the UML projects that are marked as being dirty to list model.
107
     */
105
     */
108
    protected void initDirtyProjectList()
106
    protected void initDirtyProjectList() {
109
    {
110
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
107
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
111
        
108
112
        for(Project curProj : allProjects)
109
        for (Project curProj : allProjects) {
113
        {
110
            UMLProjectHelper helper = (UMLProjectHelper) curProj.getLookup().lookup(UMLProjectHelper.class);
114
            UMLProjectHelper helper = (UMLProjectHelper)curProj.getLookup()
111
115
            .lookup(UMLProjectHelper.class);
112
            if (helper != null) {
116
            
117
            if(helper != null)
118
            {
119
                IProject umlProject = helper.getProject();
113
                IProject umlProject = helper.getProject();
120
                if((umlProject != null) && (umlProject.isDirty() == true))
114
                if ((umlProject != null) && (umlProject.isDirty() == true)) {
121
                {
122
                    mModel.addElement(curProj);
115
                    mModel.addElement(curProj);
123
                }
116
                }
124
            }
117
            }
125
        }
118
        }
126
    }
119
    }
127
    
120
128
    public void addProject(Project project)
121
    public void addProject(Project project) {
129
    {
130
        mModel.addElement(project);
122
        mModel.addElement(project);
131
    }
123
    }
132
    
124
133
    public void showDialog()
125
    public void showDialog() {
134
    {
135
        mProjectsList.setSelectedIndex(0);
126
        mProjectsList.setSelectedIndex(0);
136
        setVisible(true);
127
        setVisible(true);
137
    }
128
    }
138
    
129
139
    public static boolean saveProjects()
130
    public static boolean saveProjects() {
140
    {
141
        boolean retVal = true;
131
        boolean retVal = true;
142
        
132
143
        Frame frame = WindowManager.getDefault().getMainWindow();
133
        Frame frame = WindowManager.getDefault().getMainWindow();
144
        SaveProjectsDialog dialog = new SaveProjectsDialog(frame, true);
134
        SaveProjectsDialog dialog = new SaveProjectsDialog(frame, true);
145
135
146
        dialog.getRootPane().setDefaultButton(dialog.mSaveBtn);
136
        dialog.getRootPane().setDefaultButton(dialog.mSaveBtn);
147
        
137
148
        dialog.getAccessibleContext().setAccessibleName(NbBundle.getMessage(
138
        dialog.getAccessibleContext().setAccessibleName(NbBundle.getMessage(
149
            SaveProjectsDialog.class, "ACSN_SaveProjectsDialog")); // NOI18N
139
                SaveProjectsDialog.class, "ACSN_SaveProjectsDialog")); // NOI18N
150
        dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(
140
        dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(
151
            SaveProjectsDialog.class, "ACSD_SaveProjectsDialog")); // NOI18N
141
                SaveProjectsDialog.class, "ACSD_SaveProjectsDialog")); // NOI18N
152
        
142
153
        // Load the projects that need to be saved into the dialog. If no projects
143
        // Load the projects that need to be saved into the dialog. If no projects
154
        // needed to be saved then do not show the dialog.
144
        // needed to be saved then do not show the dialog.
155
        boolean showDialog = false;
145
        boolean showDialog = false;
156
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
146
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
157
        
147
158
        for (Project curProj : allProjects)
148
        for (Project curProj : allProjects) {
159
        {
149
            UMLProjectHelper helper = (UMLProjectHelper) curProj.getLookup().lookup(UMLProjectHelper.class);
160
            UMLProjectHelper helper = (UMLProjectHelper)curProj
150
161
                .getLookup().lookup(UMLProjectHelper.class);
151
            if (helper != null) {
162
            
163
            if (helper != null)
164
            {
165
                IProject umlProject = helper.getProject();
152
                IProject umlProject = helper.getProject();
166
                
153
167
                if ((umlProject != null) && (umlProject.isDirty() == true))
154
                if ((umlProject != null) && (umlProject.isDirty() == true)) {
168
                {
169
                    dialog.addProject(curProj);
155
                    dialog.addProject(curProj);
170
                    showDialog = true;
156
                    showDialog = true;
171
                }
157
                }
172
            }
158
            }
173
        }
159
        }
174
        
160
175
        if (showDialog == true)
161
        if (showDialog == true) {
176
        {
177
            dialog.showDialog();
162
            dialog.showDialog();
178
            if(dialog.isCanceled() == true)
163
            if (dialog.isCanceled() == true) {
179
            {
180
                retVal = false;
164
                retVal = false;
181
            }
165
            }
182
        }
166
        }
183
        
167
184
        return retVal;
168
        return retVal;
185
    }
169
    }
186
    
170
187
    /**
171
    /**
188
     * Retruns whether or not the user canceled the save operation.
172
     * Retruns whether or not the user canceled the save operation.
189
     */
173
     */
190
    public boolean isCanceled()
174
    public boolean isCanceled() {
191
    {
192
        return mIsCanceled;
175
        return mIsCanceled;
193
    }
176
    }
194
    
177
195
    /** This method is called from within the constructor to
178
    /** This method is called from within the constructor to
196
     * initialize the form.
179
     * initialize the form.
197
     * WARNING: Do NOT modify this code. The content of this method is
180
     * WARNING: Do NOT modify this code. The content of this method is
Lines 319-424 Link Here
319
302
320
        pack();
303
        pack();
321
    }// </editor-fold>//GEN-END:initComponents
304
    }// </editor-fold>//GEN-END:initComponents
322
        
305
323
   private void mCancelBtnActionPerformed(ActionEvent evt)//GEN-FIRST:event_mCancelBtnActionPerformed
306
   private void mCancelBtnActionPerformed(ActionEvent evt)//GEN-FIRST:event_mCancelBtnActionPerformed
324
   {//GEN-HEADEREND:event_mCancelBtnActionPerformed
307
   {//GEN-HEADEREND:event_mCancelBtnActionPerformed
325
       closeWindow(true);
308
       closeWindow(true);
326
   }//GEN-LAST:event_mCancelBtnActionPerformed
309
   }//GEN-LAST:event_mCancelBtnActionPerformed
327
   
310
328
   private void mDiscardAllBtnActionPerformed(ActionEvent evt)//GEN-FIRST:event_mDiscardAllBtnActionPerformed
311
   private void mDiscardAllBtnActionPerformed(ActionEvent evt)//GEN-FIRST:event_mDiscardAllBtnActionPerformed
329
   {//GEN-HEADEREND:event_mDiscardAllBtnActionPerformed
312
   {//GEN-HEADEREND:event_mDiscardAllBtnActionPerformed
330
       int count = mModel.getSize();
313
       int count = mModel.getSize();
331
       UMLProject[] projects = new UMLProject[count];
314
       UMLProject[] projects = new UMLProject[count];
332
       
315
333
       for(int index = 0; index < count; index++)
316
       for (int index = 0; index < count; index++) {
334
       {
317
           projects[index] = (UMLProject) mModel.getElementAt(index);
335
           projects[index] = (UMLProject)mModel.getElementAt(index);
318
336
           
319
           UMLProjectHelper helper = (UMLProjectHelper) projects[index].getLookup().lookup(UMLProjectHelper.class);
337
           UMLProjectHelper helper = (UMLProjectHelper)projects[index]
320
338
               .getLookup().lookup(UMLProjectHelper.class);
339
           
340
           helper.getProject().setDirty(false);
321
           helper.getProject().setDirty(false);
341
           helper.getProject().setChildrenDirty(false);
322
           helper.getProject().setChildrenDirty(false);
342
       }
323
       }
343
       
324
344
       closeWindow(false);
325
       closeWindow(false);
345
   }//GEN-LAST:event_mDiscardAllBtnActionPerformed
326
   }//GEN-LAST:event_mDiscardAllBtnActionPerformed
346
   
327
347
   private void mSaveAllBtnActionPerformed(ActionEvent evt)//GEN-FIRST:event_mSaveAllBtnActionPerformed
328
   private void mSaveAllBtnActionPerformed(ActionEvent evt)//GEN-FIRST:event_mSaveAllBtnActionPerformed
348
   {//GEN-HEADEREND:event_mSaveAllBtnActionPerformed
329
   {//GEN-HEADEREND:event_mSaveAllBtnActionPerformed
349
       int count = mModel.getSize();
330
       int count = mModel.getSize();
350
       UMLProject[] projects = new UMLProject[count];
331
       UMLProject[] projects = new UMLProject[count];
351
       
332
352
       for (int index = 0; index < count; index++)
333
       for (int index = 0; index < count; index++) {
353
           projects[index] = (UMLProject)mModel.getElementAt(index);
334
           projects[index] = (UMLProject) mModel.getElementAt(index);
354
       
335
       }
336
355
       saveProjects(projects);
337
       saveProjects(projects);
356
       closeWindow(false);
338
       closeWindow(false);
357
   }//GEN-LAST:event_mSaveAllBtnActionPerformed
339
   }//GEN-LAST:event_mSaveAllBtnActionPerformed
358
   
340
359
   private void mSaveBtnActionPerformed(ActionEvent evt)//GEN-FIRST:event_mSaveBtnActionPerformed
341
   private void mSaveBtnActionPerformed(ActionEvent evt)//GEN-FIRST:event_mSaveBtnActionPerformed
360
   {//GEN-HEADEREND:event_mSaveBtnActionPerformed
342
   {//GEN-HEADEREND:event_mSaveBtnActionPerformed
361
       int[] indices = mProjectsList.getSelectedIndices();
343
       int[] indices = mProjectsList.getSelectedIndices();
362
       UMLProject[] projects = new UMLProject[indices.length];
344
       UMLProject[] projects = new UMLProject[indices.length];
363
       int totUnsaved = mModel.size();
345
       int totUnsaved = mModel.size();
364
       
346
365
       for (int index = 0; index < indices.length; index++)
347
       for (int index = 0; index < indices.length; index++) {
366
       {
367
           // get selected projects to be saved
348
           // get selected projects to be saved
368
           projects[index] = (UMLProject)mModel.getElementAt(indices[index]);
349
           projects[index] = (UMLProject) mModel.getElementAt(indices[index]);
369
           
350
370
           // remove the project from the listbox because once it is saved
351
           // remove the project from the listbox because once it is saved
371
           // it no longer needs to be listed as dirty
352
           // it no longer needs to be listed as dirty
372
           mModel.removeElementAt(indices[index]);
353
           mModel.removeElementAt(indices[index]);
373
       }
354
       }
374
       
355
375
       saveProjects(projects);
356
       saveProjects(projects);
376
357
377
       // only close the dialog if all the dirty projects were saved
358
       // only close the dialog if all the dirty projects were saved
378
       // otherwise leave dialog open to allow the rest to be saved
359
       // otherwise leave dialog open to allow the rest to be saved
379
       if (indices.length == totUnsaved)
360
       if (indices.length == totUnsaved) {
380
           closeWindow(false);
361
           closeWindow(false);
381
       
362
       } else {
382
       else
383
           mProjectsList.setSelectedIndex(0);
363
           mProjectsList.setSelectedIndex(0);
364
       }
384
   }//GEN-LAST:event_mSaveBtnActionPerformed
365
   }//GEN-LAST:event_mSaveBtnActionPerformed
385
   
386
   protected void closeWindow(boolean isCanceled)
387
   {
388
       mIsCanceled = isCanceled;
389
       setVisible(false);
390
   }
391
   
392
   protected void saveProjects(UMLProject[] projects)
393
   {
394
       for(UMLProject curProj : projects)
395
       {
396
           curProj.saveProject();
397
       }
398
   }
399
366
400
   
367
    protected void closeWindow(boolean isCanceled) {
401
   public class UMLProjectRender extends DefaultListCellRenderer
368
        mIsCanceled = isCanceled;
402
   {
369
        setVisible(false);
403
       public Component getListCellRendererComponent(JList list,
370
    }
404
           Object value,
371
405
           int index,
372
    protected void saveProjects(UMLProject[] projects) {
406
           boolean isSelected,
373
        for (UMLProject curProj : projects) {
407
           boolean cellHasFocus)
374
            curProj.saveProject();
408
       {
375
        }
409
           Project project = (Project)value;
376
    }
410
           
377
411
           ProjectInformation info = (ProjectInformation)project
378
    public class UMLProjectRender extends DefaultListCellRenderer {
412
               .getLookup().lookup(ProjectInformation.class);
379
413
           
380
        public Component getListCellRendererComponent(JList list,
414
           super.getListCellRendererComponent(
381
                Object value,
415
               list, info.getDisplayName(), index, isSelected, cellHasFocus);
382
                int index,
416
           
383
                boolean isSelected,
417
           setIcon(info.getIcon());
384
                boolean cellHasFocus) {
418
           return this;
385
            Project project = (Project) value;
419
       }
386
420
   }
387
            ProjectInformation info = (ProjectInformation) project.getLookup().lookup(ProjectInformation.class);
421
   
388
389
            super.getListCellRendererComponent(
390
                    list, info.getDisplayName(), index, isSelected, cellHasFocus);
391
392
            setIcon(info.getIcon());
393
            return this;
394
        }
395
    }
422
    // Variables declaration - do not modify//GEN-BEGIN:variables
396
    // Variables declaration - do not modify//GEN-BEGIN:variables
423
    private javax.swing.JPanel jPanel1;
397
    private javax.swing.JPanel jPanel1;
424
    private javax.swing.JScrollPane jScrollPane1;
398
    private javax.swing.JScrollPane jScrollPane1;
Lines 428-432 Link Here
428
    private javax.swing.JButton mSaveAllBtn;
402
    private javax.swing.JButton mSaveAllBtn;
429
    private javax.swing.JButton mSaveBtn;
403
    private javax.swing.JButton mSaveBtn;
430
    // End of variables declaration//GEN-END:variables
404
    // End of variables declaration//GEN-END:variables
431
    
432
}
405
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/UMLActionProvider.java (-29 / +16 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project;
44
package org.netbeans.modules.uml.project;
46
45
47
import java.io.IOException;
46
import java.io.IOException;
Lines 50-62 Link Here
50
import org.openide.ErrorManager;
49
import org.openide.ErrorManager;
51
import org.openide.util.Lookup;
50
import org.openide.util.Lookup;
52
51
53
public class UMLActionProvider implements ActionProvider
52
public class UMLActionProvider implements ActionProvider {
54
{
55
    // Fixed for IZ# 118836
53
    // Fixed for IZ# 118836
56
    // Commented out actions that are not applicable to UML project to prevent
54
    // Commented out actions that are not applicable to UML project to prevent
57
    // them from being shown on the menu.
55
    // them from being shown on the menu.
58
    private static final String[] supportedActions =
56
59
    {
57
    private static final String[] supportedActions = {
60
        //COMMAND_BUILD,
58
        //COMMAND_BUILD,
61
        //COMMAND_CLEAN,
59
        //COMMAND_CLEAN,
62
        //COMMAND_REBUILD,
60
        //COMMAND_REBUILD,
Lines 71-113 Link Here
71
        //COMMAND_DEBUG_STEP_INTO,
69
        //COMMAND_DEBUG_STEP_INTO,
72
        COMMAND_DELETE
70
        COMMAND_DELETE
73
    };
71
    };
74
    
75
    private UMLProject mProject = null;
72
    private UMLProject mProject = null;
76
    private UMLProjectHelper mHelper = null;
73
    private UMLProjectHelper mHelper = null;
77
    
74
78
    public UMLActionProvider(UMLProject project, UMLProjectHelper helper)
75
    public UMLActionProvider(UMLProject project, UMLProjectHelper helper) {
79
    {
80
        mProject = project;
76
        mProject = project;
81
        mHelper = helper;
77
        mHelper = helper;
82
    }
78
    }
83
    
79
84
    public String[] getSupportedActions()
80
    public String[] getSupportedActions() {
85
    {
86
        return supportedActions;
81
        return supportedActions;
87
    }
82
    }
88
    
83
89
    public void invokeAction(String command, Lookup context)
84
    public void invokeAction(String command, Lookup context)
90
        throws IllegalArgumentException
85
            throws IllegalArgumentException {
91
    {
86
        if (command.equals(COMMAND_DELETE)) {
92
        if (command.equals(COMMAND_DELETE))
87
            UMLPhysicalViewProvider provider = (UMLPhysicalViewProvider) mProject.getLookup().lookup(UMLPhysicalViewProvider.class);
93
        {
88
94
            UMLPhysicalViewProvider provider = (UMLPhysicalViewProvider)mProject.
89
            try {
95
                getLookup().lookup(UMLPhysicalViewProvider.class);
96
            
97
            try
98
            {
99
                provider.createLogicalView().destroy();
90
                provider.createLogicalView().destroy();
100
            }
91
            } catch (IOException e) {
101
            
102
            catch (IOException e)
103
            {
104
                ErrorManager.getDefault().notify(e);
92
                ErrorManager.getDefault().notify(e);
105
            }
93
            }
106
        }
94
        }
107
    }
95
    }
108
    
96
109
    public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException
97
    public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException {
110
    {
111
        //System.out.println("UMLActionProvider: command="+ command);
98
        //System.out.println("UMLActionProvider: command="+ command);
112
        return true;
99
        return true;
113
    }
100
    }
(-)a/uml.project/src/org/netbeans/modules/uml/project/UMLProjectDataObject.java (-124 / +90 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project;
44
package org.netbeans.modules.uml.project;
46
45
47
import java.io.IOException;
46
import java.io.IOException;
Lines 73-117 Link Here
73
 *
72
 *
74
 * @author Sheryl
73
 * @author Sheryl
75
 */
74
 */
76
public class UMLProjectDataObject extends MultiDataObject
75
public class UMLProjectDataObject extends MultiDataObject {
77
{
78
//    static final long serialVersionUID = 1L;
76
//    static final long serialVersionUID = 1L;
79
    
77
80
    // file extension for uml project xml file
78
    // file extension for uml project xml file
81
    public static final String EXT = "etd";  //NOI18N
79
    public static final String EXT = "etd";  //NOI18N
82
    public static final String ICON = ImageUtil.IMAGE_FOLDER + "model-root-node.png"; // NOI18N
80
    public static final String ICON = ImageUtil.IMAGE_FOLDER + "model-root-node.png"; // NOI18N
83
    private EditorCookie editor = null;
81
    private EditorCookie editor = null;
84
    
85
    private FileObject fo = null;
82
    private FileObject fo = null;
86
    
83
87
    /** Creates a new instance of UMLProjectDataObject */
84
    /** Creates a new instance of UMLProjectDataObject */
88
    public UMLProjectDataObject(FileObject fo, MultiFileLoader loader)
85
    public UMLProjectDataObject(FileObject fo, MultiFileLoader loader)
89
    throws DataObjectExistsException
86
            throws DataObjectExistsException {
90
    {
91
        super(fo, loader);
87
        super(fo, loader);
92
        this.fo = fo;
88
        this.fo = fo;
93
        
89
94
        CookieSet.Factory factory = new CookieSet.Factory()
90
        CookieSet.Factory factory = new CookieSet.Factory() {
95
        {
91
96
            public Node.Cookie createCookie(Class klass)
92
            public Node.Cookie createCookie(Class klass) {
97
            {
98
                if (klass.isAssignableFrom(EditorCookie.class)
93
                if (klass.isAssignableFrom(EditorCookie.class)
99
                || klass.isAssignableFrom(OpenCookie.class)
94
                        || klass.isAssignableFrom(OpenCookie.class)
100
                || klass.isAssignableFrom(CloseCookie.class)
95
                        || klass.isAssignableFrom(CloseCookie.class)
101
                || klass.isAssignableFrom(PrintCookie.class) )
96
                        || klass.isAssignableFrom(PrintCookie.class)) {
102
                {
97
                    if (editor == null) {
103
                    if (editor == null) editor = createEditorCookie(); 
98
                        editor = createEditorCookie();
104
                    if (editor == null) return null;                    
99
                    }
105
                    
100
                    if (editor == null) {
101
                        return null;
102
                    }
103
106
                    return klass.isAssignableFrom(editor.getClass()) ? editor : null;
104
                    return klass.isAssignableFrom(editor.getClass()) ? editor : null;
107
                }
105
                } else {
108
                else
109
                {
110
                    return null;
106
                    return null;
111
                }
107
                }
112
            }
108
            }
113
        };
109
        };
114
        
110
115
        CookieSet cookies = getCookieSet();
111
        CookieSet cookies = getCookieSet();
116
        // EditorCookie.class must be synchronized with
112
        // EditorCookie.class must be synchronized with
117
        // UMLEditor.Env->findCloneableOpenSupport
113
        // UMLEditor.Env->findCloneableOpenSupport
Lines 120-169 Link Here
120
        cookies.add(CloseCookie.class, factory);
116
        cookies.add(CloseCookie.class, factory);
121
        cookies.add(PrintCookie.class, factory);
117
        cookies.add(PrintCookie.class, factory);
122
    }
118
    }
123
    
119
124
    private FileObject getFileObject()
120
    private FileObject getFileObject() {
125
    {
126
        return fo;
121
        return fo;
127
    }
122
    }
128
    
123
129
    protected EditorCookie createEditorCookie()
124
    protected EditorCookie createEditorCookie() {
130
    {
131
        return new UMLEditorSupport(this);
125
        return new UMLEditorSupport(this);
132
    }
126
    }
133
    
127
134
    protected final void addSaveCookie()
128
    protected final void addSaveCookie() {
135
    {
136
        getCookieSet().add(new Save());
129
        getCookieSet().add(new Save());
137
    }
130
    }
138
    
131
139
    private final void removeSaveCookie(SaveCookie save)
132
    private final void removeSaveCookie(SaveCookie save) {
140
    {
141
        getCookieSet().remove(save);
133
        getCookieSet().remove(save);
142
    }
134
    }
143
    
135
144
    private String getDisplayName()
136
    private String getDisplayName() {
145
    {
146
        Project proj = FileOwnerQuery.getOwner(getFileObject());
137
        Project proj = FileOwnerQuery.getOwner(getFileObject());
147
        UMLProjectHelper helper = null;
138
        UMLProjectHelper helper = null;
148
        if ( proj != null )
139
        if (proj != null) {
149
        {
150
            Lookup lkup = proj.getLookup();
140
            Lookup lkup = proj.getLookup();
151
            helper = (lkup != null  ? lkup.lookup(UMLProjectHelper.class) : null);
141
            helper = (lkup != null ? lkup.lookup(UMLProjectHelper.class) : null);
152
        }
142
        }
153
        
143
154
        if (helper != null)
144
        if (helper != null) {
155
            return helper.getDisplayName();
145
            return helper.getDisplayName();
146
        }
156
// conover - removing the word "Model" in the Save dialog
147
// conover - removing the word "Model" in the Save dialog
157
//            return helper.getDisplayName() + " " + NbBundle.getMessage(
148
//            return helper.getDisplayName() + " " + NbBundle.getMessage(
158
//                UMLModelRootNode.class, "CTL_UMLModelRootNode"); // NOI18N
149
//                UMLModelRootNode.class, "CTL_UMLModelRootNode"); // NOI18N
159
        
150
160
        return getName();
151
        return getName();
161
    }
152
    }
162
    
153
163
    protected Node createNodeDelegate()
154
    protected Node createNodeDelegate() {
164
    {
165
        DataNode node = null;
155
        DataNode node = null;
166
        
156
167
//        Project currentProj = FileOwnerQuery.getOwner(getFileObject());
157
//        Project currentProj = FileOwnerQuery.getOwner(getFileObject());
168
//        UMLPhysicalViewProvider view = (UMLPhysicalViewProvider)currentProj.
158
//        UMLPhysicalViewProvider view = (UMLPhysicalViewProvider)currentProj.
169
//                getLookup().lookup(UMLPhysicalViewProvider.class);
159
//                getLookup().lookup(UMLPhysicalViewProvider.class);
Lines 172-178 Link Here
172
//        
162
//        
173
//        if (dnode != null)
163
//        if (dnode != null)
174
//            return dnode;
164
//            return dnode;
175
        
165
176
        node = new DataNode(this, org.openide.nodes.Children.LEAF);
166
        node = new DataNode(this, org.openide.nodes.Children.LEAF);
177
        // netbeans.core.nodes.description
167
        // netbeans.core.nodes.description
178
        node.setShortDescription(NbBundle.getMessage(
168
        node.setShortDescription(NbBundle.getMessage(
Lines 181-312 Link Here
181
        node.setDisplayName(getDisplayName());
171
        node.setDisplayName(getDisplayName());
182
        return node;
172
        return node;
183
    }
173
    }
184
    
174
185
    
175
    public boolean isMoveAllowed() {
186
    public boolean isMoveAllowed()
187
    {
188
        return false;
176
        return false;
189
    }
177
    }
190
    
178
191
    /* Getter for rename action.
179
    /* Getter for rename action.
192
     * @return true if the object can be renamed
180
     * @return true if the object can be renamed
193
     */
181
     */
194
    public boolean isRenameAllowed()
182
    public boolean isRenameAllowed() {
195
    {
196
        return false;
183
        return false;
197
    }
184
    }
198
    
185
199
    
186
    private static class UMLEditorSupport extends DataEditorSupport
200
    private static class UMLEditorSupport extends DataEditorSupport 
187
            implements OpenCookie, EditorCookie.Observable, PrintCookie, CloseCookie {
201
            implements OpenCookie, EditorCookie.Observable, PrintCookie, CloseCookie
188
202
    {
189
        public UMLEditorSupport(UMLProjectDataObject obj) {
203
        public UMLEditorSupport(UMLProjectDataObject obj)
204
        {
205
            super(obj, new UMLEditorEnv(obj));
190
            super(obj, new UMLEditorEnv(obj));
206
            setMIMEType("text/xml"); // NOI18N
191
            setMIMEType("text/xml"); // NOI18N
207
        }
192
        }
208
        
193
209
    
194
        private static class UMLEditorEnv extends DataEditorSupport.Env {
210
        private static class UMLEditorEnv extends DataEditorSupport.Env
211
        {
212
//            private static final long serialVersionUID = 1L;
195
//            private static final long serialVersionUID = 1L;
213
            
196
214
            public UMLEditorEnv(DataObject obj)
197
            public UMLEditorEnv(DataObject obj) {
215
            {
216
                super(obj);
198
                super(obj);
217
            }
199
            }
218
            
200
219
            protected FileObject getFile()
201
            protected FileObject getFile() {
220
            {
221
                return getDataObject().getPrimaryFile();
202
                return getDataObject().getPrimaryFile();
222
            }
203
            }
223
            
204
224
            /* make uml project data file read only in editor to prevent users
205
            /* make uml project data file read only in editor to prevent users
225
             * from tampering it accidentally
206
             * from tampering it accidentally
226
             */
207
             */
227
            protected FileLock takeLock() throws IOException
208
            protected FileLock takeLock() throws IOException {
228
            {
229
                throw new IOException("Read Only"); // I18N
209
                throw new IOException("Read Only"); // I18N
230
            }
210
            }
231
            
211
232
            public CloneableOpenSupport findCloneableOpenSupport()
212
            public CloneableOpenSupport findCloneableOpenSupport() {
233
            {
234
                return (CloneableOpenSupport) getDataObject().getCookie(EditorCookie.class);
213
                return (CloneableOpenSupport) getDataObject().getCookie(EditorCookie.class);
235
            }
214
            }
236
        }
215
        }
237
    }
216
    }
238
    
217
239
    
218
    private class Save implements SaveCookie {
240
    private class Save implements SaveCookie
219
241
    {
220
        public void save() throws IOException {
242
        public void save() throws IOException
243
        {
244
            //custom logic to save uml project files
221
            //custom logic to save uml project files
245
            Project currentProj = FileOwnerQuery.getOwner(getFileObject());
222
            Project currentProj = FileOwnerQuery.getOwner(getFileObject());
246
            if (currentProj != null && currentProj.getLookup() != null) 
223
            if (currentProj != null && currentProj.getLookup() != null) {
247
            {
224
                UMLProjectHelper helper = (UMLProjectHelper) currentProj.getLookup().
248
                UMLProjectHelper helper = (UMLProjectHelper)currentProj.getLookup().
225
                        lookup(UMLProjectHelper.class);
249
                    lookup(UMLProjectHelper.class);
226
                if (helper != null) {
250
                if (helper!=null)
251
                {
252
                    // save modified documentation in the edit pane
227
                    // save modified documentation in the edit pane
253
                    DocumentationTopComponnet.saveDocumentation();
228
                    DocumentationTopComponnet.saveDocumentation();
254
                    
229
255
                    helper.saveProject();
230
                    helper.saveProject();
256
                    SaveCookie save = (SaveCookie) UMLProjectDataObject.this.
231
                    SaveCookie save = (SaveCookie) UMLProjectDataObject.this.getCookie(SaveCookie.class);
257
                        getCookie(SaveCookie.class);
232
                    if (save != null) {
258
                    if (save!=null)
259
                        UMLProjectDataObject.this.removeSaveCookie(save);
233
                        UMLProjectDataObject.this.removeSaveCookie(save);
234
                    }
260
                    setModified(false);
235
                    setModified(false);
261
                }
236
                }
262
            }
237
            }
263
        }
238
        }
264
    }
239
    }
265
    
240
266
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~ private Loader ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
241
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~ private Loader ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267
    
268
    
269
    /** The DataLoader for UMLProjectDataObjects.
242
    /** The DataLoader for UMLProjectDataObjects.
270
     */
243
     */
271
    static final class Loader extends MultiFileLoader
244
    static final class Loader extends MultiFileLoader {
272
    {
245
273
        static final long serialVersionUID =1L;
246
        static final long serialVersionUID = 1L;
247
274
        /** Creates a new XMLDataLoader */
248
        /** Creates a new XMLDataLoader */
275
        public Loader()
249
        public Loader() {
276
        {
277
            super("org.netbeans.modules.uml.project.UMLProjectDataObject"); // NOI18N
250
            super("org.netbeans.modules.uml.project.UMLProjectDataObject"); // NOI18N
278
        }
251
        }
279
        
252
280
        protected String actionsContext()
253
        protected String actionsContext() {
281
        {
282
            return "Loaders/text/xml/Actions"; // NOI18N
254
            return "Loaders/text/xml/Actions"; // NOI18N
283
        }
255
        }
284
        
256
285
        /** Get the default display name of this loader.
257
        /** Get the default display name of this loader.
286
         * @return default display name
258
         * @return default display name
287
         */
259
         */
288
        protected String defaultDisplayName()
260
        protected String defaultDisplayName() {
289
        {
290
            return NbBundle.getMessage(UMLProjectDataObject.class, "PROP_UMLProjectDataLoader_Name");
261
            return NbBundle.getMessage(UMLProjectDataObject.class, "PROP_UMLProjectDataLoader_Name");
291
        }
262
        }
292
        
263
293
        /** For a given file finds a primary file.
264
        /** For a given file finds a primary file.
294
         * @param fo the file to find primary file for
265
         * @param fo the file to find primary file for
295
         *
266
         *
296
         * @return the primary file for the file or null if the file is not
267
         * @return the primary file for the file or null if the file is not
297
         *   recognized by this loader
268
         *   recognized by this loader
298
         */
269
         */
299
        protected FileObject findPrimaryFile(FileObject fo)
270
        protected FileObject findPrimaryFile(FileObject fo) {
300
        {
301
            String ext = fo.getExt();
271
            String ext = fo.getExt();
302
            if (ext.equals(EXT))
272
            if (ext.equals(EXT)) {
303
            { 
304
                return fo;
273
                return fo;
305
            }
274
            }
306
            // not recognized
275
            // not recognized
307
            return null;
276
            return null;
308
        }
277
        }
309
        
278
310
        /** Creates the right data object for given primary file.
279
        /** Creates the right data object for given primary file.
311
         * It is guaranteed that the provided file is realy primary file
280
         * It is guaranteed that the provided file is realy primary file
312
         * returned from the method findPrimaryFile.
281
         * returned from the method findPrimaryFile.
Lines 316-344 Link Here
316
         * @exception DataObjectExistsException if the primary file already has data object
285
         * @exception DataObjectExistsException if the primary file already has data object
317
         */
286
         */
318
        protected MultiDataObject createMultiObject(FileObject primaryFile)
287
        protected MultiDataObject createMultiObject(FileObject primaryFile)
319
        throws DataObjectExistsException
288
                throws DataObjectExistsException {
320
        {
321
            return new UMLProjectDataObject(primaryFile, this);
289
            return new UMLProjectDataObject(primaryFile, this);
322
        }
290
        }
323
        
291
324
        /** Creates the right primary entry for given primary file.
292
        /** Creates the right primary entry for given primary file.
325
         *
293
         *
326
         * @param primaryFile primary file recognized by this loader
294
         * @param primaryFile primary file recognized by this loader
327
         * @return primary entry for that file
295
         * @return primary entry for that file
328
         */
296
         */
329
        protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile)
297
        protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) {
330
        {
331
            return new FileEntry(obj, primaryFile);
298
            return new FileEntry(obj, primaryFile);
332
        }
299
        }
333
        
300
334
        /** Creates right secondary entry for given file. The file is said to
301
        /** Creates right secondary entry for given file. The file is said to
335
         * belong to an object created by this loader.
302
         * belong to an object created by this loader.
336
         *
303
         *
337
         * @param secondaryFile secondary file for which we want to create entry
304
         * @param secondaryFile secondary file for which we want to create entry
338
         * @return the entry
305
         * @return the entry
339
         */
306
         */
340
        protected MultiDataObject.Entry createSecondaryEntry(MultiDataObject obj, FileObject secondaryFile)
307
        protected MultiDataObject.Entry createSecondaryEntry(MultiDataObject obj, FileObject secondaryFile) {
341
        {
342
            // uml project defines two project files, *.etd as the primary (data file) and *.ettm as the 
308
            // uml project defines two project files, *.etd as the primary (data file) and *.ettm as the 
343
            // secondary (schema), but the secondary file is not used for save cookie purpose,
309
            // secondary (schema), but the secondary file is not used for save cookie purpose,
344
            // in fact, the logic to update all relevant files is captured in save()
310
            // in fact, the logic to update all relevant files is captured in save()
(-)a/uml.project/src/org/netbeans/modules/uml/project/UMLProjectGenerator.java (-380 / +330 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project;
44
package org.netbeans.modules.uml.project;
46
45
47
import java.io.File;
46
import java.io.File;
Lines 76-106 Link Here
76
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
75
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
77
import org.netbeans.modules.uml.project.ui.wizards.NewUMLProjectWizardIterator;
76
import org.netbeans.modules.uml.project.ui.wizards.NewUMLProjectWizardIterator;
78
77
79
80
/**
78
/**
81
 * Create a fresh J2SEProject from scratch.
79
 * Create a fresh J2SEProject from scratch.
82
 * Currently does not permit much to be specified - feel free to 
80
 * Currently does not permit much to be specified - feel free to 
83
 * add more parameters as needed.
81
 * add more parameters as needed.
84
 * @author Mike Frisino
82
 * @author Mike Frisino
85
 */
83
 */
86
public class UMLProjectGenerator
84
public class UMLProjectGenerator {
87
{
85
88
	
86
    private UMLProjectGenerator() {
89
	private UMLProjectGenerator()
87
    }
90
	{}
88
91
	
89
    /**
92
	/**
90
     * Create a new UML project then performs reverse engineering to populatet
93
	 * Create a new UML project then performs reverse engineering to populatet
91
     * the model.
94
	 * the model.
92
     */
95
	 */
93
    public static AntProjectHelper createRoseImprtProject(File dir,
96
	public static AntProjectHelper createRoseImprtProject(File dir,
94
            String displayName,
97
		String displayName,
95
            File roseFile,
98
		File roseFile,
96
            String modelingMode)
99
        String modelingMode)
97
            throws IOException {
100
		throws IOException
98
        AntProjectHelper helper = null; //JM: 03/31 this is just a temp fix to get the build going.
101
	{
99
102
            AntProjectHelper helper = null; //JM: 03/31 this is just a temp fix to get the build going.
103
            
104
//		String mode = "PSK_IMPLEMENTATION"; // NOI18N
100
//		String mode = "PSK_IMPLEMENTATION"; // NOI18N
105
//		String strLanaguage = "java"; // NOI18N
101
//		String strLanaguage = "java"; // NOI18N
106
//		
102
//		
Lines 154-198 Link Here
154
//		}
150
//		}
155
//		
151
//		
156
//		return helper;
152
//		return helper;
157
                return helper;
153
        return helper;
158
	}
154
    }
159
	
155
160
    /**
156
    /**
161
     * Create a new UML project then performs reverse engineering to populate
157
     * Create a new UML project then performs reverse engineering to populate
162
     * the model
158
     * the model
163
     */
159
     */
164
    public static AntProjectHelper createRevEngProject(File dir,
160
    public static AntProjectHelper createRevEngProject(File dir,
165
        String displayName,
161
            String displayName,
166
        Project javaSrcProject,
162
            Project javaSrcProject,
167
        JavaSourceRootsUI.JavaSourceRootsModel rootsModel,
163
            JavaSourceRootsUI.JavaSourceRootsModel rootsModel,
168
        ArrayList<String> sourcesToRE,
164
            ArrayList<String> sourcesToRE,
169
        int umlProjectType)
165
            int umlProjectType)
170
        throws IOException
166
            throws IOException {
171
    {
172
        boolean partialRE = false;
167
        boolean partialRE = false;
173
        
168
174
        if (javaSrcProject == null) // || rootsModel == null)
169
        if (javaSrcProject == null) // || rootsModel == null)
175
        {
170
        {
176
            return createEmptyProject(dir, displayName,
171
            return createEmptyProject(dir, displayName,
177
                UMLProject.PROJECT_MODE_IMPL_STR,
172
                    UMLProject.PROJECT_MODE_IMPL_STR,
178
                javaSrcProject, new String[0],
173
                    javaSrcProject, new String[0],
179
                umlProjectType);
174
                    umlProjectType);
180
        }
175
        } else if (sourcesToRE != null && rootsModel == null) {
181
182
        else if (sourcesToRE != null && rootsModel == null)
183
        {
184
            rootsModel = JavaSourceRootsUI.createModel(javaSrcProject);
176
            rootsModel = JavaSourceRootsUI.createModel(javaSrcProject);
185
            partialRE = true;
177
            partialRE = true;
186
        }
178
        }
187
        
179
188
        ArrayList<File> reSrcsList = new ArrayList<File>();
180
        ArrayList<File> reSrcsList = new ArrayList<File>();
189
        ArrayList<String> reSrcsIdList = new ArrayList<String>();
181
        ArrayList<String> reSrcsIdList = new ArrayList<String>();
190
182
191
        for (int i=0; i < rootsModel.getRowCount(); i++)
183
        for (int i = 0; i < rootsModel.getRowCount(); i++) {
192
        {
184
            boolean includeSrcGrp =
193
            boolean includeSrcGrp = 
185
                    partialRE
194
                partialRE || 
186
                    || ((Boolean) rootsModel.getValueAt(i,
195
                ((Boolean)rootsModel.getValueAt(i, 
196
                    JavaSourceRootsUI.COL_INCLUDE_FLAG)).booleanValue();
187
                    JavaSourceRootsUI.COL_INCLUDE_FLAG)).booleanValue();
197
188
198
            // if the source group was manually selected or we have a partial
189
            // if the source group was manually selected or we have a partial
Lines 200-236 Link Here
200
            // all of the source groups added 
191
            // all of the source groups added 
201
            // I know this seems logically backwards, but it is done for speed
192
            // I know this seems logically backwards, but it is done for speed
202
            // and simplicity with the partial RE scenario
193
            // and simplicity with the partial RE scenario
203
            if (includeSrcGrp)
194
            if (includeSrcGrp) {
204
            {
195
                SourceGroup grp = (SourceGroup) rootsModel.getSourceGroup(i);
205
                SourceGroup grp = (SourceGroup)rootsModel.getSourceGroup(i);
206
196
207
                if (!partialRE)
197
                if (!partialRE) {
208
                    reSrcsList.add(FileUtil.toFile(grp.getRootFolder()));
198
                    reSrcsList.add(FileUtil.toFile(grp.getRootFolder()));
209
                
199
                }
200
210
                reSrcsIdList.add(grp.getName());
201
                reSrcsIdList.add(grp.getName());
211
            }
202
            }
212
        }
203
        }
213
204
214
        if (partialRE)
205
        if (partialRE) {
215
        {
206
            for (String source : sourcesToRE) {
216
            for (String source: sourcesToRE)
217
                reSrcsList.add(new File(source));
207
                reSrcsList.add(new File(source));
208
            }
218
        }
209
        }
219
        
210
220
        File[] reSrcs = (File[]) reSrcsList.toArray(new File[reSrcsList.size()]);
211
        File[] reSrcs = (File[]) reSrcsList.toArray(new File[reSrcsList.size()]);
221
        String[] javaSrcRootIds = (String[])reSrcsIdList.toArray(
212
        String[] javaSrcRootIds = (String[]) reSrcsIdList.toArray(
222
            new String[reSrcsIdList.size()]);
213
                new String[reSrcsIdList.size()]);
223
214
224
        AntProjectHelper retVal = createEmptyProject(dir, displayName,
215
        AntProjectHelper retVal = createEmptyProject(dir, displayName,
225
            UMLProject.PROJECT_MODE_IMPL_STR, javaSrcProject, javaSrcRootIds,
216
                UMLProject.PROJECT_MODE_IMPL_STR, javaSrcProject, javaSrcRootIds,
226
            umlProjectType);
217
                umlProjectType);
227
218
228
        FileObject dirFO = FileUtil.toFileObject(dir);
219
        FileObject dirFO = FileUtil.toFileObject(dir);
229
        Project p = ProjectManager.getDefault().findProject(dirFO);
220
        Project p = ProjectManager.getDefault().findProject(dirFO);
230
221
231
        if (p instanceof UMLProject)
222
        if (p instanceof UMLProject) {
232
        {
223
            UMLProject umlProject = (UMLProject) p;
233
            UMLProject umlProject = (UMLProject)p;
234
            umlProject.reverseEngineer(reSrcs);
224
            umlProject.reverseEngineer(reSrcs);
235
            // MCF - i think we need to save reverse engineering
225
            // MCF - i think we need to save reverse engineering
236
            // baseline model. Not sure of best place to invoke or what to
226
            // baseline model. Not sure of best place to invoke or what to
Lines 244-252 Link Here
244
234
245
        return retVal;
235
        return retVal;
246
    }
236
    }
247
	
237
248
	
249
	
250
    /**
238
    /**
251
     * Create a new empty UML project.
239
     * Create a new empty UML project.
252
     * @param dir the top-level directory (need not yet exist but if it does it must be empty)
240
     * @param dir the top-level directory (need not yet exist but if it does it must be empty)
Lines 261-268 Link Here
261
            Project javaSrcProj,
249
            Project javaSrcProj,
262
            String[] javaSrcRootIds,
250
            String[] javaSrcRootIds,
263
            int umlProjectType)
251
            int umlProjectType)
264
            throws IOException
252
            throws IOException {
265
    {
266
//        dir.mkdirs();
253
//        dir.mkdirs();
267
//        
254
//        
268
//        // XXX clumsy way to refresh, but otherwise it doesn't work for new folders
255
//        // XXX clumsy way to refresh, but otherwise it doesn't work for new folders
Lines 278-351 Link Here
278
//        fo.getFileSystem().refresh(false);
265
//        fo.getFileSystem().refresh(false);
279
//        FileObject dirFO = FileUtil.toFileObject(dir);
266
//        FileObject dirFO = FileUtil.toFileObject(dir);
280
        FileObject dirFO = FileUtil.createFolder(dir);
267
        FileObject dirFO = FileUtil.createFolder(dir);
281
        assert dirFO != null: "No such dir on disk: " + dir; // NOI18N
268
        assert dirFO != null : "No such dir on disk: " + dir; // NOI18N
282
        
269
283
        assert dirFO.isFolder() : "Not really a dir: " + dir; // NOI18N
270
        assert dirFO.isFolder() : "Not really a dir: " + dir; // NOI18N
284
        //assert dirFO.getChildren().length == 1 : "Dir must have been empty: " + dir;
271
        //assert dirFO.getChildren().length == 1 : "Dir must have been empty: " + dir;
285
        
272
286
        AntProjectHelper h = createProject(
273
        AntProjectHelper h = createProject(
287
                dirFO, displayName, modelingMode, javaSrcProj, javaSrcRootIds);
274
                dirFO, displayName, modelingMode, javaSrcProj, javaSrcRootIds);
288
        
275
289
        // This is a HACK.  Basically I can not do this when the constructor
276
        // This is a HACK.  Basically I can not do this when the constructor
290
        // of the project because the project does not know it's name until the
277
        // of the project because the project does not know it's name until the
291
        // above code.  So, I have to wait until the project knows its name
278
        // above code.  So, I have to wait until the project knows its name
292
        // before I can initialize the project.
279
        // before I can initialize the project.
293
        Project p = ProjectManager.getDefault().findProject(dirFO);
280
        Project p = ProjectManager.getDefault().findProject(dirFO);
294
        if (p instanceof UMLProject)
281
        if (p instanceof UMLProject) {
295
        {
282
            final UMLProjectHelper helper = (UMLProjectHelper) p.getLookup().lookup(UMLProjectHelper.class);
296
            final UMLProjectHelper helper = (UMLProjectHelper)p.getLookup()
283
297
            .lookup(UMLProjectHelper.class);
298
            
299
            helper.initializeProject();
284
            helper.initializeProject();
300
            ((UMLProject)p).saveProject();
285
            ((UMLProject) p).saveProject();
301
            
286
302
            // bring up new diagram dialog when creating empty project
287
            // bring up new diagram dialog when creating empty project
303
            //if "new project -> create new diagram" preference is set to yes
288
            //if "new project -> create new diagram" preference is set to yes
304
            if (umlProjectType==NewUMLProjectWizardIterator.TYPE_UML ||
289
            if (umlProjectType == NewUMLProjectWizardIterator.TYPE_UML
305
                    umlProjectType==NewUMLProjectWizardIterator.TYPE_UML_JAVA)
290
                    || umlProjectType == NewUMLProjectWizardIterator.TYPE_UML_JAVA) {
306
            {
307
                //Kris Richards - options no longer available. Default to yes, so removed
291
                //Kris Richards - options no longer available. Default to yes, so removed
308
                // condition also.
292
                // condition also.
309
//                IPreferenceManager2 prefMgr = ProductHelper.getPreferenceManager();
293
//                IPreferenceManager2 prefMgr = ProductHelper.getPreferenceManager();
310
//                String pref = prefMgr.getPreferenceValue(
294
//                String pref = prefMgr.getPreferenceValue(
311
//                        "Default|NewProject|QueryForNewDiagram"); // NOI18N
295
//                        "Default|NewProject|QueryForNewDiagram"); // NOI18N
312
296
313
                    IDiagram newDiagram =
297
                IDiagram newDiagram =
314
                            ProductHelper.getProductDiagramManager()
298
                        ProductHelper.getProductDiagramManager().newDiagramDialog(
315
                            .newDiagramDialog(
299
                        (INamespace) helper.getProject(),
316
                            (INamespace)helper.getProject(),
300
                        IDiagramKind.DK_UNKNOWN,
317
                            IDiagramKind.DK_UNKNOWN,
301
                        IDiagramKind.DK_ALL,
318
                            IDiagramKind.DK_ALL,
302
                        null);
319
                            null);
303
320
                    
304
                // Fixed issue 95782. When a diagram is 1st created, its dirty state is false.
321
                    // Fixed issue 95782. When a diagram is 1st created, its dirty state is false.
305
                // Set the dirty state to true to have the diagram autosaved.
322
                    // Set the dirty state to true to have the diagram autosaved.
306
                if (newDiagram != null) {
323
                    if (newDiagram != null )
307
                    newDiagram.setDirty(true);
324
                    {
308
                    newDiagram.save();
325
                          newDiagram.setDirty(true);
309
                }
326
                          newDiagram.save();
327
                    }
328
310
329
            }
311
            }
330
        }
312
        }
331
        
313
332
        return h;
314
        return h;
333
    }
315
    }
334
	
316
335
	
336
    // This method creates the project artifacts , project.xml, 
317
    // This method creates the project artifacts , project.xml, 
337
    // project.proprties, private.properties etc.
318
    // project.proprties, private.properties etc.
338
    private static AntProjectHelper createProject(
319
    private static AntProjectHelper createProject(
339
        FileObject dirFO, 
320
            FileObject dirFO,
340
        String name,
321
            String name,
341
        String modelingMode, 
322
            String modelingMode,
342
        Project javaSrcProj, 
323
            Project javaSrcProj,
343
        String[] javaSrcRootIds )
324
            String[] javaSrcRootIds)
344
        // String srcRoot, String testRoot, String mainClass,
325
            // String srcRoot, String testRoot, String mainClass,
345
        // String manifestFile, boolean isLibrary)
326
            // String manifestFile, boolean isLibrary)
346
        throws IOException
327
            throws IOException {
347
348
    {
349
        AntProjectHelper h = ProjectGenerator.createProject(
328
        AntProjectHelper h = ProjectGenerator.createProject(
350
                dirFO, UMLProjectType.TYPE);
329
                dirFO, UMLProjectType.TYPE);
351
330
Lines 353-366 Link Here
353
        Document doc = data.getOwnerDocument();
332
        Document doc = data.getOwnerDocument();
354
333
355
        Element nameEl = doc.createElementNS(
334
        Element nameEl = doc.createElementNS(
356
            UMLProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N
335
                UMLProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N
357
336
358
        nameEl.appendChild(doc.createTextNode(name));
337
        nameEl.appendChild(doc.createTextNode(name));
359
        data.appendChild(nameEl);
338
        data.appendChild(nameEl);
360
339
361
        Element minant = doc.createElementNS(
340
        Element minant = doc.createElementNS(
362
            UMLProjectType.PROJECT_CONFIGURATION_NAMESPACE,
341
                UMLProjectType.PROJECT_CONFIGURATION_NAMESPACE,
363
            "minimum-ant-version"); // NOI18N
342
                "minimum-ant-version"); // NOI18N
364
343
365
        minant.appendChild(doc.createTextNode("1.6")); // NOI18N
344
        minant.appendChild(doc.createTextNode("1.6")); // NOI18N
366
        data.appendChild(minant);
345
        data.appendChild(minant);
Lines 368-375 Link Here
368
        // Manage the source roots stuff here
347
        // Manage the source roots stuff here
369
348
370
        // ep - the project.properties
349
        // ep - the project.properties
371
        EditableProperties ep = 
350
        EditableProperties ep =
372
            h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
351
                h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
373
        h.putPrimaryConfigurationData(data, true);
352
        h.putPrimaryConfigurationData(data, true);
374
353
375
        // Initialize and store the project props
354
        // Initialize and store the project props
Lines 382-388 Link Here
382
//            org.netbeans.modules.uml.project.ui.common.CommonUiSupport.class,
361
//            org.netbeans.modules.uml.project.ui.common.CommonUiSupport.class,
383
//            "LBL_ProjectMode_Implementation"))) // NOI18N
362
//            "LBL_ProjectMode_Implementation"))) // NOI18N
384
//        {
363
//        {
385
            ep.setProperty(UMLProjectProperties.CODE_GEN_TEMPLATES, 
364
        ep.setProperty(UMLProjectProperties.CODE_GEN_TEMPLATES,
386
                UMLProjectProperties.DEFAULT_JAVA_TEMPLATES);
365
                UMLProjectProperties.DEFAULT_JAVA_TEMPLATES);
387
//        }
366
//        }
388
367
Lines 396-668 Link Here
396
375
397
        return h;
376
        return h;
398
    }
377
    }
399
	
378
400
	
379
    // This method is refactored as a independent method so that it
401
	// This method is refactored as a independent method so that it 
380
    //  can be reused from code generation user interface.
402
	//  can be reused from code generation user interface.
381
    public static void setJavaProjectReferences(
403
	public static void setJavaProjectReferences(
382
            AntProjectHelper h, Project javaSrcProj, String[] javaSrcRootIds) {
404
		AntProjectHelper h, Project javaSrcProj, String[] javaSrcRootIds)
383
405
	{
384
        String javaSrcProjRefVal = ""; // NOI18N
406
		
385
        EditableProperties ep = h.getProperties(
407
		String javaSrcProjRefVal = ""; // NOI18N
386
                AntProjectHelper.PROJECT_PROPERTIES_PATH);
408
		EditableProperties ep = h.getProperties(
387
        // epPriv - the private.properties
409
			AntProjectHelper.PROJECT_PROPERTIES_PATH);
388
        EditableProperties epPriv = h.getProperties(
410
		// epPriv - the private.properties
389
                AntProjectHelper.PRIVATE_PROPERTIES_PATH);
411
		EditableProperties epPriv = h.getProperties(
390
412
			AntProjectHelper.PRIVATE_PROPERTIES_PATH);
391
        if (javaSrcProj != null) {
413
		
392
            javaSrcProjRefVal = getJavaSrcProjRefVal(h, javaSrcProj);
414
		if (javaSrcProj != null )
393
        }
415
		{
394
416
			javaSrcProjRefVal = getJavaSrcProjRefVal(h, javaSrcProj);
395
        ep.setProperty(
417
		}
396
                UMLProjectProperties.REFERENCED_JAVA_PROJECT, javaSrcProjRefVal);
418
		
397
419
		ep.setProperty(
398
        ep.setProperty(
420
			UMLProjectProperties.REFERENCED_JAVA_PROJECT, javaSrcProjRefVal);
399
                UMLProjectProperties.REFERENCED_JAVA_PROJECT_SRC, javaSrcRootIds);
421
        
400
422
		ep.setProperty(
401
        h.putProperties(
423
			UMLProjectProperties.REFERENCED_JAVA_PROJECT_SRC, javaSrcRootIds);
402
                AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
424
        
403
425
		h.putProperties(
404
        // Initialize and store the private props.
426
			AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
405
        if (javaSrcProjRefVal.length() > 0) {
427
		
406
            epPriv.setProperty(javaSrcProjRefVal.substring(
428
		// Initialize and store the private props.
407
                    2, javaSrcProjRefVal.length() - 1),
429
		if (javaSrcProjRefVal.length()>0)
408
                    getJavaSrcProjectDirectory(javaSrcProj));
430
		{
409
            // it's not a nice solution,
431
			epPriv.setProperty(javaSrcProjRefVal.substring(
410
            // free form project uses this property to define source group folder name, it
432
					2, javaSrcProjRefVal.length()-1), 
411
            // it appears in uml project.properties "uml.javaproject.src=${project.dir}/src/java"
433
				getJavaSrcProjectDirectory(javaSrcProj));
412
            // which causes broken reference to project "dir" when loading uml project
434
			// it's not a nice solution,
413
            // add this to uml project private properties file to avoid broken reference
435
			// free form project uses this property to define source group folder name, it
414
            epPriv.setProperty("project.dir", getJavaSrcProjectDirectory(javaSrcProj));
436
			// it appears in uml project.properties "uml.javaproject.src=${project.dir}/src/java" 
415
        }
437
			// which causes broken reference to project "dir" when loading uml project
416
        h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, epPriv);
438
			// add this to uml project private properties file to avoid broken reference
417
439
			epPriv.setProperty("project.dir", getJavaSrcProjectDirectory(javaSrcProj));
418
        // It looks like we need to do the auxiliary config stuff
440
		}
419
        // after we have putProperties, otherwise the putProperties call
441
		h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, epPriv);
420
        // overwrites everything. Or else, we have to just getProperties again
442
		
421
443
		// It looks like we need to do the auxiliary config stuff
422
        // Should we set the uml java src property even in cases where
444
		// after we have putProperties, otherwise the putProperties call
423
        // there is no initial project?
445
		// overwrites everything. Or else, we have to just getProperties again
424
        // Note this is relying on assumption that the reference is set
446
		
425
        // by the ReferenceHelper
447
		// Should we set the uml java src property even in cases where
426
        ReferenceHelper referenceHelper = new ReferenceHelper(h,
448
		// there is no initial project?
427
                h.createAuxiliaryConfiguration(), h.getStandardPropertyEvaluator());
449
		// Note this is relying on assumption that the reference is set
428
450
		// by the ReferenceHelper
429
        if (javaSrcProj != null) {
451
		ReferenceHelper referenceHelper = new ReferenceHelper(h,
430
            String[] refStrs =
452
			h.createAuxiliaryConfiguration(), h.getStandardPropertyEvaluator());
431
                    addJavaSrcProjRef(h, referenceHelper, javaSrcProj);
453
		
432
454
		if (javaSrcProj != null )
433
            ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
455
		{
434
456
			String[] refStrs = 
435
            ep.setProperty(UMLProjectProperties.REFERENCED_JAVA_PROJECT_ARTIFACTS, refStrs);
457
				addJavaSrcProjRef(h, referenceHelper, javaSrcProj);
436
458
            
437
            h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
459
			ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
438
        }
460
            
439
    }
461
			ep.setProperty(UMLProjectProperties
440
462
                .REFERENCED_JAVA_PROJECT_ARTIFACTS, refStrs);
441
    public static String[] addJavaSrcProjRef(AntProjectHelper h,
463
            
442
            ReferenceHelper referenceHelper,
464
			h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
443
            Project javaSrcProj) {
465
		}
444
466
	}
445
467
	
446
        // If I use the ReferenceHelper, this should indirectly modify the ep and
468
	public static String[] addJavaSrcProjRef(AntProjectHelper h,
447
        // epPriv. Is there any order faults that I can incurr depending on how
469
		ReferenceHelper referenceHelper,
448
        // I structure this code? The ReferenceHelper is useful and it brings
470
		Project javaSrcProj)
449
        // some good benefits for free re: managing some of the broken refs
471
	{
450
        // opening dependent projects etc.
472
		
451
        // But it does depend on AntArtifact as the key linkage.
473
		
452
        // This should be ok, and may help if we actually want to create
474
		// If I use the ReferenceHelper, this should indirectly modify the ep and
453
        // build scripts in uml which call java build scripts.
475
		// epPriv. Is there any order faults that I can incurr depending on how
454
        // So i think it can't hurt and may help.
476
		// I structure this code? The ReferenceHelper is useful and it brings
455
477
		// some good benefits for free re: managing some of the broken refs
456
        // TODO - what is best practice to getting a handle to a ReferenceHelper
478
		// opening dependent projects etc.
457
        // there is one already in the UMLProject but for some reason most
479
		// But it does depend on AntArtifact as the key linkage.
458
        // code I've seen avoids dereferencing the Project itself. So I am not
480
		// This should be ok, and may help if we actually want to create
459
        // sure if I should be just creating a new Ref helper like i am below or
481
		// build scripts in uml which call java build scripts.
460
        // trying to get access to the one already in the UMLProject object
482
		// So i think it can't hurt and may help.
461
483
		
462
484
		// TODO - what is best practice to getting a handle to a ReferenceHelper
463
        AntArtifactProvider javaSrcArtiProv = (AntArtifactProvider) javaSrcProj.getLookup().lookup(AntArtifactProvider.class);
485
		// there is one already in the UMLProject but for some reason most
464
        ArrayList refStrs = new ArrayList();
486
		// code I've seen avoids dereferencing the Project itself. So I am not
465
487
		// sure if I should be just creating a new Ref helper like i am below or
466
        if (javaSrcArtiProv != null) {
488
		// trying to get access to the one already in the UMLProject object
467
            // there may be n uri's per ant artifact
489
		
468
            AntArtifact[] javaSrcAntArtis = javaSrcArtiProv.getBuildArtifacts();
490
		
469
491
		AntArtifactProvider javaSrcArtiProv = (AntArtifactProvider)
470
            for (int i = 0; i < javaSrcAntArtis.length; i++) {
492
		javaSrcProj.getLookup().lookup(AntArtifactProvider.class);
471
                URI[] artiURIs = javaSrcAntArtis[i].getArtifactLocations();
493
		ArrayList refStrs = new ArrayList();
472
494
		
473
                for (int j = 0; j < artiURIs.length; j++) {
495
		if (javaSrcArtiProv != null)
474
                    // AntArtifact artifact, URI location
496
		{
475
                    refStrs.add(
497
			// there may be n uri's per ant artifact
476
                            referenceHelper.addReference(
498
			AntArtifact[] javaSrcAntArtis = javaSrcArtiProv.getBuildArtifacts();
477
                            javaSrcAntArtis[i], artiURIs[j]));
499
            
478
                }
500
			for (int i=0; i<javaSrcAntArtis.length; i++)
479
501
			{
480
            }
502
				URI[] artiURIs =  javaSrcAntArtis[i].getArtifactLocations();
481
503
				
482
        }
504
				for (int j=0; j<artiURIs.length; j++)
483
        return (String[]) refStrs.toArray(new String[refStrs.size()]);
505
				{
484
    }
506
					// AntArtifact artifact, URI location
485
507
					refStrs.add(
486
    /**
508
						referenceHelper.addReference( 
487
     * Project reference ID cannot contain dot character.
509
							javaSrcAntArtis[i], artiURIs[j]));
488
     * File reference can.
510
				}
489
     */
511
				
490
    public static String getUsableReferenceID(String ID) {
512
			}
491
        return PropertyUtils.getUsablePropertyName(ID).replace('.', '_');
513
			
492
    }
514
		}
493
515
		return (String[]) refStrs.toArray(new String[refStrs.size()]);
494
    /**
516
	}
495
     * Find reference ID (e.g. something you can then pass to RawReference
517
	
496
     * as foreignProjectName) for the given property base name, prefix and path.
518
	/**
497
     * @param property project name or jar filename
519
	 * Project reference ID cannot contain dot character.
498
     * @param prefix prefix used for reference, i.e. "project." for project
520
	 * File reference can.
499
     *    reference or "file.reference." for file reference
521
	 */
500
     * @param path absolute filename the reference points to
522
	public static String getUsableReferenceID(String ID)
501
     * @return found reference ID or null
523
	{
502
     */
524
		return PropertyUtils.getUsablePropertyName(ID).replace('.', '_');
503
    public static String findReferenceID(AntProjectHelper h,
525
	}
504
            String property, String prefix, String path) {
526
	
505
        Map m = h.getStandardPropertyEvaluator().getProperties();
527
	/**
506
        Iterator it = m.keySet().iterator();
528
	 * Find reference ID (e.g. something you can then pass to RawReference
507
529
	 * as foreignProjectName) for the given property base name, prefix and path.
508
        while (it.hasNext()) {
530
	 * @param property project name or jar filename
509
            String key = (String) it.next();
531
	 * @param prefix prefix used for reference, i.e. "project." for project
510
532
	 *    reference or "file.reference." for file reference
511
            if (key.startsWith(prefix + property)) {
533
	 * @param path absolute filename the reference points to
512
                String v = h.resolvePath((String) m.get(key));
534
	 * @return found reference ID or null
513
535
	 */
514
                if (path.equals(v)) {
536
	public static String findReferenceID( AntProjectHelper h,
515
                    return key.substring(prefix.length());
537
		String property, String prefix, String path)
516
                }
538
	{
517
            }
539
		Map m = h.getStandardPropertyEvaluator().getProperties();
518
        }
540
		Iterator it = m.keySet().iterator();
519
541
        
520
        return null;
542
		while (it.hasNext())
521
    }
543
		{
522
544
			String key = (String)it.next();
523
    /**
545
            
524
     * Generate unique reference ID for the given property base name, prefix
546
			if (key.startsWith(prefix+property))
525
     * and path. See also {@link #findReferenceID(String, String, String)}.
547
			{
526
     * @param property project name or jar filename
548
				String v = h.resolvePath((String)m.get(key));
527
     * @param prefix prefix used for reference, i.e. "project." for project
549
                
528
     *    reference or "file.reference." for file reference
550
				if (path.equals(v))
529
     * @param path absolute filename the reference points to
551
				{
530
     * @return generated unique reference ID
552
					return key.substring(prefix.length());
531
     */
553
				}
532
    public static String generateUniqueID(AntProjectHelper h,
554
			}
533
            String property, String prefix, String value) {
555
		}
534
        PropertyEvaluator pev = h.getStandardPropertyEvaluator();
556
        
535
557
		return null;
536
        if (pev.getProperty(prefix + property) == null) {
558
	}
537
            return property;
559
	
538
        }
560
	
539
561
	/**
540
        int i = 1;
562
	 * Generate unique reference ID for the given property base name, prefix
541
        while (pev.getProperty(prefix + property + "-" + i) != null) // NOI18N
563
	 * and path. See also {@link #findReferenceID(String, String, String)}.
564
	 * @param property project name or jar filename
565
	 * @param prefix prefix used for reference, i.e. "project." for project
566
	 *    reference or "file.reference." for file reference
567
	 * @param path absolute filename the reference points to
568
	 * @return generated unique reference ID
569
	 */
570
	public static String generateUniqueID(AntProjectHelper h,
571
		String property, String prefix, String value)
572
	{
573
		PropertyEvaluator pev = h.getStandardPropertyEvaluator();
574
        
575
		if (pev.getProperty(prefix+property) == null)
576
		{
577
			return property;
578
		}
579
		
580
		int i = 1;
581
		while (pev.getProperty(prefix+property+"-"+i) != null) // NOI18N
582
		{
583
			i++;
584
		}
585
		
586
		return property+"-"+i; // NOI18N
587
	}
588
	
589
	public static String getJavaSrcProjRefVal(
590
        AntProjectHelper h, Project forProj)
591
	{
592
		
593
		// We want to generate something that looks like this
594
		// uml.javaproject=${project.A3}
595
		//  ${project.foreignProjectName}
596
		//ep.setProperty("dist.jar", "${dist.dir}/" +  // NOI18N
597
		// PropertyUtils.getUsablePropertyName(name) + ".jar"); // NOI18N
598
		
599
		File forProjDir = FileUtil.toFile(forProj.getProjectDirectory());
600
		assert forProjDir != null : forProj.getProjectDirectory();
601
		
602
		String projName = getUsableReferenceID(
603
			ProjectUtils.getInformation(forProj).getName());
604
		
605
		String forProjName = findReferenceID(h, projName, 
606
			"project.", forProjDir.getAbsolutePath()); // NOI18N
607
		
608
		if (forProjName == null)
609
		{
610
			forProjName = generateUniqueID(h, projName, 
611
				"project.", forProjDir.getAbsolutePath()); // NOI18N
612
		}
613
		
614
		return "${project."+forProjName+"}"; // NOI18N
615
	}
616
	
617
	private static String getJavaSrcProjectDirectory(Project forProj)
618
	{
619
		File forProjDir = FileUtil.toFile(forProj.getProjectDirectory());
620
		assert forProjDir != null : forProj.getProjectDirectory();
621
		
622
		return forProjDir.getAbsolutePath();
623
	}
624
	
625
	
626
	/* added to fix free-form project reference #6317890
627
	 * for j2se project, the reference is automatically resolved, the source
628
	 * project directory path is saved uml project private properties
629
	 */
630
	
631
	public static void fixJavaProjectReferences(
632
		AntProjectHelper h, Project javaSrcProj)
633
	{
634
		
635
		String javaSrcProjRefVal = ""; // NOI18N
636
		
637
		// epPriv - the private.properties
638
		EditableProperties epPriv = h.getProperties(
639
			AntProjectHelper.PRIVATE_PROPERTIES_PATH);
640
		
641
		if (javaSrcProj != null )
642
		{
643
			javaSrcProjRefVal = getJavaSrcProjRefVal(h, javaSrcProj);
644
		}
645
       
646
		// Initialize and store the private props.
647
		if (javaSrcProjRefVal.length()>0)
648
		{
649
			epPriv.setProperty(javaSrcProjRefVal.substring(
650
					2, javaSrcProjRefVal.length()-1), 
651
				getJavaSrcProjectDirectory(javaSrcProj));
652
		}
653
		h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, epPriv);
654
	}
655
        
656
        public static void createNewDiagram(INamespace namespace, int diagramKind, String diagramName)
657
              throws IOException
658
        {
542
        {
659
           IDiagram newDiagram = ProductHelper.getProductDiagramManager().
543
            i++;
660
                 createDiagram(diagramKind, namespace, diagramName, null);
661
           if (newDiagram != null)
662
           {
663
              newDiagram.setDirty(true);
664
              newDiagram.save();
665
           }
666
           
667
        }
544
        }
545
546
        return property + "-" + i; // NOI18N
547
    }
548
549
    public static String getJavaSrcProjRefVal(
550
            AntProjectHelper h, Project forProj) {
551
552
        // We want to generate something that looks like this
553
        // uml.javaproject=${project.A3}
554
        //  ${project.foreignProjectName}
555
        //ep.setProperty("dist.jar", "${dist.dir}/" +  // NOI18N
556
        // PropertyUtils.getUsablePropertyName(name) + ".jar"); // NOI18N
557
558
        File forProjDir = FileUtil.toFile(forProj.getProjectDirectory());
559
        assert forProjDir != null : forProj.getProjectDirectory();
560
561
        String projName = getUsableReferenceID(
562
                ProjectUtils.getInformation(forProj).getName());
563
564
        String forProjName = findReferenceID(h, projName,
565
                "project.", forProjDir.getAbsolutePath()); // NOI18N
566
567
        if (forProjName == null) {
568
            forProjName = generateUniqueID(h, projName,
569
                    "project.", forProjDir.getAbsolutePath()); // NOI18N
570
        }
571
572
        return "${project." + forProjName + "}"; // NOI18N
573
    }
574
575
    private static String getJavaSrcProjectDirectory(Project forProj) {
576
        File forProjDir = FileUtil.toFile(forProj.getProjectDirectory());
577
        assert forProjDir != null : forProj.getProjectDirectory();
578
579
        return forProjDir.getAbsolutePath();
580
    }
581
582
    /* added to fix free-form project reference #6317890
583
     * for j2se project, the reference is automatically resolved, the source
584
     * project directory path is saved uml project private properties
585
     */
586
    public static void fixJavaProjectReferences(
587
            AntProjectHelper h, Project javaSrcProj) {
588
589
        String javaSrcProjRefVal = ""; // NOI18N
590
591
        // epPriv - the private.properties
592
        EditableProperties epPriv = h.getProperties(
593
                AntProjectHelper.PRIVATE_PROPERTIES_PATH);
594
595
        if (javaSrcProj != null) {
596
            javaSrcProjRefVal = getJavaSrcProjRefVal(h, javaSrcProj);
597
        }
598
599
        // Initialize and store the private props.
600
        if (javaSrcProjRefVal.length() > 0) {
601
            epPriv.setProperty(javaSrcProjRefVal.substring(
602
                    2, javaSrcProjRefVal.length() - 1),
603
                    getJavaSrcProjectDirectory(javaSrcProj));
604
        }
605
        h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, epPriv);
606
    }
607
608
    public static void createNewDiagram(INamespace namespace, int diagramKind, String diagramName)
609
            throws IOException {
610
        IDiagram newDiagram = ProductHelper.getProductDiagramManager().
611
                createDiagram(diagramKind, namespace, diagramName, null);
612
        if (newDiagram != null) {
613
            newDiagram.setDirty(true);
614
            newDiagram.save();
615
        }
616
617
    }
668
}
618
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/UMLProjectHelper.java (-167 / +120 lines)
Lines 47-57 Link Here
47
 *
47
 *
48
 * Created on February 19, 2004, 1:12 PM
48
 * Created on February 19, 2004, 1:12 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project;
50
package org.netbeans.modules.uml.project;
52
51
53
import java.io.File;
52
import java.io.File;
54
import javax.swing.SwingUtilities;
55
import org.netbeans.api.project.SourceGroup;
53
import org.netbeans.api.project.SourceGroup;
56
import org.netbeans.spi.project.CacheDirectoryProvider;
54
import org.netbeans.spi.project.CacheDirectoryProvider;
57
import org.netbeans.spi.project.support.ant.AntProjectHelper;
55
import org.netbeans.spi.project.support.ant.AntProjectHelper;
Lines 74-324 Link Here
74
import org.netbeans.modules.uml.ui.products.ad.applicationcore.IADProduct;
72
import org.netbeans.modules.uml.ui.products.ad.applicationcore.IADProduct;
75
import org.netbeans.modules.uml.project.ui.MDREventProcessor;
73
import org.netbeans.modules.uml.project.ui.MDREventProcessor;
76
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
74
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
77
import org.openide.windows.TopComponent;
78
import org.openide.windows.WindowManager;
79
80
75
81
/**
76
/**
82
 *
77
 *
83
 * @author  treys
78
 * @author  treys
84
 */
79
 */
85
public class UMLProjectHelper
80
public class UMLProjectHelper {
86
{
81
87
    private AntProjectHelper antHelper = null;
82
    private AntProjectHelper antHelper = null;
88
    private IProject mProject = null;
83
    private IProject mProject = null;
89
    private UMLProject mNBProject = null;
84
    private UMLProject mNBProject = null;
90
    private IADProduct mADProduct = null;
85
    private IADProduct mADProduct = null;
91
    private IADApplication mApplication = null;
86
    private IADApplication mApplication = null;
92
    
87
93
    /** Creates a new instance of UMLProjectHelper */
88
    /** Creates a new instance of UMLProjectHelper */
94
    public UMLProjectHelper(AntProjectHelper aggregate, UMLProject project)
89
    public UMLProjectHelper(AntProjectHelper aggregate, UMLProject project) {
95
    {
96
        antHelper = aggregate;
90
        antHelper = aggregate;
97
        mNBProject = project;
91
        mNBProject = project;
98
    }
92
    }
99
    
93
100
    public AntProjectHelper getAntProjectHelper()
94
    public AntProjectHelper getAntProjectHelper() {
101
    {
102
        return antHelper;
95
        return antHelper;
103
    }
96
    }
104
    
97
105
    public EditableProperties getProperties(String str)
98
    public EditableProperties getProperties(String str) {
106
    {
107
        EditableProperties retValue = antHelper.getProperties(str);
99
        EditableProperties retValue = antHelper.getProperties(str);
108
        return retValue;
100
        return retValue;
109
    }
101
    }
110
    
102
111
    public int hashCode()
103
    public int hashCode() {
112
    {
113
        int retValue = antHelper.hashCode();
104
        int retValue = antHelper.hashCode();
114
        return retValue;
105
        return retValue;
115
    }
106
    }
116
    
107
117
    public FileObject getProjectDirectory()
108
    public FileObject getProjectDirectory() {
118
    {
109
        FileObject retValue = antHelper.getProjectDirectory();
119
        FileObject retValue= antHelper.getProjectDirectory();
120
        return retValue;
110
        return retValue;
121
    }
111
    }
122
    
112
123
    public Element getPrimaryConfigurationData(boolean param)
113
    public Element getPrimaryConfigurationData(boolean param) {
124
    {
125
        Element retValue = antHelper.getPrimaryConfigurationData(param);
114
        Element retValue = antHelper.getPrimaryConfigurationData(param);
126
        return retValue;
115
        return retValue;
127
    }
116
    }
128
    
117
129
    public String toString()
118
    public String toString() {
130
    {
131
        String retValue = antHelper.toString();
119
        String retValue = antHelper.toString();
132
        return retValue;
120
        return retValue;
133
    }
121
    }
134
    
122
135
    public void addAntProjectListener(AntProjectListener antProjectListener)
123
    public void addAntProjectListener(AntProjectListener antProjectListener) {
136
    {
137
        antHelper.addAntProjectListener(antProjectListener);
124
        antHelper.addAntProjectListener(antProjectListener);
138
    }
125
    }
139
    
126
140
    public void putPrimaryConfigurationData(Element element, boolean param)
127
    public void putPrimaryConfigurationData(Element element, boolean param)
141
        throws java.lang.IllegalArgumentException
128
            throws java.lang.IllegalArgumentException {
142
    {
143
        antHelper.putPrimaryConfigurationData(element, param);
129
        antHelper.putPrimaryConfigurationData(element, param);
144
    }
130
    }
145
    
131
146
    public void putProperties(String str, EditableProperties editableProperties)
132
    public void putProperties(String str, EditableProperties editableProperties) {
147
    {
148
        antHelper.putProperties(str, editableProperties);
133
        antHelper.putProperties(str, editableProperties);
149
    }
134
    }
150
    
135
151
    public void removeAntProjectListener(AntProjectListener antProjectListener)
136
    public void removeAntProjectListener(AntProjectListener antProjectListener) {
152
    {
153
        antHelper.removeAntProjectListener(antProjectListener);
137
        antHelper.removeAntProjectListener(antProjectListener);
154
    }
138
    }
155
    
139
156
    public PropertyEvaluator getStandardPropertyEvaluator()
140
    public PropertyEvaluator getStandardPropertyEvaluator() {
157
    {
158
        return antHelper.getStandardPropertyEvaluator();
141
        return antHelper.getStandardPropertyEvaluator();
159
    }
142
    }
160
    
143
161
    public CacheDirectoryProvider createCacheDirectoryProvider()
144
    public CacheDirectoryProvider createCacheDirectoryProvider() {
162
    {
163
        return antHelper.createCacheDirectoryProvider();
145
        return antHelper.createCacheDirectoryProvider();
164
    }
146
    }
165
    
147
166
    public String resolvePath(String str)
148
    public String resolvePath(String str) {
167
    {
168
        String retValue;
149
        String retValue;
169
        
150
170
        retValue = antHelper.resolvePath(str);
151
        retValue = antHelper.resolvePath(str);
171
        return retValue;
152
        return retValue;
172
    }
153
    }
173
    
154
174
    public boolean equals(Object obj)
155
    public boolean equals(Object obj) {
175
    {
176
        boolean retValue;
156
        boolean retValue;
177
        
157
178
        retValue = antHelper.equals(obj);
158
        retValue = antHelper.equals(obj);
179
        return retValue;
159
        return retValue;
180
    }
160
    }
181
    
161
182
    public FileObject resolveFileObject(String str)
162
    public FileObject resolveFileObject(String str) {
183
    {
163
        FileObject retValue = antHelper.resolveFileObject(str);
184
        FileObject retValue  = antHelper.resolveFileObject(str);
185
        return retValue;
164
        return retValue;
186
    }
165
    }
187
    
166
188
    public File resolveFile(String str)
167
    public File resolveFile(String str) {
189
    {
190
        File retValue;
168
        File retValue;
191
        
169
192
        retValue = antHelper.resolveFile(str);
170
        retValue = antHelper.resolveFile(str);
193
        return retValue;
171
        return retValue;
194
    }
172
    }
195
    
173
196
    public void setProject(IProject project)
174
    public void setProject(IProject project) {
197
    {
198
        mProject = project;
175
        mProject = project;
199
    }
176
    }
200
    
177
201
    public IProject getProject()
178
    public IProject getProject() {
202
    {
179
        if (mProject == null) {
203
        if (mProject == null)
204
            initializeProject();
180
            initializeProject();
205
        
181
        }
182
206
        return mProject;
183
        return mProject;
207
    }
184
    }
208
    
185
209
    public File getProjectFile()
186
    public File getProjectFile() {
210
    {
211
        File retVal = null;
187
        File retVal = null;
212
        FileObject fo = getProjectDirectory();
188
        FileObject fo = getProjectDirectory();
213
        
189
214
        if (fo != null)
190
        if (fo != null) {
215
        {
216
            //retVal = new File(getProjectDirectory().getPath());
191
            //retVal = new File(getProjectDirectory().getPath());
217
            retVal = org.openide.filesystems.FileUtil.toFile(fo);
192
            retVal = org.openide.filesystems.FileUtil.toFile(fo);
218
        }
193
        }
219
        
194
220
        return retVal;
195
        return retVal;
221
    }
196
    }
222
    
197
223
    protected String getDisplayName()
198
    protected String getDisplayName() {
224
    {
225
        return mNBProject.getName();
199
        return mNBProject.getName();
226
    }
200
    }
227
    
201
228
    
202
    protected void initializeProject() {
229
    protected void initializeProject()
203
        if (mProject != null) {
230
    {
231
        if (mProject != null)
232
            return;
204
            return;
233
        
205
        }
234
	UMLProjectModule.checkInit();
206
207
        UMLProjectModule.checkInit();
235
208
236
        mADProduct = getProduct();
209
        mADProduct = getProduct();
237
        
210
238
        if (mADProduct != null)
211
        if (mADProduct != null) {
239
        {
240
            IApplication app = mADProduct.initialize2(false);
212
            IApplication app = mADProduct.initialize2(false);
241
            mApplication = (IADApplication)app;
213
            mApplication = (IADApplication) app;
242
        }
214
        }
243
        
215
244
        if (mApplication != null)
216
        if (mApplication != null) {
245
        {
246
            String projName = getDisplayName();
217
            String projName = getDisplayName();
247
            
218
248
            File projectFile =
219
            File projectFile =
249
                new File(getProjectFile(), GeneratedFilesHelper.BUILD_XML_PATH);
220
                    new File(getProjectFile(), GeneratedFilesHelper.BUILD_XML_PATH);
250
            
221
251
//         String relPath ="nbproject" +
222
//         String relPath ="nbproject" +
252
//             File.separatorChar + projName + ".etd"; // NOI18N
223
//             File.separatorChar + projName + ".etd"; // NOI18N
253
            String relPath = projName + ".etd"; // NOI18N
224
            String relPath = projName + ".etd"; // NOI18N
254
            
225
255
            File projectFilename =  new File(projectFile.getParentFile(), relPath);
226
            File projectFilename = new File(projectFile.getParentFile(), relPath);
256
            
227
257
            mProject = null;
228
            mProject = null;
258
            // System.out.println("Going to open project " + relPath); // NOI18N
229
            // System.out.println("Going to open project " + relPath); // NOI18N
259
            
230
260
            if (projectFilename.exists() == true)
231
            if (projectFilename.exists() == true) {
261
            {
262
                mProject = mApplication.openProject(projectFilename.getAbsolutePath());
232
                mProject = mApplication.openProject(projectFilename.getAbsolutePath());
263
//                mProject.setDirty(false);
233
//                mProject.setDirty(false);
264
            }
234
            }
265
            
235
266
            if (mProject == null)
236
            if (mProject == null) {
267
            {
268
                mProject = mApplication.createProject();
237
                mProject = mApplication.createProject();
269
                
238
270
                EditableProperties ep =
239
                EditableProperties ep =
271
                    getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
240
                        getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
272
                
241
273
                String mode = (String)ep.getProperty(UMLProjectProperties.MODELING_MODE);
242
                String mode = (String) ep.getProperty(UMLProjectProperties.MODELING_MODE);
274
                mProject.setMode(mode);
243
                mProject.setMode(mode);
275
                mProject.setName(projName);
244
                mProject.setName(projName);
276
                mProject.setFileName(projectFilename.getAbsolutePath());
245
                mProject.setFileName(projectFilename.getAbsolutePath());
277
            }
246
            }
278
            
247
279
            AssociatedSourceProvider provider =
248
            AssociatedSourceProvider provider =
280
                (AssociatedSourceProvider)mNBProject.getLookup()
249
                    (AssociatedSourceProvider) mNBProject.getLookup().lookup(AssociatedSourceProvider.class);
281
                .lookup(AssociatedSourceProvider.class);
250
282
            
283
            mProject.setAssociatedProjectSourceRoots(provider);
251
            mProject.setAssociatedProjectSourceRoots(provider);
284
        }
252
        }
285
    }
253
    }
286
    
254
287
    protected IADProduct getProduct()
255
    protected IADProduct getProduct() {
288
    {
289
        IADProduct retVal = null;
256
        IADProduct retVal = null;
290
        
257
291
        ICoreProductManager productManager = CoreProductManager.instance();
258
        ICoreProductManager productManager = CoreProductManager.instance();
292
        //ETList<IProductDescriptor> pDesc = productManager.getProducts();
259
        //ETList<IProductDescriptor> pDesc = productManager.getProducts();
293
        ETList pDesc = productManager.getProducts();
260
        ETList pDesc = productManager.getProducts();
294
        
261
295
        // Make sure that another project has not already created a product
262
        // Make sure that another project has not already created a product
296
        if ((pDesc == null) || (pDesc.size() == 0))
263
        if ((pDesc == null) || (pDesc.size() == 0)) {
297
        {
298
            // Create a new ADProduct
264
            // Create a new ADProduct
299
            retVal = new ADProduct();
265
            retVal = new ADProduct();
300
            productManager.setCoreProduct(retVal);
266
            productManager.setCoreProduct(retVal);
267
        } else {
268
            IProductDescriptor descriptor = (IProductDescriptor) pDesc.get(0);
269
270
            if (descriptor.getCoreProduct() instanceof IADProduct) {
271
                retVal = (IADProduct) descriptor.getCoreProduct();
272
            }
301
        }
273
        }
302
        
274
303
        else
304
        {
305
            IProductDescriptor descriptor = (IProductDescriptor)pDesc.get(0);
306
            
307
            if(descriptor.getCoreProduct() instanceof IADProduct)
308
                retVal = (IADProduct)descriptor.getCoreProduct();
309
        }
310
        
311
        return retVal;
275
        return retVal;
312
    }
276
    }
313
    
277
314
    /**
278
    /**
315
     * @param b
279
     * @param b
316
     */
280
     */
317
    public void closeProject(boolean save)
281
    public void closeProject(boolean save) {
318
    {
319
        // The project will be saved if the user told the save dialog to save
282
        // The project will be saved if the user told the save dialog to save
320
        // the project.
283
        // the project.
321
        
284
322
        // cvc - CR 6269224
285
        // cvc - CR 6269224
323
        // this was disabled. reenabled so that open diagram drawing areas will
286
        // this was disabled. reenabled so that open diagram drawing areas will
324
        // close when its Project is closed
287
        // close when its Project is closed
Lines 327-384 Link Here
327
//        TopComponent tc = WindowManager.getDefault().findTopComponent("documentation");
290
//        TopComponent tc = WindowManager.getDefault().findTopComponent("documentation");
328
//        if (tc != null)
291
//        if (tc != null)
329
//            tc.canClose();
292
//            tc.canClose();
330
        
293
331
        if (mProject == null)
294
        if (mProject == null) {
332
            return;
295
            return;
333
        
296
        }
297
334
        mApplication.closeProject(mProject, save);
298
        mApplication.closeProject(mProject, save);
335
        mNBProject.removeUMLProjectMetaListener();
299
        mNBProject.removeUMLProjectMetaListener();
336
        mProject = null;
300
        mProject = null;
337
    }
301
    }
338
    
302
339
    
340
    // MCF TODO - I am adding some stuff here that is copied from the
303
    // MCF TODO - I am adding some stuff here that is copied from the
341
    // UpdateHelper. I am not sure if we need a full blown UpdateHelper or
304
    // UpdateHelper. I am not sure if we need a full blown UpdateHelper or
342
    // whether we integrate what we need into this class.
305
    // whether we integrate what we need into this class.
343
    // Review as we go.
306
    // Review as we go.
344
    
307
    public void saveProject() {
345
    
308
        if (mApplication != null) {
346
    public void saveProject()
347
    {
348
        if (mApplication != null) 
349
        {
350
            mApplication.saveProject(mProject);
309
            mApplication.saveProject(mProject);
351
        }
310
        }
352
    }
311
    }
353
    
312
354
    public void scanSourceGroups()
313
    public void scanSourceGroups() {
355
    {
356
        scanSourceGroups(mNBProject);
314
        scanSourceGroups(mNBProject);
357
    }
315
    }
358
    
316
359
    public static void scanSourceGroups(UMLProject currentUMLProj)
317
    public static void scanSourceGroups(UMLProject currentUMLProj) {
360
    {
318
        if (currentUMLProj != null) {
361
        if (currentUMLProj!=null)
362
        {
363
            UMLProjectProperties props = currentUMLProj.getUMLProjectProperties();
319
            UMLProjectProperties props = currentUMLProj.getUMLProjectProperties();
364
            props.init();
320
            props.init();
365
            
321
366
            Lookup l = currentUMLProj.getLookup();
322
            Lookup l = currentUMLProj.getLookup();
367
            final AssociatedSourceProvider asp =
323
            final AssociatedSourceProvider asp =
368
                (AssociatedSourceProvider)l.lookup(AssociatedSourceProvider.class);
324
                    (AssociatedSourceProvider) l.lookup(AssociatedSourceProvider.class);
369
            
325
370
            if (asp != null)
326
            if (asp != null) {
371
            {
372
                final SourceGroup[] grp = asp.getSourceGroups();
327
                final SourceGroup[] grp = asp.getSourceGroups();
373
                RequestProcessor rp = new RequestProcessor
328
                RequestProcessor rp = new RequestProcessor("Post Scan Request Processor"); // NOI18N
374
                    ("Post Scan Request Processor"); // NOI18N
329
375
                
330
                rp.post(new Runnable() {
376
                rp.post(new Runnable()
331
377
                {
332
                    public void run() {
378
                    public void run()
379
                    {
380
//                        ((JMManager)JMManager.getManager()).waitScanFinished();
333
//                        ((JMManager)JMManager.getManager()).waitScanFinished();
381
                        MDREventProcessor.getInstance().fireChanged(null,grp);
334
                        MDREventProcessor.getInstance().fireChanged(null, grp);
382
                    }
335
                    }
383
                });
336
                });
384
            }
337
            }
(-)a/uml.project/src/org/netbeans/modules/uml/project/UMLProjectMetadataListener.java (-27 / +20 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on April 30, 2005, 7:51 AM
48
 * Created on April 30, 2005, 7:51 AM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project;
50
package org.netbeans.modules.uml.project;
52
51
53
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
52
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
Lines 60-96 Link Here
60
 *
59
 *
61
 * @author Administrator
60
 * @author Administrator
62
 */
61
 */
63
public class UMLProjectMetadataListener implements PropertyChangeListener,AntProjectListener
62
public class UMLProjectMetadataListener implements PropertyChangeListener, AntProjectListener {
64
{
65
   private UMLProject mAssociatedProject = null;
66
   
67
   /** Creates a new instance of UMLProjectMetadataListener */
68
   public UMLProjectMetadataListener(UMLProject project)
69
   {
70
      mAssociatedProject = project;
71
   }
72
63
73
   /**
64
    private UMLProject mAssociatedProject = null;
74
    * React to changes originating from customizer modification to project metadata
65
75
    */
66
    /** Creates a new instance of UMLProjectMetadataListener */
76
    public void propertyChange(PropertyChangeEvent evt)
67
    public UMLProjectMetadataListener(UMLProject project) {
77
    {
68
        mAssociatedProject = project;
78
       if(UMLProjectProperties.MODELING_MODE.equals(evt.getPropertyName()) == true)
79
       {
80
          mAssociatedProject.setProjectMode((String)evt.getNewValue());
81
       }
82
    }
69
    }
83
    
70
84
    /**
71
    /**
85
     * React to changes originating from customizer modification to project metadata
72
     * React to changes originating from customizer modification to project metadata
86
     */
73
     */
87
    public void configurationXmlChanged(AntProjectEvent ev)
74
    public void propertyChange(PropertyChangeEvent evt) {
88
    {
75
        if (UMLProjectProperties.MODELING_MODE.equals(evt.getPropertyName()) == true) {
76
            mAssociatedProject.setProjectMode((String) evt.getNewValue());
77
        }
89
    }
78
    }
90
    
79
91
    public void propertiesChanged(AntProjectEvent ev)
80
    /**
92
    {
81
     * React to changes originating from customizer modification to project metadata
93
       //Handled by propertyChange
82
     */
83
    public void configurationXmlChanged(AntProjectEvent ev) {
94
    }
84
    }
95
   
85
86
    public void propertiesChanged(AntProjectEvent ev) {
87
        //Handled by propertyChange
88
    }
96
}
89
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/UMLProjectModule.java (-118 / +83 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on March 30, 2005, 3:10 PM
48
 * Created on March 30, 2005, 3:10 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project;
50
package org.netbeans.modules.uml.project;
52
51
53
import javax.swing.SwingUtilities;
52
import javax.swing.SwingUtilities;
Lines 77-264 Link Here
77
 *
76
 *
78
 * @author Trey Spiva
77
 * @author Trey Spiva
79
 */
78
 */
80
public class UMLProjectModule extends ModuleInstall
79
public class UMLProjectModule extends ModuleInstall {
81
{
80
82
    private static ADProjectTreeEngine mEngine = null;
81
    private static ADProjectTreeEngine mEngine = null;
83
//	private static NetBeansUMLProjectTreeModel mModel = new NetBeansUMLProjectTreeModel();
82
//	private static NetBeansUMLProjectTreeModel mModel = new NetBeansUMLProjectTreeModel();
84
    private static NetBeansUMLProjectTreeModel mModel = null;
83
    private static NetBeansUMLProjectTreeModel mModel = null;
85
    
84
86
    /** Creates a new instance of UMLProjectModule */
85
    /** Creates a new instance of UMLProjectModule */
87
    public UMLProjectModule()
86
    public UMLProjectModule() {
88
    {
89
        
90
    }
87
    }
91
        
92
88
93
    private static void lightInit() 
89
    private static void lightInit() {
94
    {
90
        if (!lightInitialized) {
95
	if ( ! lightInitialized ) 
91
            synchronized (initLock) {
96
	{ 
92
                if (!lightInitialized) {
97
	    synchronized(initLock) 
93
                    final IADProduct product = getProduct();
98
	    {
94
                    mModel = new NetBeansUMLProjectTreeModel();
99
		if ( ! lightInitialized ) 
100
		{ 
101
		    final IADProduct product = getProduct();
102
		    mModel = new NetBeansUMLProjectTreeModel();
103
        
104
		    if(product != null)
105
		    {
106
95
107
                        IProductDiagramManager diagManager = (IProductDiagramManager) Lookup.getDefault()
96
                    if (product != null) {
108
                            .lookup(IProductDiagramManager.class);
97
98
                        IProductDiagramManager diagManager = (IProductDiagramManager) Lookup.getDefault().lookup(IProductDiagramManager.class);
109
                        product.setDiagramManager(diagManager);
99
                        product.setDiagramManager(diagManager);
110
100
111
			{
101
                        {
112
                
102
113
			    DispatchHelper helper = new DispatchHelper();
103
                            DispatchHelper helper = new DispatchHelper();
114
			}
104
                        }
115
            
105
116
			// Put the user interface proxy
106
                        // Put the user interface proxy
117
			product.setProxyUserInterface(new UMLUserInterface());
107
                        product.setProxyUserInterface(new UMLUserInterface());
118
			product.setProjectManager(new UMLProductProjectManager());
108
                        product.setProjectManager(new UMLProductProjectManager());
119
                        product.setProjectTreeModel(mModel);
109
                        product.setProjectTreeModel(mModel);
120
		    }
110
                    } else {
121
		    else
111
                        DispatchHelper helper = new DispatchHelper();
122
		    {
112
                    }
123
			DispatchHelper helper = new DispatchHelper();
113
                    lightInitialized = true;
124
		    }      
114
                }
125
		    lightInitialized = true;
115
            }
126
		}
116
        }
127
	    }
128
	}
129
    }
117
    }
130
131
    private static Object initLock = new Object();
118
    private static Object initLock = new Object();
132
    private static boolean lightInitialized = false;
119
    private static boolean lightInitialized = false;
133
    private static boolean initialized = false;
120
    private static boolean initialized = false;
134
 
121
135
    public static void checkInit() 
122
    public static void checkInit() {
136
    {
123
        if (!initialized) {
137
	if ( ! initialized ) 
124
            synchronized (initLock) {
138
	{ 
125
                if (!initialized) {
139
	    synchronized(initLock) 
126
                    lightInit();
140
	    {
141
		if ( ! initialized ) 
142
		{ 
143
		    lightInit();
144
                    org.netbeans.modules.uml.UMLCoreModule.checkInit();
127
                    org.netbeans.modules.uml.UMLCoreModule.checkInit();
145
		    IADProduct product = getProduct();
128
                    IADProduct product = getProduct();
146
		    IApplication app = product.initialize2(false);
129
                    IApplication app = product.initialize2(false);
147
130
148
		    mEngine = new ADProjectTreeEngine();
131
                    mEngine = new ADProjectTreeEngine();
149
		    mEngine.initialize(mModel);
132
                    mEngine.initialize(mModel);
150
133
151
		    initialized = true;
134
                    initialized = true;
152
		}
135
                }
153
	    }
136
            }
154
	}
137
        }
155
    }
138
    }
156
    
139
157
    /**
140
    /**
158
     * Makes sure that all of the UML projects are saved.
141
     * Makes sure that all of the UML projects are saved.
159
     */
142
     */
160
    public boolean closing()
143
    public boolean closing() {
161
    {
162
        return true;
144
        return true;
163
        // if project is modified user will be prompted, no need to save the project
145
        // if project is modified user will be prompted, no need to save the project
164
        // automatically
146
        // automatically
165
//      boolean retVal = SaveProjectsDialog.saveProjects();
147
//      boolean retVal = SaveProjectsDialog.saveProjects();
166
        
148
167
    }
149
    }
168
    
150
169
    
151
    public void uninstalled() {
170
    public void uninstalled()
171
    {
172
        final Project[] projects = ProjectUtil.getOpenUMLProjects();
152
        final Project[] projects = ProjectUtil.getOpenUMLProjects();
173
        
153
174
        // 108119, save changes before uninstalling modules
154
        // 108119, save changes before uninstalling modules
175
        for (Project p: projects)
155
        for (Project p : projects) {
176
        {
156
            UMLProjectHelper h = (UMLProjectHelper) p.getLookup().lookup(UMLProjectHelper.class);
177
            UMLProjectHelper h = (UMLProjectHelper)p.getLookup().lookup(UMLProjectHelper.class);
157
            if (h != null) {
178
            if (h != null)
179
            {
180
                h.closeProject(true);
158
                h.closeProject(true);
181
            }
159
            }
182
        }
160
        }
183
        
161
184
        SwingUtilities.invokeLater( new Runnable()
162
        SwingUtilities.invokeLater(new Runnable() {
185
        {
163
186
            public void run()
164
            public void run() {
187
            {
165
                for (Project p : projects) {
188
                for (Project p: projects)
166
                    UMLProjectHelper h = (UMLProjectHelper) p.getLookup().lookup(UMLProjectHelper.class);
189
                {
167
                    if (h != null) {
190
                    UMLProjectHelper h = (UMLProjectHelper)p.getLookup().lookup(UMLProjectHelper.class);
191
                    if (h != null)
192
                    {
193
                        IProductDiagramManager pDiaMgr =
168
                        IProductDiagramManager pDiaMgr =
194
                                ProductHelper.getProductDiagramManager();
169
                                ProductHelper.getProductDiagramManager();
195
                        pDiaMgr.closeAllDiagrams();
170
                        pDiaMgr.closeAllDiagrams();
196
                    }
171
                    }
197
                }
172
                }
198
                
173
199
                TopComponent tc = WindowManager.getDefault().findTopComponent("designpattern");
174
                TopComponent tc = WindowManager.getDefault().findTopComponent("designpattern");
200
                if (tc != null)
175
                if (tc != null) {
201
                    tc.close();
176
                    tc.close();
177
                }
202
                tc = WindowManager.getDefault().findTopComponent("documentation");
178
                tc = WindowManager.getDefault().findTopComponent("documentation");
203
                if (tc != null)
179
                if (tc != null) {
204
                    tc.close();
180
                    tc.close();
205
                
181
                }
182
206
            }
183
            }
207
        });
184
        });
208
        
185
209
        OpenProjects.getDefault().close(projects);
186
        OpenProjects.getDefault().close(projects);
210
    }
187
    }
211
188
212
    
213
    ////////////////////////////////////////////////////////////////////////////
189
    ////////////////////////////////////////////////////////////////////////////
214
    // Data Access Methods
190
    // Data Access Methods
215
    
191
    public static ADProjectTreeEngine getProjectTreeEngine() {
216
    public static ADProjectTreeEngine getProjectTreeEngine()
192
        checkInit();
217
    {
218
	checkInit();
219
        return mEngine;
193
        return mEngine;
220
    }
194
    }
221
    
195
222
    public static NetBeansUMLProjectTreeModel getProjectTreeModel()
196
    public static NetBeansUMLProjectTreeModel getProjectTreeModel() {
223
    {
197
        checkInit();
224
	checkInit();
225
        return mModel;
198
        return mModel;
226
    }
199
    }
227
    
200
228
    public static void addModelNode(UMLModelRootNode node, UMLProject project)
201
    public static void addModelNode(UMLModelRootNode node, UMLProject project) {
229
    {
202
        checkInit();
230
	checkInit();
231
        mModel.addModelRootNode(node, project);
203
        mModel.addModelRootNode(node, project);
232
    }
204
    }
233
    
205
234
    
235
    //////////////////////////////////////////////////////////////////
206
    //////////////////////////////////////////////////////////////////
236
    // Helper Methods
207
    // Helper Methods
237
    
208
    protected static IADProduct getProduct() {
238
    protected static IADProduct getProduct()
239
    {
240
        IADProduct retVal = null;
209
        IADProduct retVal = null;
241
        
210
242
        ICoreProductManager productManager = CoreProductManager.instance();
211
        ICoreProductManager productManager = CoreProductManager.instance();
243
        ETList<IProductDescriptor> pDesc = productManager.getProducts();
212
        ETList<IProductDescriptor> pDesc = productManager.getProducts();
244
        //ETList pDesc = productManager.getProducts();
213
        //ETList pDesc = productManager.getProducts();
245
        
214
246
        // Make sure that another project has not already created a product
215
        // Make sure that another project has not already created a product
247
        if((pDesc == null) || (pDesc.size() == 0))
216
        if ((pDesc == null) || (pDesc.size() == 0)) {
248
        {
249
            // Create a new ADProduct
217
            // Create a new ADProduct
250
            retVal = new ADProduct();
218
            retVal = new ADProduct();
251
            productManager.setCoreProduct(retVal);
219
            productManager.setCoreProduct(retVal);
252
        }
220
        } else {
253
        else
221
            IProductDescriptor descriptor = (IProductDescriptor) pDesc.get(0);
254
        {
222
            if (descriptor.getCoreProduct() instanceof IADProduct) {
255
            IProductDescriptor descriptor = (IProductDescriptor)pDesc.get(0);
223
                retVal = (IADProduct) descriptor.getCoreProduct();
256
            if(descriptor.getCoreProduct() instanceof IADProduct)
257
            {
258
                retVal = (IADProduct)descriptor.getCoreProduct();
259
            }
224
            }
260
        }
225
        }
261
        
226
262
        return retVal;
227
        return retVal;
263
    }
228
    }
264
}
229
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/UMLProjectType.java (-27 / +17 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project;
44
package org.netbeans.modules.uml.project;
46
45
47
import java.io.IOException;
46
import java.io.IOException;
Lines 53-61 Link Here
53
 * Factory for simple J2SE projects.
52
 * Factory for simple J2SE projects.
54
 * @author Jesse Glick
53
 * @author Jesse Glick
55
 */
54
 */
56
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.project.support.ant.AntBasedProjectType.class)
55
@org.openide.util.lookup.ServiceProvider(service = org.netbeans.spi.project.support.ant.AntBasedProjectType.class)
57
public final class UMLProjectType implements AntBasedProjectType
56
public final class UMLProjectType implements AntBasedProjectType {
58
{
59
57
60
    //public static final String TYPE = "org.netbeans.modules.uml.project";
58
    //public static final String TYPE = "org.netbeans.modules.uml.project";
61
    public static final String TYPE = "com.sun.tools.ide.uml.project";
59
    public static final String TYPE = "com.sun.tools.ide.uml.project";
Lines 63-102 Link Here
63
    public static final String PROJECT_CONFIGURATION_NAMESPACE = "http://www.sun.com/ns/uml-project/1";
61
    public static final String PROJECT_CONFIGURATION_NAMESPACE = "http://www.sun.com/ns/uml-project/1";
64
    private static final String PRIVATE_CONFIGURATION_NAME = "data";
62
    private static final String PRIVATE_CONFIGURATION_NAME = "data";
65
    private static final String PRIVATE_CONFIGURATION_NAMESPACE = "http://www.sun.com/ns/uml-project-private/1";
63
    private static final String PRIVATE_CONFIGURATION_NAMESPACE = "http://www.sun.com/ns/uml-project-private/1";
66
    
64
67
    /** Do nothing, just a service. */
65
    /** Do nothing, just a service. */
68
    public UMLProjectType()
66
    public UMLProjectType() {
69
    {}
67
    }
70
    
68
71
    public String getType()
69
    public String getType() {
72
    {
73
        return TYPE;
70
        return TYPE;
74
    }
71
    }
75
    
72
76
    public Project createProject(AntProjectHelper helper) throws IOException
73
    public Project createProject(AntProjectHelper helper) throws IOException {
77
    {
78
        Project retVal = null;
74
        Project retVal = null;
79
        
75
80
        try
76
        try {
81
        {
82
            retVal = new UMLProject(helper);
77
            retVal = new UMLProject(helper);
83
        }
78
        } catch (Throwable t) {
84
        catch(Throwable t)
85
        {
86
            t.printStackTrace();
79
            t.printStackTrace();
87
        }
80
        }
88
        
81
89
        return retVal;
82
        return retVal;
90
    }
83
    }
91
    
84
92
    public String getPrimaryConfigurationDataElementName(boolean shared)
85
    public String getPrimaryConfigurationDataElementName(boolean shared) {
93
    {
94
        return shared ? PROJECT_CONFIGURATION_NAME : PRIVATE_CONFIGURATION_NAME;
86
        return shared ? PROJECT_CONFIGURATION_NAME : PRIVATE_CONFIGURATION_NAME;
95
    }
87
    }
96
    
88
97
    public String getPrimaryConfigurationDataElementNamespace(boolean shared)
89
    public String getPrimaryConfigurationDataElementNamespace(boolean shared) {
98
    {
99
        return shared ? PROJECT_CONFIGURATION_NAMESPACE : PRIVATE_CONFIGURATION_NAMESPACE;
90
        return shared ? PROJECT_CONFIGURATION_NAMESPACE : PRIVATE_CONFIGURATION_NAMESPACE;
100
    }
91
    }
101
    
102
}
92
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/IMDRListener.java (-4 / +3 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
/**
44
/**
46
 *
45
 *
47
 */
46
 */
Lines 53-61 Link Here
53
 * @author alagud
52
 * @author alagud
54
 *
53
 *
55
 */
54
 */
56
public interface IMDRListener
55
public interface IMDRListener {
57
{
56
58
    public void registerJMI(SourceGroup[] grp);
57
    public void registerJMI(SourceGroup[] grp);
58
59
    public void removeJMI(SourceGroup[] grp);
59
    public void removeJMI(SourceGroup[] grp);
60
61
}
60
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/ITreeItemExpandContext.java (-4 / +3 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui;
44
package org.netbeans.modules.uml.project.ui;
46
45
47
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem;
46
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem;
Lines 50-56 Link Here
50
 *
49
 *
51
 * @author Trey Spiva
50
 * @author Trey Spiva
52
 */
51
 */
53
public interface ITreeItemExpandContext
52
public interface ITreeItemExpandContext {
54
{
53
55
   public void itemAdded(ITreeItem item);
54
    public void itemAdded(ITreeItem item);
56
}
55
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/MDREventProcessor.java (-48 / +25 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
/**
44
/**
46
 *
45
 *
47
 */
46
 */
Lines 59-142 Link Here
59
import org.netbeans.modules.uml.core.support.umlsupport.Log;
58
import org.netbeans.modules.uml.core.support.umlsupport.Log;
60
import org.openide.filesystems.FileUtil;
59
import org.openide.filesystems.FileUtil;
61
60
62
63
64
/**
61
/**
65
 * @author alagud
62
 * @author alagud
66
 *
63
 *
67
 */
64
 */
68
public class MDREventProcessor
65
public class MDREventProcessor {
69
{
66
70
    Vector<IMDRListener> listener = new Vector<IMDRListener>();
67
    Vector<IMDRListener> listener = new Vector<IMDRListener>();
71
    private static MDREventProcessor instance = null;
68
    private static MDREventProcessor instance = null;
72
    
69
73
    private MDREventProcessor()
70
    private MDREventProcessor() {
74
    {
75
        Log.out("MDREventProcessor instance Created");
71
        Log.out("MDREventProcessor instance Created");
76
    }
72
    }
77
    
73
78
    public static MDREventProcessor getInstance()
74
    public static MDREventProcessor getInstance() {
79
    {
75
        if (instance == null) {
80
        if(instance==null)
81
            instance = new MDREventProcessor();
76
            instance = new MDREventProcessor();
82
        
77
        }
78
83
        return instance;
79
        return instance;
84
    }
80
    }
85
    public void fireChanged(SourceGroup[] oldValue , SourceGroup[] newValue)
81
86
    {
82
    public void fireChanged(SourceGroup[] oldValue, SourceGroup[] newValue) {
87
        try
83
        try {
88
        {
89
            FileObject lookupDir = FileUtil.getConfigFile("uml/source-roots-listeners");
84
            FileObject lookupDir = FileUtil.getConfigFile("uml/source-roots-listeners");
90
            if (lookupDir != null)
85
            if (lookupDir != null) {
91
            {
92
                FileObject[] children = lookupDir.getChildren();
86
                FileObject[] children = lookupDir.getChildren();
93
                for (FileObject curObj : children)
87
                for (FileObject curObj : children) {
94
                {
88
                    try {
95
                    try
96
                    {
97
                        DataObject dObj = DataObject.find(curObj);
89
                        DataObject dObj = DataObject.find(curObj);
98
                        if (dObj != null)
90
                        if (dObj != null) {
99
                        {
91
                            InstanceCookie cookie = (InstanceCookie) dObj.getCookie(InstanceCookie.class);
100
                            InstanceCookie cookie = (InstanceCookie)dObj
101
                                    .getCookie(InstanceCookie.class);
102
92
103
                            if (cookie != null)
93
                            if (cookie != null) {
104
                            {
105
                                Object obj = cookie.instanceCreate();
94
                                Object obj = cookie.instanceCreate();
106
95
107
                                if (obj instanceof IMDRListener)
96
                                if (obj instanceof IMDRListener) {
108
                                {
97
                                    IMDRListener listener = (IMDRListener) obj;
109
                                    IMDRListener listener = (IMDRListener)obj;
98
                                    if (oldValue != null) {
110
                                    if(oldValue!=null)
111
                                    {
112
                                        listener.removeJMI(oldValue);
99
                                        listener.removeJMI(oldValue);
113
                                    }
100
                                    }
114
101
115
                                    if(newValue!=null)
102
                                    if (newValue != null) {
116
                                    {
117
                                        listener.registerJMI(newValue);
103
                                        listener.registerJMI(newValue);
118
                                    }
104
                                    }
119
                                }
105
                                }
120
                            }
106
                            }
121
                        } // dObj != null
107
                        } // dObj != null
122
                    }
108
                    } catch (ClassNotFoundException e) {
123
124
                    catch (ClassNotFoundException e)
125
                    {
126
                        // Unable to create the instance for some reason.  So the
109
                        // Unable to create the instance for some reason.  So the
127
                        // do not worry about adding the instance to the list.
110
                        // do not worry about adding the instance to the list.
128
                    }
111
                    }
129
                } // for-each FileObject
112
                } // for-each FileObject
130
            } // if lookupDir != null
113
            } // if lookupDir != null
131
        }        
114
        } catch (DataObjectNotFoundException e) {
132
        catch (DataObjectNotFoundException e)
133
        {
134
            // Basically Bail at this time.
115
            // Basically Bail at this time.
135
        }        
116
        } catch (IOException ioE) {
136
        catch (IOException ioE)
137
        {
138
            
139
        }
117
        }
140
    }
118
    }
141
142
}
119
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/ModelElementNewType.java (-32 / +26 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on January 19, 2005, 2:29 PM
48
 * Created on January 19, 2005, 2:29 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui;
50
package org.netbeans.modules.uml.project.ui;
52
51
53
import java.io.IOException;
52
import java.io.IOException;
Lines 58-93 Link Here
58
 *
57
 *
59
 * @author  Trey Spiva
58
 * @author  Trey Spiva
60
 */
59
 */
61
public class ModelElementNewType extends NewType
60
public class ModelElementNewType extends NewType {
62
{
63
   private String mMetaName = "";
64
61
65
   /**
62
    private String mMetaName = "";
66
    * Creates a new ModelElementNewType.  The NewType instance will be able to
63
67
    * create a new Modeling Meta Data instance for the specified type.
64
    /**
68
    *
65
     * Creates a new ModelElementNewType.  The NewType instance will be able to
69
    * @param name The meta data type to be created.
66
     * create a new Modeling Meta Data instance for the specified type.
70
    */
67
     *
71
   public ModelElementNewType(String name)
68
     * @param name The meta data type to be created.
72
   {
69
     */
73
      mMetaName = name;
70
    public ModelElementNewType(String name) {
74
   }
71
        mMetaName = name;
75
   
72
    }
76
   /**
73
77
    * Display name for the creation action. This should be presented as an 
74
    /**
78
    * item in a menu.
75
     * Display name for the creation action. This should be presented as an
79
    */
76
     * item in a menu.
80
   public String getName()
77
     */
81
   {
78
    public String getName() {
82
      return mMetaName;
79
        return mMetaName;
83
   }
80
    }
84
   
81
85
   /**
82
    /**
86
    * Create the object.  The type that is created is model element meta datatype.
83
     * Create the object.  The type that is created is model element meta datatype.
87
    */
84
     */
88
   public void create() throws IOException
85
    public void create() throws IOException {
89
   {
86
    }
90
      
91
   }
92
   
93
}
87
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/NetBeansUMLProjectTreeModel.java (-744 / +641 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui;
44
package org.netbeans.modules.uml.project.ui;
46
45
47
import org.netbeans.modules.uml.project.ui.nodes.UMLRelationshipNode;
46
import org.netbeans.modules.uml.project.ui.nodes.UMLRelationshipNode;
Lines 88-245 Link Here
88
import org.netbeans.modules.uml.project.ui.nodes.UMLDiagramNode;
87
import org.netbeans.modules.uml.project.ui.nodes.UMLDiagramNode;
89
import org.netbeans.modules.uml.project.ui.nodes.NBNodeFactory;
88
import org.netbeans.modules.uml.project.ui.nodes.NBNodeFactory;
90
import java.util.Enumeration;
89
import java.util.Enumeration;
91
import org.netbeans.modules.uml.ui.support.diagramsupport.DrawingAreaEventsAdapter;
92
import org.netbeans.modules.uml.ui.support.diagramsupport.ProxyDiagramManager;
93
90
94
/**
91
/**
95
 *
92
 *
96
 * @author Trey Spiva
93
 * @author Trey Spiva
97
 */
94
 */
98
public class NetBeansUMLProjectTreeModel extends ProjectTreeModelAdapter
95
public class NetBeansUMLProjectTreeModel extends ProjectTreeModelAdapter
99
	implements ISCMEventsSink
96
        implements ISCMEventsSink {
100
{
97
101
	private ITreeItemExpandContext mContext = null;
98
    private ITreeItemExpandContext mContext = null;
102
	private DispatchHelper m_DispatcherHelper = new DispatchHelper();
99
    private DispatchHelper m_DispatcherHelper = new DispatchHelper();
103
	private ProjectTreeNodeFactory mFactory = new NBNodeFactory();
100
    private ProjectTreeNodeFactory mFactory = new NBNodeFactory();
104
	
101
    // All the nodes under the Model root node:
105
	// All the nodes under the Model root node:
102
    // key=<diagramName>#<diagramType>, example: MyDiagram#ClassDiagram_CLOSED;
106
	// key=<diagramName>#<diagramType>, example: MyDiagram#ClassDiagram_CLOSED;
103
    // value=<weak reference to node>, example: #360
107
	// value=<weak reference to node>, example: #360
104
    private HashMap<String, ETList<WeakReference<ITreeItem>>> mNodeMap =
108
	private HashMap<String, ETList<WeakReference<ITreeItem>>> mNodeMap =
105
            new HashMap<String, ETList<WeakReference<ITreeItem>>>();
109
		new HashMap<String, ETList<WeakReference<ITreeItem>>>();
106
    // key=Absolute path/file name of the diagrams .etld file;
110
	
107
    // value=<diagramName>#<diagramType>, example: MyDiagram#ClassDiagram_CLOSED
111
	// key=Absolute path/file name of the diagrams .etld file;
108
    private HashMap<String, String> mDiagramNodeMap =
112
	// value=<diagramName>#<diagramType>, example: MyDiagram#ClassDiagram_CLOSED
109
            new HashMap<String, String>();
113
	private HashMap<String, String> mDiagramNodeMap =
110
    // Just one entry; the ModelRootNode's xmi id is the key and the value
114
		new HashMap<String, String>();
111
    //  is the instance reference # of the Diagrams Root Node,
115
	
112
    //  example: "DCE.96692F3F-E206-862D-D95E-79BF5ABF480B"=>#252
116
	// Just one entry; the ModelRootNode's xmi id is the key and the value
113
    private WeakHashMap<String, UMLDiagramsRootNode> mDiagramsNodeMap =
117
	//  is the instance reference # of the Diagrams Root Node,
114
            new WeakHashMap<String, UMLDiagramsRootNode>();
118
	//  example: "DCE.96692F3F-E206-862D-D95E-79BF5ABF480B"=>#252
115
    private FilteredItemManager diagramOnlyFilter = new FilteredItemManager();
119
	private WeakHashMap<String, UMLDiagramsRootNode> mDiagramsNodeMap =
120
		new WeakHashMap<String, UMLDiagramsRootNode>();
121
	
122
	private FilteredItemManager diagramOnlyFilter = new FilteredItemManager();
123
//	private DrawingAreaSink mDrawingAreaSink = new DrawingAreaSink();
116
//	private DrawingAreaSink mDrawingAreaSink = new DrawingAreaSink();
124
	
117
125
	
118
    /**
126
	/**
119
     *
127
	 *
120
     */
128
	 */
121
    public NetBeansUMLProjectTreeModel() {
129
	public NetBeansUMLProjectTreeModel()
122
        super();
130
	{
123
        diagramOnlyFilter.turnOffModelElements();
131
		super();
124
        m_DispatcherHelper.registerForSCMEvents(this);
132
		diagramOnlyFilter.turnOffModelElements();
125
133
		m_DispatcherHelper.registerForSCMEvents(this);
126
    }
134
		
127
135
	}
128
    public ProjectTreeNodeFactory getNodeFactory() {
136
	
129
        return mFactory;
137
	public ProjectTreeNodeFactory getNodeFactory()
130
    }
138
	{
131
139
		return mFactory;
132
    // TODO: meteora
140
	}
141
	
142
        // TODO: meteora
143
//	public IDrawingAreaEventsSink getDrawingAreaListener()
133
//	public IDrawingAreaEventsSink getDrawingAreaListener()
144
//	{
134
//	{
145
//		return mDrawingAreaSink;
135
//		return mDrawingAreaSink;
146
//	}
136
//	}
147
	
137
    public void fireDiagramsExpanding(UMLDiagramsRootNode node, IProject project) {
148
	public void fireDiagramsExpanding(UMLDiagramsRootNode node, IProject project)
138
        try {
149
	{
139
            IProjectTreeEventDispatcher disp =
150
		try
140
                    m_DispatcherHelper.getProjectTreeDispatcher();
151
		{
152
			IProjectTreeEventDispatcher disp = 
153
				m_DispatcherHelper.getProjectTreeDispatcher();
154
			
155
			if (disp != null)
156
			{
157
				IEventPayload payload = 
158
					disp.createPayload("ProjectTreeItemExpanding"); // NOI18N
159
				IProjectTreeExpandingContext expandingContext = 
160
					new ProjectTreeExpandingContextImpl(node);
161
				
162
				disp.fireItemExpandingWithFilter(
163
					null, expandingContext, diagramOnlyFilter, payload);
164
			}
165
			
166
			mDiagramsNodeMap.put(project.getXMIID(), node);
167
		}
168
		
169
		catch (Exception e)
170
		{
171
		}
172
	}
173
	
174
	public void fireItemExpanding(ITreeItem item, ITreeItemExpandContext context)
175
	{
176
		try
177
		{
178
			mContext = context;
179
			
180
			IProjectTreeEventDispatcher disp = 
181
				m_DispatcherHelper.getProjectTreeDispatcher();
182
			
183
			if (disp != null)
184
			{
185
				// Debug.out.println("In fireItemExpanding " + disp);
186
				IEventPayload payload = 
187
					disp.createPayload("ProjectTreeItemExpanding"); // NOI18N
188
				
189
				IProjectTreeExpandingContext expandingContext = 
190
					new ProjectTreeExpandingContextImpl(item);
191
				
192
				disp.fireItemExpanding(null, expandingContext, payload);
193
			}
194
		}
195
		
196
		catch (Exception e)
197
		{
198
			e.printStackTrace();
199
		}
200
		
201
		finally
202
		{
203
			mContext = null;
204
		}
205
	}
206
141
207
	public void fireItemExpanding(ITreeItem item)
142
            if (disp != null) {
208
	{
143
                IEventPayload payload =
209
            fireItemExpanding(item, null);
144
                        disp.createPayload("ProjectTreeItemExpanding"); // NOI18N
145
                IProjectTreeExpandingContext expandingContext =
146
                        new ProjectTreeExpandingContextImpl(node);
147
148
                disp.fireItemExpandingWithFilter(
149
                        null, expandingContext, diagramOnlyFilter, payload);
150
            }
151
152
            mDiagramsNodeMap.put(project.getXMIID(), node);
153
        } catch (Exception e) {
210
        }
154
        }
211
		
155
    }
212
        
156
213
   /* (non-Javadoc)
157
    public void fireItemExpanding(ITreeItem item, ITreeItemExpandContext context) {
214
	* @see org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeModel#addItem(org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeItem, java.lang.String, java.lang.String, long, org.netbeans.modules.uml.core.metamodel.core.foundation.IElement, java.lang.Object, java.lang.String)
158
        try {
215
	*/
159
            mContext = context;
216
	public IProjectTreeItem addItem(
160
217
		IProjectTreeItem parent,
161
            IProjectTreeEventDispatcher disp =
218
		String name,
162
                    m_DispatcherHelper.getProjectTreeDispatcher();
219
		String text,
163
220
		long sortPriority,
164
            if (disp != null) {
221
		IElement element,
165
                // Debug.out.println("In fireItemExpanding " + disp);
222
		Object supportTreeItem,
166
                IEventPayload payload =
223
		String description)
167
                        disp.createPayload("ProjectTreeItemExpanding"); // NOI18N
224
	{
168
225
		IProjectTreeItem retVal = createProjectTreeItem(
169
                IProjectTreeExpandingContext expandingContext =
226
			text, sortPriority, element, supportTreeItem, description);
170
                        new ProjectTreeExpandingContextImpl(item);
227
		
171
228
		// notifyContextOfAdd(retVal);
172
                disp.fireItemExpanding(null, expandingContext, payload);
229
		//Debug.out.println("addItem 1: [name="+name+", text="+text+"]");
173
            }
230
		
174
        } catch (Exception e) {
231
		return retVal;
175
            e.printStackTrace();
232
	}
176
        } finally {
233
	
177
            mContext = null;
234
        /* (non-Javadoc)
178
        }
235
	* @see org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeModel#addItem(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem, org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
179
    }
236
	*/
180
237
	public void addItem(ITreeItem parent, ITreeItem node)
181
    public void fireItemExpanding(ITreeItem item) {
238
	{
182
        fireItemExpanding(item, null);
239
            // Commented out this block of code since it causes IZ=110809. 
183
    }
240
            // The root cause of # 6283081 is addressed in the updateTree() method
184
241
            // of ADProjectTreeEngine.
185
    /* (non-Javadoc)
242
            
186
     * @see org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeModel#addItem(org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeItem, java.lang.String, java.lang.String, long, org.netbeans.modules.uml.core.metamodel.core.foundation.IElement, java.lang.Object, java.lang.String)
187
     */
188
    public IProjectTreeItem addItem(
189
            IProjectTreeItem parent,
190
            String name,
191
            String text,
192
            long sortPriority,
193
            IElement element,
194
            Object supportTreeItem,
195
            String description) {
196
        IProjectTreeItem retVal = createProjectTreeItem(
197
                text, sortPriority, element, supportTreeItem, description);
198
199
        // notifyContextOfAdd(retVal);
200
        //Debug.out.println("addItem 1: [name="+name+", text="+text+"]");
201
202
        return retVal;
203
    }
204
205
    /* (non-Javadoc)
206
     * @see org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeModel#addItem(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem, org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
207
     */
208
    public void addItem(ITreeItem parent, ITreeItem node) {
209
        // Commented out this block of code since it causes IZ=110809.
210
        // The root cause of # 6283081 is addressed in the updateTree() method
211
        // of ADProjectTreeEngine.
212
243
//            // since folder node is always created with a new UMLFolderNode
213
//            // since folder node is always created with a new UMLFolderNode
244
//            // we have to remove the old folder node before adding the new one #6283081
214
//            // we have to remove the old folder node before adding the new one #6283081
245
//            if (node instanceof ITreeFolder)
215
//            if (node instanceof ITreeFolder)
Lines 256-439 Link Here
256
//                    }
226
//                    }
257
//            }
227
//            }
258
228
259
            if (!alreadyHasChild(parent, node) && 
229
        if (!alreadyHasChild(parent, node)
260
                !(parent instanceof UMLRelationshipNode))
230
                && !(parent instanceof UMLRelationshipNode)) {
261
            {
231
            parent.addChild(node);
262
                    parent.addChild(node);
263
232
264
                    if (!(node instanceof ITreeFolder))
233
            if (!(node instanceof ITreeFolder)) {
265
                    addNode(node);
234
                addNode(node);
266
            }
235
            }
267
	}
236
        }
268
	
237
    }
269
    
238
270
    public boolean alreadyHasChild(ITreeItem parent, ITreeItem child)
239
    public boolean alreadyHasChild(ITreeItem parent, ITreeItem child)
271
        throws IllegalArgumentException
240
            throws IllegalArgumentException {
272
    {
241
        if (parent == null || child == null) {
273
        if (parent == null || child == null)
274
            throw new IllegalArgumentException(
242
            throw new IllegalArgumentException(
275
                "Neither parent nor child argument can be null"); // NOI18N
243
                    "Neither parent nor child argument can be null"); // NOI18N
276
        
244
        }
277
        if (parent.getChildCount() == 0)
245
        if (parent.getChildCount() == 0) {
278
            return false;
246
            return false;
279
        
247
        }
248
280
        Enumeration<ITreeItem> kids = parent.getNodeChildren();
249
        Enumeration<ITreeItem> kids = parent.getNodeChildren();
281
        ITreeItem curChild = null;
250
        ITreeItem curChild = null;
282
        
251
283
        while (kids.hasMoreElements())
252
        while (kids.hasMoreElements()) {
284
        {
285
            curChild = kids.nextElement();
253
            curChild = kids.nextElement();
286
            if (curChild == child || curChild.equals(child))
254
            if (curChild == child || curChild.equals(child)) {
287
                return true;
255
                return true;
256
            }
288
        }
257
        }
289
        
258
290
        return false;
259
        return false;
291
    }
260
    }
292
    
261
293
    
262
    /* (non-Javadoc)
294
   /* (non-Javadoc)
263
     * @see org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeModel#addItem(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem, java.lang.String, java.lang.String, long, org.netbeans.modules.uml.core.metamodel.core.foundation.IElement, java.lang.Object, java.lang.String)
295
	* @see org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeModel#addItem(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem, java.lang.String, java.lang.String, long, org.netbeans.modules.uml.core.metamodel.core.foundation.IElement, java.lang.Object, java.lang.String)
264
     */
296
	*/
265
    public IProjectTreeItem addItem(
297
	public IProjectTreeItem addItem(
266
            ITreeItem parent,
298
		ITreeItem parent,
267
            String name,
299
		String name,
268
            String text,
300
		String text,
269
            long sortPriority,
301
		long sortPriority,
270
            IElement element,
302
		IElement element,
271
            Object supportTreeItem,
303
		Object supportTreeItem,
272
            String description) {
304
		String description)
273
        IProjectTreeItem retVal = createProjectTreeItem(
305
	{
274
                text, sortPriority, element, supportTreeItem, description);
306
		IProjectTreeItem retVal = createProjectTreeItem(
275
307
			text, sortPriority, element, supportTreeItem, description);
276
        // Debug.out.println("addItem 1: [name="+name+", text=" + text + "]");
308
		
277
        // notifyContextOfAdd(retVal);
309
		// Debug.out.println("addItem 1: [name="+name+", text=" + text + "]");
278
310
		// notifyContextOfAdd(retVal);
279
        return retVal;
311
		
280
    }
312
		return retVal;
281
313
	}
282
    /**
314
	
283
     * Locate the node that represents the model element.
315
	/**
284
     *
316
	 * Locate the node that represents the model element.
285
     * @param element The model element to locate.
317
	 *
286
     * @return The tree Node.  <code>null</code> is returned if the node
318
	 * @param element The model element to locate.
287
     *         is not found.
319
	 * @return The tree Node.  <code>null</code> is returned if the node
288
     */
320
	 *         is not found.
289
    public ETList<ITreeItem> findNodes(final IElement element) {
321
	 */
290
        ETList<ITreeItem> retVal = new ETArrayList<ITreeItem>();
322
	public ETList<ITreeItem> findNodes(final IElement element)
291
323
	{
292
        ETList<WeakReference<ITreeItem>> list =
324
		ETList<ITreeItem> retVal = new ETArrayList<ITreeItem>();
293
                mNodeMap.get(element.getXMIID());
325
		
294
326
		ETList<WeakReference<ITreeItem>> list = 
295
        if (list != null) {
327
			mNodeMap.get(element.getXMIID());
296
            for (WeakReference<ITreeItem> ref : list) {
328
		
297
                if (ref != null) {
329
		if (list != null)
298
                    ITreeItem item = ref.get();
330
		{
299
331
			for (WeakReference<ITreeItem> ref : list)
300
                    if (item != null) {
332
			{
301
                        if (getModelRootNode(item) != null) {
333
				if (ref != null)
302
                            retVal.add(item);
334
				{
303
                        }
335
					ITreeItem item = ref.get();
304
                    }
336
					
305
                }
337
					if (item != null) 
306
            }
338
                                        {
307
        }
339
                                                if ( getModelRootNode(item) != null) 
308
340
                                                {
309
        return retVal;
341
                                                        retVal.add(item);
310
    }
342
                                                }
311
343
                                        }
312
    /**
344
				}
313
     * Locates the nodes that represents the model element.
345
			}
314
     *
346
		}
315
     * @param element The model element to locate.
347
		
316
     * @return The tree Node.  <code>null</code> is returned if the node
348
		return retVal;
317
     *         is not found.
349
	}
318
     */
350
	
319
    public ETList<ITreeItem> findNodes(Comparator<ITreeItem> comparator) {
351
	/**
320
        ETList<ITreeItem> retVal = new ETArrayList<ITreeItem>();
352
	 * Locates the nodes that represents the model element.
321
353
	 *
322
        // findNodes(getRootItem(), comparator, retVal);
354
	 * @param element The model element to locate.
323
355
	 * @return The tree Node.  <code>null</code> is returned if the node
324
        return retVal;
356
	 *         is not found.
325
    }
357
	 */
326
358
	public ETList<ITreeItem> findNodes(Comparator<ITreeItem> comparator )
327
    /**
359
	{
328
     * Locate the node that represents the model element.
360
		ETList<ITreeItem> retVal = new ETArrayList<ITreeItem>();
329
     *
361
		
330
     * @param filename The name of the file that specifies the diagram.
362
		// findNodes(getRootItem(), comparator, retVal);
331
     * @return The tree Nodes.  <code>null</code> is returned if the node
363
		
332
     *         is not found.
364
		return retVal;
333
     */
365
	}
334
    public ETList<ITreeItem> findDiagramNodes(final String filename) {
366
	
335
        //      Debug.out.println("Got findDiagramNodes in NetBeansUMLProjectTreeModel");
367
	/**
336
        //      TopComponent tc = WindowManager.getDefault().findTopComponent("project");
368
	 * Locate the node that represents the model element.
337
        //      if (tc != null)
369
	 *
338
        //      {
370
	 * @param filename The name of the file that specifies the diagram.
339
        //         Debug.out.println("got the tc");
371
	 * @return The tree Nodes.  <code>null</code> is returned if the node
340
        //      }
372
	 *         is not found.
341
        //
373
	 */
342
        //      return findNodes(new Comparator < ITreeItem >()
374
	public ETList<ITreeItem> findDiagramNodes(final String filename)
343
        //      {
375
	{
344
        //         public int compare(ITreeItem o1, ITreeItem o2)
376
		//      Debug.out.println("Got findDiagramNodes in NetBeansUMLProjectTreeModel");
345
        //         {
377
		//      TopComponent tc = WindowManager.getDefault().findTopComponent("project");
346
        //            return 0;
378
		//      if (tc != null)
347
        //         }
379
		//      {
348
        //
380
		//         Debug.out.println("got the tc");
349
        //         public boolean equals(Object obj)
381
		//      }
350
        //         {
382
		//
351
        //            return obj.equals(filename);
383
		//      return findNodes(new Comparator < ITreeItem >()
352
        //         }
384
		//      {
353
        //      });
385
		//         public int compare(ITreeItem o1, ITreeItem o2)
354
386
		//         {
355
        String key = mDiagramNodeMap.get(filename);
387
		//            return 0;
356
        ETList<ITreeItem> retVal = new ETArrayList<ITreeItem>();
388
		//         }
357
389
		//
358
        if (key != null) {
390
		//         public boolean equals(Object obj)
359
            // Now we got the key we can get the list from the node list.
391
		//         {
360
            ETList<WeakReference<ITreeItem>> list = mNodeMap.get(key);
392
		//            return obj.equals(filename);
361
393
		//         }
362
            if (list != null) {
394
		//      });
363
                for (WeakReference<ITreeItem> ref : list) {
395
		
364
                    if (ref != null) {
396
		String key = mDiagramNodeMap.get(filename);
365
                        ITreeItem diagRef = ref.get();
397
		ETList<ITreeItem> retVal = new ETArrayList<ITreeItem>();
366
398
		
367
                        if (diagRef != null) {
399
		if (key != null)
368
                            retVal.add(diagRef);
400
		{
369
                        }
401
			// Now we got the key we can get the list from the node list.
370
                    }
402
			ETList<WeakReference<ITreeItem>> list = mNodeMap.get(key);
371
                }
403
			
372
            }
404
			if (list != null)
373
        }
405
			{
374
406
				for (WeakReference<ITreeItem> ref : list)
375
        return retVal;
407
				{
376
    }
408
					if (ref != null)
377
409
					{
378
    /**
410
						ITreeItem diagRef = ref.get();
379
     * Removes a node from its parent.  The parent of the nodes is determined
411
						
380
     * by calling getParent on the passed in node.
412
						if (diagRef != null)
381
     *
413
							retVal.add(diagRef);
382
     * @param node The node to be removed.
414
					}
383
     */
415
				}
384
    public void removeNodeFromParent(ITreeItem node) {
416
			}
385
        ITreeItem parent = node.getParentItem();
417
		}
386
418
		
387
        if (parent != null) {
419
		return retVal;
388
            removeInstanceFromModel(node);
420
	}
389
            parent.removeChild(node);
421
	
390
422
	/**
423
	 * Removes a node from its parent.  The parent of the nodes is determined
424
	 * by calling getParent on the passed in node.
425
	 *
426
	 * @param node The node to be removed.
427
	 */
428
	public void removeNodeFromParent(ITreeItem node)
429
	{
430
		ITreeItem parent = node.getParentItem();
431
		
432
		if (parent != null)
433
		{
434
			removeInstanceFromModel(node);
435
			parent.removeChild(node);
436
			
437
//                                // cvc - CR 6272973
391
//                                // cvc - CR 6272973
438
//			// refresh the Diagrams root node
392
//			// refresh the Diagrams root node
439
//			if (node instanceof ITreeDiagram)
393
//			if (node instanceof ITreeDiagram)
Lines 445-835 Link Here
445
//
399
//
446
//				diagramsNode.recalculateChildren();
400
//				diagramsNode.recalculateChildren();
447
//			}
401
//			}
448
                        // refresh parent node if parent node is a folder node
402
            // refresh parent node if parent node is a folder node
449
                        // and parent node is current expanded.
403
            // and parent node is current expanded.
450
                        
404
451
		}
405
        }
452
	}
406
    }
453
	
407
454
	public UMLModelRootNode getModelRootNode(ITreeItem node)
408
    public UMLModelRootNode getModelRootNode(ITreeItem node) {
455
	{
456
//		if (node instanceof IProjectTreeItem)
409
//		if (node instanceof IProjectTreeItem)
457
//		{
410
//		{
458
//			IProjectTreeItem prjTreeItem = (IProjectTreeItem)node;
411
//			IProjectTreeItem prjTreeItem = (IProjectTreeItem)node;
459
//			IProject project = prjTreeItem.getProject();
412
//			IProject project = prjTreeItem.getProject();
460
//			mNodeMap.get(project.getXMIID());
413
//			mNodeMap.get(project.getXMIID());
461
//		}
414
//		}
462
		
415
463
		if (node == null)
416
        if (node == null) {
464
			return null;
417
            return null;
465
		
418
        } else if (node instanceof UMLModelRootNode) {
466
		else if (node instanceof UMLModelRootNode)
419
            return (UMLModelRootNode) node;
467
			return (UMLModelRootNode)node;
420
        }
468
		
421
469
		ITreeItem parent = node.getParentItem();
422
        ITreeItem parent = node.getParentItem();
470
		
423
471
		if (parent == null)
424
        if (parent == null) {
472
			return null;
425
            return null;
473
		
426
        } else if (parent instanceof UMLModelRootNode) {
474
		else if (parent instanceof UMLModelRootNode)
427
            return (UMLModelRootNode) parent;
475
			return (UMLModelRootNode)parent;
428
        } else if (parent instanceof IProject) {
476
		
429
            ITreeItem treeItem = (ITreeItem) mNodeMap.get(((IProject) parent).getXMIID());
477
		else if (parent instanceof IProject)
430
478
		{
431
            if (treeItem instanceof UMLModelRootNode) {
479
			ITreeItem treeItem = (ITreeItem)mNodeMap
432
                return (UMLModelRootNode) treeItem;
480
				.get(((IProject)parent).getXMIID());
481
			
482
			if (treeItem instanceof UMLModelRootNode)
483
				return (UMLModelRootNode)treeItem;
484
		}
485
		
486
		return getModelRootNode(parent);
487
	}
488
	
489
        public UMLDiagramsRootNode getDiagramsRootNode(IProject project) 
490
        {
491
            
492
            UMLDiagramsRootNode diagramsRootNode = null;
493
            if ( project != null)
494
            {
495
                diagramsRootNode = mDiagramsNodeMap.get(project.getXMIID());
496
            }
433
            }
497
            
498
            return diagramsRootNode;
499
        }
434
        }
500
	
501
	/**
502
	 * Remove all instances of the model element from the model.
503
	 */
504
	public void removeAll(IElement element)
505
	{
506
		ETList<ITreeItem> nodes = findNodes(element);
507
		
508
		if (nodes != null)
509
		{
510
			for (ITreeItem curNode : nodes)
511
			{
512
				removeNodeFromParent(curNode);
513
			}
514
		}
515
	}
516
	
517
	public void addModelRootNode(UMLModelRootNode node, Project project)
518
	{
519
		Lookup lookup = project.getLookup();
520
		
521
		// cvc - as per comments by MCF in UMLProject, the IProject is not
522
		//  added as a "lookup" anymore, but the ProjectHelper is and we can
523
		//  get the Project from that
524
		// IProject projectElement = (IProject)lookup.lookup(IProject.class);
525
		IProject projectElement = ((UMLProjectHelper)lookup
526
			.lookup(UMLProjectHelper.class)).getProject();
527
		
528
		if (projectElement != null)
529
		{
530
			// The project can only be displayed on the list once.  Therefore,
531
			// if the project is already present do not allow it to be added
532
			// again.
533
			ETList<WeakReference<ITreeItem>> list =
534
				mNodeMap.get(projectElement.getXMIID());
535
			
536
			if ((list == null) || (list.size() <= 0))
537
				addNode(projectElement.getXMIID(), node);
538
		}
539
	}
540
	
541
	////////////////////////////////////////////////////////////////////////////
542
	// Helper Methods
543
	////////////////////////////////////////////////////////////////////////////
544
	
545
	/**
546
	 * Notify that listener that something tree item has been updated.
547
	 */
548
	protected void notifyContextOfAdd(IProjectTreeItem retVal)
549
	{
550
		if (mContext != null)
551
		{
552
			ProjectTreeNode node = new ProjectTreeNode(retVal);
553
			mContext.itemAdded(node);
554
		}
555
	}
556
	
557
	/**
558
	 * Create and a new tree item.
559
	 *
560
	 * @parem text The display text
561
	 * @param sortPriority The index into the sort algorithm
562
	 * @param element The associated model element
563
	 * @param supportedTreeItem Additional data to assoicated with the tree item.
564
	 * @param description A description of the tree node.
565
	 */
566
	protected IProjectTreeItem createProjectTreeItem(
567
		String text,
568
		long sortPriority,
569
		IElement element,
570
		Object supportTreeItem,
571
		String description)
572
	{
573
		// Debug.out.println("Creating a project tree item for " + text);
574
		
575
		IProjectTreeItem retVal = new ProjectTreeItemImpl();
576
		retVal.setItemText(text);
577
		retVal.setModelElement(element);
578
		retVal.setDescription(description);
579
		retVal.setSortPriority((int)sortPriority);
580
		
581
		if (supportTreeItem instanceof ITreeItem)
582
			retVal.setProjectTreeSupportTreeItem((ITreeItem)supportTreeItem);
583
		
584
		return retVal;
585
	}
586
	
587
	/**
588
	 * Searches the model for the node that visualizes the model tree item.
589
	 *
590
	 * @param element
591
	 * @param item
592
	 * @param items
593
	 */
594
	protected void findNodes(
595
		ITreeItem parentItem,
596
		Comparator<ITreeItem> comparator,
597
		ETList<ITreeItem> items)
598
	{
599
		if ((parentItem != null) && (items != null))
600
		{
601
			// if(parentItem.equals(element) == true)
602
			
603
			if(comparator.equals(parentItem) == true)
604
				items.add(parentItem);
605
			
606
			int childCnt = parentItem.getChildCount();
607
			
608
			for (int index = 0; index < childCnt; index++)
609
			{
610
				ITreeItem child = parentItem.getChild(index);
611
				findNodes(child, comparator, items);
612
			}
613
		}
614
	}
615
	
616
435
617
	/**
436
        return getModelRootNode(parent);
618
	 * Removes the reference to the node from node map in our model.
437
    }
619
	 *
438
620
	 * @param node The node that needs to be removed.
439
    public UMLDiagramsRootNode getDiagramsRootNode(IProject project) {
621
	 */
440
622
	public void removeInstanceFromHash(ITreeItem node)
441
        UMLDiagramsRootNode diagramsRootNode = null;
623
	{
442
        if (project != null) {
624
		if (node != null)
443
            diagramsRootNode = mDiagramsNodeMap.get(project.getXMIID());
625
		{       
444
        }
626
			String key = getNodeKey(node);
445
627
			ETList<WeakReference<ITreeItem>> nodeList = mNodeMap.get(key);
446
        return diagramsRootNode;
628
			
447
    }
629
			// cvc - 6272973
448
630
			// if the diagram is closed, then its name now has "_CLOSED"
449
    /**
631
			// appended to it but the mNodeMap has a key for the diagram
450
     * Remove all instances of the model element from the model.
632
			// that doesn't have "_CLOSED". Also, try appending "_CLOSED"
451
     */
633
			// if it wasn't ther already just to cover all the bases
452
    public void removeAll(IElement element) {
634
			if (nodeList == null && node instanceof UMLDiagramNode)
453
        ETList<ITreeItem> nodes = findNodes(element);
635
			{
454
636
				if (key.endsWith("_CLOSED"))
455
        if (nodes != null) {
637
					key = key.substring(0, key.indexOf("_CLOSED"));
456
            for (ITreeItem curNode : nodes) {
457
                removeNodeFromParent(curNode);
458
            }
459
        }
460
    }
461
462
    public void addModelRootNode(UMLModelRootNode node, Project project) {
463
        Lookup lookup = project.getLookup();
464
465
        // cvc - as per comments by MCF in UMLProject, the IProject is not
466
        //  added as a "lookup" anymore, but the ProjectHelper is and we can
467
        //  get the Project from that
468
        // IProject projectElement = (IProject)lookup.lookup(IProject.class);
469
        IProject projectElement = ((UMLProjectHelper) lookup.lookup(UMLProjectHelper.class)).getProject();
470
471
        if (projectElement != null) {
472
            // The project can only be displayed on the list once.  Therefore,
473
            // if the project is already present do not allow it to be added
474
            // again.
475
            ETList<WeakReference<ITreeItem>> list =
476
                    mNodeMap.get(projectElement.getXMIID());
477
478
            if ((list == null) || (list.size() <= 0)) {
479
                addNode(projectElement.getXMIID(), node);
480
            }
481
        }
482
    }
483
484
    ////////////////////////////////////////////////////////////////////////////
485
    // Helper Methods
486
    ////////////////////////////////////////////////////////////////////////////
487
    /**
488
     * Notify that listener that something tree item has been updated.
489
     */
490
    protected void notifyContextOfAdd(IProjectTreeItem retVal) {
491
        if (mContext != null) {
492
            ProjectTreeNode node = new ProjectTreeNode(retVal);
493
            mContext.itemAdded(node);
494
        }
495
    }
496
497
    /**
498
     * Create and a new tree item.
499
     *
500
     * @parem text The display text
501
     * @param sortPriority The index into the sort algorithm
502
     * @param element The associated model element
503
     * @param supportedTreeItem Additional data to assoicated with the tree item.
504
     * @param description A description of the tree node.
505
     */
506
    protected IProjectTreeItem createProjectTreeItem(
507
            String text,
508
            long sortPriority,
509
            IElement element,
510
            Object supportTreeItem,
511
            String description) {
512
        // Debug.out.println("Creating a project tree item for " + text);
513
514
        IProjectTreeItem retVal = new ProjectTreeItemImpl();
515
        retVal.setItemText(text);
516
        retVal.setModelElement(element);
517
        retVal.setDescription(description);
518
        retVal.setSortPriority((int) sortPriority);
519
520
        if (supportTreeItem instanceof ITreeItem) {
521
            retVal.setProjectTreeSupportTreeItem((ITreeItem) supportTreeItem);
522
        }
523
524
        return retVal;
525
    }
526
527
    /**
528
     * Searches the model for the node that visualizes the model tree item.
529
     *
530
     * @param element
531
     * @param item
532
     * @param items
533
     */
534
    protected void findNodes(
535
            ITreeItem parentItem,
536
            Comparator<ITreeItem> comparator,
537
            ETList<ITreeItem> items) {
538
        if ((parentItem != null) && (items != null)) {
539
            // if(parentItem.equals(element) == true)
540
541
            if (comparator.equals(parentItem) == true) {
542
                items.add(parentItem);
543
            }
544
545
            int childCnt = parentItem.getChildCount();
546
547
            for (int index = 0; index < childCnt; index++) {
548
                ITreeItem child = parentItem.getChild(index);
549
                findNodes(child, comparator, items);
550
            }
551
        }
552
    }
553
554
    /**
555
     * Removes the reference to the node from node map in our model.
556
     *
557
     * @param node The node that needs to be removed.
558
     */
559
    public void removeInstanceFromHash(ITreeItem node) {
560
        if (node != null) {
561
            String key = getNodeKey(node);
562
            ETList<WeakReference<ITreeItem>> nodeList = mNodeMap.get(key);
563
564
            // cvc - 6272973
565
            // if the diagram is closed, then its name now has "_CLOSED"
566
            // appended to it but the mNodeMap has a key for the diagram
567
            // that doesn't have "_CLOSED". Also, try appending "_CLOSED"
568
            // if it wasn't ther already just to cover all the bases
569
            if (nodeList == null && node instanceof UMLDiagramNode) {
570
                if (key.endsWith("_CLOSED")) {
571
                    key = key.substring(0, key.indexOf("_CLOSED"));
572
                }
638
//				
573
//				
639
//				else
574
//				else
640
//					key = key+"_CLOSED";
575
//					key = key+"_CLOSED";
641
				
642
				nodeList = mNodeMap.get(key);
643
			}
644
			
645
			if (nodeList != null)
646
			{
647
				// I need to remove all of the items from the tree that are the
648
				// same instance of the specified node.  I can not just call remove
649
				// becaue the remove will use the equals method to determine if
650
				// the list item is the same as the specified node.  Since all items
651
				// have the same key theorectially the equals method will say all
652
				// list items are the same.
653
				//
654
				// This time I am not interested in the logicaly equality, I am
655
				// interested if they are the same instances.
656
				
657
				for (int index = nodeList.size() - 1; index >= 0; index--)
658
				{
659
					WeakReference<ITreeItem> curNode = nodeList.get(index);
660
					
661
					if (curNode.get() == node)
662
						nodeList.remove(index);
663
				}
664
				
665
				if (nodeList.size() == 0)
666
					mNodeMap.remove(key);
667
			}
668
		} // if node !null
669
	}
670
	
671
576
672
	/**
577
                nodeList = mNodeMap.get(key);
673
	 * Removes the reference to the node in our model.
578
            }
674
	 *
579
675
	 * @param node The node that needs to be removed.
580
            if (nodeList != null) {
676
	 */
581
                // I need to remove all of the items from the tree that are the
677
	protected void removeInstanceFromModel(ITreeItem node)
582
                // same instance of the specified node.  I can not just call remove
678
	{
583
                // becaue the remove will use the equals method to determine if
679
		if (node != null)
584
                // the list item is the same as the specified node.  Since all items
680
		{
585
                // have the same key theorectially the equals method will say all
681
		        removeInstanceFromHash(node);
586
                // list items are the same.
682
			
587
                //
683
			if (node instanceof ITreeDiagram)
588
                // This time I am not interested in the logicaly equality, I am
684
			{
589
                // interested if they are the same instances.
685
				ITreeDiagram diagramNode = (ITreeDiagram)node;
590
686
				IProxyDiagram diagram = diagramNode.getDiagram();
591
                for (int index = nodeList.size() - 1; index >= 0; index--) {
687
				
592
                    WeakReference<ITreeItem> curNode = nodeList.get(index);
688
				if (diagram != null)
593
689
				{
594
                    if (curNode.get() == node) {
690
					String filename = diagram.getFilename();
595
                        nodeList.remove(index);
691
					mDiagramNodeMap.remove(filename);
596
                    }
692
					
597
                }
693
					// cvc - start 6272973 fix
598
694
					// IProject project = diagram.getProject();
599
                if (nodeList.size() == 0) {
695
					// if(project != null)
600
                    mNodeMap.remove(key);
696
					// {
601
                }
697
					//     UMLDiagramsRootNode diagramsNode =
602
            }
698
					//             mDiagramsNodeMap.get(project.getXMIID());
603
        } // if node !null
699
					//     if (diagramsNode != null)
604
    }
700
					//         diagramsNode.removeChild(diagramNode);
605
701
					// }
606
    /**
702
					
607
     * Removes the reference to the node in our model.
703
					// cvc - 6272973
608
     *
704
					// the above method for getting the Diagrams root node was
609
     * @param node The node that needs to be removed.
705
					// failing because the project was always null
610
     */
706
					// removeFromDiagramsRootNode(diagramNode);
611
    protected void removeInstanceFromModel(ITreeItem node) {
707
				} // if diagram !null
612
        if (node != null) {
708
			} // if node instanceof ITreeDiagram
613
            removeInstanceFromHash(node);
709
		} // if node !null
614
710
	}
615
            if (node instanceof ITreeDiagram) {
711
	
616
                ITreeDiagram diagramNode = (ITreeDiagram) node;
712
	private void removeFromDiagramsRootNode(ITreeItem treeItem)
617
                IProxyDiagram diagram = diagramNode.getDiagram();
713
	{
618
714
		UMLModelRootNode modelRootNode = getModelRootNode(treeItem);
619
                if (diagram != null) {
715
		
620
                    String filename = diagram.getFilename();
716
		if (modelRootNode != null)
621
                    mDiagramNodeMap.remove(filename);
717
		{
622
718
			UMLDiagramsRootNode diagramsNode =
623
                    // cvc - start 6272973 fix
719
				mDiagramsNodeMap.get(
624
                    // IProject project = diagram.getProject();
720
				modelRootNode.getModelElement().getXMIID());
625
                    // if(project != null)
721
			
626
                    // {
722
			if (diagramsNode != null)
627
                    //     UMLDiagramsRootNode diagramsNode =
723
				diagramsNode.removeChild(treeItem);
628
                    //             mDiagramsNodeMap.get(project.getXMIID());
724
		}
629
                    //     if (diagramsNode != null)
725
		
630
                    //         diagramsNode.removeChild(diagramNode);
726
		else
631
                    // }
727
		{
632
728
			Iterator it = mDiagramsNodeMap.keySet().iterator();
633
                    // cvc - 6272973
729
			
634
                    // the above method for getting the Diagrams root node was
730
			while (it.hasNext())
635
                    // failing because the project was always null
731
			{
636
                    // removeFromDiagramsRootNode(diagramNode);
732
				UMLDiagramsRootNode diagramsNode =
637
                } // if diagram !null
733
					mDiagramsNodeMap.get(it.next());
638
            } // if node instanceof ITreeDiagram
734
				
639
        } // if node !null
735
				diagramsNode.removeChild((ITreeItem)treeItem);
640
    }
736
			} // while
641
737
		} // else
642
    private void removeFromDiagramsRootNode(ITreeItem treeItem) {
738
	}
643
        UMLModelRootNode modelRootNode = getModelRootNode(treeItem);
739
	
644
740
	/**
645
        if (modelRootNode != null) {
741
	 * Generates a key for the specified node.  If the node is associated with
646
            UMLDiagramsRootNode diagramsNode =
742
	 * an IElement then the key will be the model elements id.
647
                    mDiagramsNodeMap.get(
743
	 *
648
                    modelRootNode.getModelElement().getXMIID());
744
	 * @param node The node that needs a key.
649
745
	 * @return The generated key.
650
            if (diagramsNode != null) {
746
	 */
651
                diagramsNode.removeChild(treeItem);
747
	protected String getNodeKey(ITreeItem node)
652
            }
748
        {
653
        } else {
749
            String retVal = "";
654
            Iterator it = mDiagramsNodeMap.keySet().iterator();
750
            IElement element = null;
655
751
            
656
            while (it.hasNext()) {
752
            if (node != null)
657
                UMLDiagramsRootNode diagramsNode =
753
            {
658
                        mDiagramsNodeMap.get(it.next());
754
                if (node.getData() != null)
659
755
                {
660
                diagramsNode.removeChild((ITreeItem) treeItem);
756
                    element = node.getData().getModelElement();
661
            } // while
757
                    
662
        } // else
758
                    if (element != null)
663
    }
759
                        retVal = element.getXMIID();
664
760
                    
665
    /**
761
                    else
666
     * Generates a key for the specified node.  If the node is associated with
762
                    {
667
     * an IElement then the key will be the model elements id.
763
                        if (node instanceof UMLDiagramNode)
668
     *
764
                        {
669
     * @param node The node that needs a key.
765
                            UMLDiagramNode aNode = (UMLDiagramNode)node;
670
     * @return The generated key.
766
                            element = aNode.getModelElement();
671
     */
767
                            if (element != null)
672
    protected String getNodeKey(ITreeItem node) {
768
                            {
673
        String retVal = "";
769
                                retVal = element.getXMIID();
674
        IElement element = null;
675
676
        if (node != null) {
677
            if (node.getData() != null) {
678
                element = node.getData().getModelElement();
679
680
                if (element != null) {
681
                    retVal = element.getXMIID();
682
                } else {
683
                    if (node instanceof UMLDiagramNode) {
684
                        UMLDiagramNode aNode = (UMLDiagramNode) node;
685
                        element = aNode.getModelElement();
686
                        if (element != null) {
687
                            retVal = element.getXMIID();
688
                        } else {
689
                            IProxyDiagram proxyDiagram = aNode.getDiagram();
690
                            if (proxyDiagram != null) {
691
                                retVal = proxyDiagram.getXMIID();
770
                            }
692
                            }
771
                            else
693
772
                            {
694
                            if (retVal == null || retVal.length() == 0) {
773
                                IProxyDiagram proxyDiagram = aNode.getDiagram();
695
                                String key = proxyDiagram.getFilename();
774
                                if ( proxyDiagram != null )
696
                                retVal = mDiagramNodeMap.get(key);
775
                                {
776
                                    retVal = proxyDiagram.getXMIID();
777
                                }
778
                                
779
                                if (retVal == null || retVal.length() == 0)
780
                                {
781
                                    String key = proxyDiagram.getFilename();
782
                                    retVal = mDiagramNodeMap.get(key);
783
                                }
784
                            }
697
                            }
785
                        }
698
                        }
786
                    }
699
                    }
787
                }
700
                }
788
            }
701
            }
789
            
790
            return ((retVal == null || retVal.length() == 0) ? 
791
                (node.getName() + '#' + node.getType()) : retVal);
792
        }
702
        }
793
	
703
794
	/**
704
        return ((retVal == null || retVal.length() == 0)
795
         * Add a new node to the models data structure.
705
                ? (node.getName() + '#' + node.getType()) : retVal);
796
         *
706
    }
797
         * @param node The node to manage.
707
798
         */
708
    /**
799
        public void addNode(ITreeItem node)
709
     * Add a new node to the models data structure.
800
        {
710
     *
801
            if (node != null)
711
     * @param node The node to manage.
802
            {
712
     */
803
                String key = getNodeKey(node);
713
    public void addNode(ITreeItem node) {
804
                addNode(key, node);
714
        if (node != null) {
805
            }
715
            String key = getNodeKey(node);
716
            addNode(key, node);
806
        }
717
        }
807
	
718
    }
808
	/**
719
809
	 * Add a new node to the models data structure.  The node will be
720
    /**
810
	 * associated with the specified key.
721
     * Add a new node to the models data structure.  The node will be
811
	 *
722
     * associated with the specified key.
812
	 * @param node The node to manage.
723
     *
813
	 * @param key The key to associate with the node.
724
     * @param node The node to manage.
814
	 */
725
     * @param key The key to associate with the node.
815
	protected void addNode(String key, ITreeItem node)
726
     */
816
        {
727
    protected void addNode(String key, ITreeItem node) {
817
            if ((node != null) && (key != null))
728
        if ((node != null) && (key != null)) {
818
            {
729
            if (node instanceof ITreeDiagram) {
819
                if (node instanceof ITreeDiagram)
730
                ITreeDiagram diagramNode = (ITreeDiagram) node;
820
                {
731
                IProxyDiagram diagram = diagramNode.getDiagram();
821
                    ITreeDiagram diagramNode = (ITreeDiagram)node;
732
822
                    IProxyDiagram diagram = diagramNode.getDiagram();
733
                if (diagram != null) {
823
                    
734
                    String filename = diagram.getFilename();
824
                    if (diagram != null)
735
                    mDiagramNodeMap.put(filename, key);
825
                    {
736
826
                        String filename = diagram.getFilename();
737
                    // cvc - 6294480 (start)
827
                        mDiagramNodeMap.put(filename, key);
738
                    // if Diagrams node is expanded before Model node, things
828
                        
739
                    // get out of whack and diagram nodes don't get removed
829
                        // cvc - 6294480 (start)
740
                    // when deleted.
830
                        // if Diagrams node is expanded before Model node, things
831
                        // get out of whack and diagram nodes don't get removed
832
                        // when deleted.
833
//                        UMLModelRootNode modelRootNode = getModelRootNode(node);
741
//                        UMLModelRootNode modelRootNode = getModelRootNode(node);
834
//                        
742
//                        
835
//                        if (modelRootNode != null && mDiagramsNodeMap != null)
743
//                        if (modelRootNode != null && mDiagramsNodeMap != null)
Lines 847-875 Link Here
847
//                                diagramsNode.addChild(nodeCopy);
755
//                                diagramsNode.addChild(nodeCopy);
848
//                            }
756
//                            }
849
//                        }
757
//                        }
850
                        // cvc - 6294480 (end)
758
                    // cvc - 6294480 (end)
851
                    }
852
                }
853
                
854
                // I've seen a lot of null reference in the the nodeList; thus 
855
                // adding a null check to prevent storing null values in nodeList
856
                if (node != null) 
857
                {
858
                    ETList<WeakReference<ITreeItem>> nodeList = mNodeMap.get(key);
859
                    if (nodeList == null)
860
                    {
861
                        nodeList = new ETArrayList<WeakReference<ITreeItem>>();
862
                        mNodeMap.put(key, nodeList);
863
                    }
864
                    nodeList.add(new WeakReference<ITreeItem>(node));
865
                }
759
                }
866
            }
760
            }
761
762
            // I've seen a lot of null reference in the the nodeList; thus
763
            // adding a null check to prevent storing null values in nodeList
764
            if (node != null) {
765
                ETList<WeakReference<ITreeItem>> nodeList = mNodeMap.get(key);
766
                if (nodeList == null) {
767
                    nodeList = new ETArrayList<WeakReference<ITreeItem>>();
768
                    mNodeMap.put(key, nodeList);
769
                }
770
                nodeList.add(new WeakReference<ITreeItem>(node));
771
            }
867
        }
772
        }
868
	
773
    }
774
869
//	public class DrawingAreaSink extends DrawingAreaEventsAdapter
775
//	public class DrawingAreaSink extends DrawingAreaEventsAdapter
870
//        {
776
//        {
871
            // Moved the logic to create a diagram node under 
777
    // Moved the logic to create a diagram node under
872
            // Diagrams root node to ADProjectTreeEngine.addDiagramNode()
778
    // Diagrams root node to ADProjectTreeEngine.addDiagramNode()
873
//            public void onDrawingAreaPostCreated(
779
//            public void onDrawingAreaPostCreated(
874
//                    IDrawingAreaControl pDiagramControl,
780
//                    IDrawingAreaControl pDiagramControl,
875
//                    IResultCell cell)
781
//                    IResultCell cell)
Lines 904-963 Link Here
904
//                }
810
//                }
905
//            }
811
//            }
906
//        }
812
//        }
907
                    
813
    /* (non-Javadoc)
908
   /* (non-Javadoc)
814
     * @see org.netbeans.modules.uml.core.scm.ISCMEventsSink#onPreFeatureExecuted(int, org.netbeans.modules.uml.core.scm.ISCMItemGroup, org.netbeans.modules.uml.core.scm.ISCMOptions, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
909
    * @see org.netbeans.modules.uml.core.scm.ISCMEventsSink#onPreFeatureExecuted(int, org.netbeans.modules.uml.core.scm.ISCMItemGroup, org.netbeans.modules.uml.core.scm.ISCMOptions, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
815
     */
910
    */
816
    public void onPreFeatureExecuted(
911
	public void onPreFeatureExecuted(
817
            int kind, ISCMItemGroup Group, ISCMOptions pOptions, IResultCell cell) {
912
		int kind, ISCMItemGroup Group, ISCMOptions pOptions, IResultCell cell){}
818
    }
913
	
819
914
	/* (non-Javadoc)
820
    /* (non-Javadoc)
915
	 * @see org.netbeans.modules.uml.core.scm.ISCMEventsSink#onFeatureExecuted(int, org.netbeans.modules.uml.core.scm.ISCMItemGroup, org.netbeans.modules.uml.core.scm.ISCMOptions, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
821
     * @see org.netbeans.modules.uml.core.scm.ISCMEventsSink#onFeatureExecuted(int, org.netbeans.modules.uml.core.scm.ISCMItemGroup, org.netbeans.modules.uml.core.scm.ISCMOptions, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
916
	 */
822
     */
917
	public void onFeatureExecuted(
823
    public void onFeatureExecuted(
918
		int kind, ISCMItemGroup group, ISCMOptions pOptions, IResultCell cell)
824
            int kind, ISCMItemGroup group, ISCMOptions pOptions, IResultCell cell) {
919
	{
825
        ETList<ITreeItem> treeElements = new ETArrayList<ITreeItem>();
920
		ETList<ITreeItem> treeElements = new ETArrayList<ITreeItem>();
826
921
		
827
        if (group != null) {
922
		if (group != null)
828
            for (int i = 0; i < group.getCount(); i++) {
923
		{
829
                ISCMItem item = group.item(i);
924
			for (int i=0; i < group.getCount(); i++)
830
925
			{
831
                if (item instanceof ISCMElementItem) {
926
				ISCMItem item = group.item(i);
832
                    ISCMElementItem elementItem = (ISCMElementItem) item;
927
				
833
                    treeElements = findNodes(elementItem.getElement());
928
				if (item instanceof ISCMElementItem)
834
                    Iterator<ITreeItem> iter = treeElements.iterator();
929
				{
835
930
					ISCMElementItem  elementItem = (ISCMElementItem)item;
836
                    while (iter.hasNext() == true) {
931
					treeElements = findNodes(elementItem.getElement());
837
                        ITreeItem treeElement = iter.next();
932
					Iterator<ITreeItem> iter = treeElements.iterator();
838
                        treeElement.vcsFeatureExecuted(kind);
933
					
839
                    }
934
					while (iter.hasNext() == true)
840
                }
935
					{
841
936
						ITreeItem treeElement = iter.next();
842
                if (item instanceof ISCMDiagramItem) {
937
						treeElement.vcsFeatureExecuted(kind);
843
                    ISCMDiagramItem diagramItem = (ISCMDiagramItem) item;
938
					}
844
                    treeElements = findDiagramNodes(diagramItem.getFileName());
939
				}
845
                    Iterator<ITreeItem> iter = treeElements.iterator();
940
				
846
941
				if (item instanceof ISCMDiagramItem)
847
                    while (iter.hasNext() == true) {
942
				{
848
                        ITreeItem treeElement = iter.next();
943
					ISCMDiagramItem  diagramItem = (ISCMDiagramItem)item;
849
                        if (kind == SCMFeatureKind.FK_REMOVE_FROM_SOURCE_CONTROL) {
944
					treeElements = findDiagramNodes(diagramItem.getFileName());
850
                            ITreeItem parentItem = treeElement.getParentItem();
945
					Iterator<ITreeItem> iter = treeElements.iterator();
851
                            parentItem.removeChild(treeElement);
946
					
852
                        } else {
947
					while (iter.hasNext() == true)
853
                            treeElement.vcsFeatureExecuted(kind);
948
					{
854
                        }
949
						ITreeItem treeElement = iter.next();
855
                    }
950
						if (kind == SCMFeatureKind.FK_REMOVE_FROM_SOURCE_CONTROL)
856
                }
951
						{
857
            }
952
							ITreeItem parentItem = treeElement.getParentItem();
858
        }
953
							parentItem.removeChild(treeElement);
859
    }
954
						}
955
						
956
						else
957
							treeElement.vcsFeatureExecuted(kind);
958
					}
959
				}
960
			}
961
		}
962
	}
963
}
860
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/UMLCustomizerProvider.java (-6 / +2 lines)
Lines 41-56 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui;
44
package org.netbeans.modules.uml.project.ui;
46
45
47
import org.netbeans.spi.project.ui.CustomizerProvider;
46
import org.netbeans.spi.project.ui.CustomizerProvider;
48
47
49
public class UMLCustomizerProvider implements CustomizerProvider
48
public class UMLCustomizerProvider implements CustomizerProvider {
50
{
51
49
52
    public void showCustomizer()
50
    public void showCustomizer() {
53
    {
54
    }
51
    }
55
56
}
52
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/UMLUserInterface.java (-286 / +241 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui;
44
package org.netbeans.modules.uml.project.ui;
46
45
47
import java.awt.Component;
46
import java.awt.Component;
Lines 55-61 Link Here
55
import java.net.URL;
54
import java.net.URL;
56
import javax.swing.SwingUtilities;
55
import javax.swing.SwingUtilities;
57
import org.openide.util.ImageUtilities;
56
import org.openide.util.ImageUtilities;
58
import org.openide.util.Utilities;
59
import org.netbeans.modules.uml.ui.controls.newdialog.AddElementWizardIterator;
57
import org.netbeans.modules.uml.ui.controls.newdialog.AddElementWizardIterator;
60
import org.netbeans.modules.uml.ui.controls.newdialog.AddPackageWizardIterator;
58
import org.netbeans.modules.uml.ui.controls.newdialog.AddPackageWizardIterator;
61
import org.openide.DialogDisplayer;
59
import org.openide.DialogDisplayer;
Lines 79-379 Link Here
79
 * @author Trey Spiva
77
 * @author Trey Spiva
80
 * @author Craig Conover, craig.conover@sun.com
78
 * @author Craig Conover, craig.conover@sun.com
81
 */
79
 */
82
public class UMLUserInterface 
80
public class UMLUserInterface
83
      implements IProxyUserInterface, INewUMLFileTemplates
81
        implements IProxyUserInterface, INewUMLFileTemplates {
84
{
82
85
	
83
    /**
86
	/**
84
     *
87
	 *
85
     */
88
	 */
86
    public UMLUserInterface() {
89
	public UMLUserInterface()
87
        super();
90
	{
88
    }
91
		super();
89
92
	}
90
    /* (non-Javadoc)
93
	
91
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#getWindowHandle()
94
   /* (non-Javadoc)
92
     */
95
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#getWindowHandle()
93
    public Frame getWindowHandle() {
96
	*/
94
        // 86994, in sdi mode, use the current activated TC instead of IDE
97
	public Frame getWindowHandle()
95
        // main window as the parent for the dialog
98
	{
96
        Component comp = WindowManager.getDefault().getRegistry().getActivated();
99
            // 86994, in sdi mode, use the current activated TC instead of IDE 
97
        Window window = null;
100
            // main window as the parent for the dialog
98
        if (comp != null) {
101
            Component comp = WindowManager.getDefault().getRegistry().getActivated();
99
            window = SwingUtilities.getWindowAncestor(comp);
102
            Window window = null;
100
        }
103
            if(comp!=null)window=SwingUtilities.getWindowAncestor(comp);
101
        if (window != null && window instanceof Frame) {
104
            if (window!=null && window instanceof Frame)
102
            return (Frame) window;
105
                return (Frame)window;
103
        } else {
106
            else
104
            // Since the WindowsManager.getMainWindow() can only be called from
107
            {
105
            // AWT event dispatch thread use the MainWindowRetriever class
108
                // Since the WindowsManager.getMainWindow() can only be called from
106
            // can be used to display the group.  However, the only time we need to
109
                // AWT event dispatch thread use the MainWindowRetriever class
107
            // execute the invokeAndWait is when we are currently not in the
110
                // can be used to display the group.  However, the only time we need to
108
            // AWT event dispatch thread.
111
                // execute the invokeAndWait is when we are currently not in the
109
            //
112
                // AWT event dispatch thread.
110
113
                //
111
            MainWindowRetriever retriever = new MainWindowRetriever();
114
                
112
            if (SwingUtilities.isEventDispatchThread() == true) {
115
                MainWindowRetriever retriever = new MainWindowRetriever();
113
                retriever.retrieveWindow();
116
                if(SwingUtilities.isEventDispatchThread() == true)
114
            } else {
117
                {
115
                try {
118
                    retriever.retrieveWindow();
116
                    SwingUtilities.invokeAndWait(retriever);
117
                } catch (InterruptedException e) {
118
                } catch (java.lang.reflect.InvocationTargetException ie) {
119
                }
119
                }
120
                else
121
                {
122
			try
123
			{
124
				SwingUtilities.invokeAndWait(retriever);
125
			}
126
			catch(InterruptedException e)
127
			{
128
			}
129
			catch(java.lang.reflect.InvocationTargetException ie)
130
			{
131
			}
132
		}
133
		
134
		return retriever.getMainWindow();
135
            }
120
            }
136
	}
121
137
	
122
            return retriever.getMainWindow();
138
	public class MainWindowRetriever implements Runnable
123
        }
139
	{
124
    }
140
		private Frame mMainWindow = null;
125
141
		
126
    public class MainWindowRetriever implements Runnable {
142
		public void run()
127
143
		{
128
        private Frame mMainWindow = null;
144
			retrieveWindow();
129
145
		}
130
        public void run() {
146
		
131
            retrieveWindow();
147
		public void retrieveWindow()
132
        }
148
		{
133
149
			mMainWindow = WindowManager.getDefault().getMainWindow();
134
        public void retrieveWindow() {
150
		}
135
            mMainWindow = WindowManager.getDefault().getMainWindow();
151
		
136
        }
152
		public Frame getMainWindow()
137
153
		{
138
        public Frame getMainWindow() {
154
			return mMainWindow;
139
            return mMainWindow;
155
		}
140
        }
156
	}
141
    }
157
	
142
158
	
143
    /* (non-Javadoc)
159
   /* (non-Javadoc)
144
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#dirtyStateChanged(org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram, boolean)
160
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#dirtyStateChanged(org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram, boolean)
145
     */
161
	*/
146
    public long dirtyStateChanged(IDiagram pDiagram, boolean bNewDirtyState) {
162
	public long dirtyStateChanged(IDiagram pDiagram, boolean bNewDirtyState)
147
        // TODO Auto-generated method stub
163
	{
148
        return 0;
164
		// TODO Auto-generated method stub
149
    }
165
		return 0;
150
166
	}
151
    /* (non-Javadoc)
167
	
152
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#quit()
168
   /* (non-Javadoc)
153
     */
169
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#quit()
154
    public void quit() {
170
	*/
155
        // TODO Auto-generated method stub
171
	public void quit()
156
    }
172
	{
157
173
		// TODO Auto-generated method stub
158
    /* (non-Javadoc)
174
		
159
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#setVisible(boolean)
175
	}
160
     */
176
	
161
    public void setVisible(boolean value) {
177
   /* (non-Javadoc)
162
    }
178
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#setVisible(boolean)
163
179
	*/
164
    /* (non-Javadoc)
180
	public void setVisible(boolean value)
165
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#getVisible()
181
	{
166
     */
182
		
167
    public boolean getVisible() {
183
	}
168
        return true;
184
	
169
    }
185
   /* (non-Javadoc)
170
186
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#getVisible()
171
    /* (non-Javadoc)
187
	*/
172
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#setPropertyEditorVisible(boolean)
188
	public boolean getVisible()
173
     */
189
	{
174
    public void setPropertyEditorVisible(boolean value) {
190
		return true;
175
        // TODO Auto-generated method stub
191
	}
176
    }
192
	
177
193
   /* (non-Javadoc)
178
    /* (non-Javadoc)
194
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#setPropertyEditorVisible(boolean)
179
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#getPropertyEditorVisible()
195
	*/
180
     */
196
	public void setPropertyEditorVisible(boolean value)
181
    public boolean getPropertyEditorVisible() {
197
	{
182
        // TODO Auto-generated method stub
198
		// TODO Auto-generated method stub
183
        return false;
199
		
184
    }
200
	}
185
201
	
186
    /* (non-Javadoc)
202
   /* (non-Javadoc)
187
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#openWorkspaceDialog()
203
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#getPropertyEditorVisible()
188
     */
204
	*/
189
    public void openWorkspaceDialog() {
205
	public boolean getPropertyEditorVisible()
190
        // TODO Auto-generated method stub
206
	{
191
    }
207
		// TODO Auto-generated method stub
192
208
		return false;
193
    /* (non-Javadoc)
209
	}
194
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#newWorkspaceDialog()
210
	
195
     */
211
   /* (non-Javadoc)
196
    public void newWorkspaceDialog() {
212
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#openWorkspaceDialog()
197
        // TODO Auto-generated method stub
213
	*/
198
    }
214
	public void openWorkspaceDialog()
199
215
	{
200
    /* (non-Javadoc)
216
		// TODO Auto-generated method stub
201
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#newPackageDialog(org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace)
217
		
202
     */
218
	}
203
    public IElement newPackageDialog(INamespace pDefaultNamespace) {
219
	
220
   /* (non-Javadoc)
221
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#newWorkspaceDialog()
222
	*/
223
	public void newWorkspaceDialog()
224
	{
225
		// TODO Auto-generated method stub
226
		
227
	}
228
	
229
   /* (non-Javadoc)
230
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#newPackageDialog(org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace)
231
	*/
232
	public IElement newPackageDialog(INamespace pDefaultNamespace)
233
	{
234
//		INewDialog diag = new NewDialog();
204
//		INewDialog diag = new NewDialog();
235
//		
205
//		
236
//		diag.addTab(NewDialogTabKind.NWIK_NEW_PACKAGE);
206
//		diag.addTab(NewDialogTabKind.NWIK_NEW_PACKAGE);
237
		
207
238
		INewDialogPackageDetails details = new NewDialogPackageDetails();
208
        INewDialogPackageDetails details = new NewDialogPackageDetails();
239
		
209
240
		details.setAllowFromRESelection( false );
210
        details.setAllowFromRESelection(false);
241
		details.setNamespace( pDefaultNamespace );
211
        details.setNamespace(pDefaultNamespace);
242
//		diag.specifyDefaults( details );
212
//		diag.specifyDefaults( details );
243
		
213
244
//		diag.display( null );
214
//		diag.display( null );
245
                //Jyothi:
215
        //Jyothi:
246
                WizardDescriptor.Iterator iterator = new AddPackageWizardIterator();
216
        WizardDescriptor.Iterator iterator = new AddPackageWizardIterator();
247
                WizardDescriptor wizardDescriptor = new WizardDescriptor(iterator);
217
        WizardDescriptor wizardDescriptor = new WizardDescriptor(iterator);
248
                // {0} will be replaced by WizardDescriptor.Panel.getComponent().getName()
218
        // {0} will be replaced by WizardDescriptor.Panel.getComponent().getName()
249
                // {1} will be replaced by WizardDescriptor.Iterator.name()
219
        // {1} will be replaced by WizardDescriptor.Iterator.name()
250
                //wizardDescriptor.setTitleFormat(new MessageFormat("{0} ({1})"));
220
        //wizardDescriptor.setTitleFormat(new MessageFormat("{0} ({1})"));
251
                wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
221
        wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
252
                wizardDescriptor.setTitle(org.openide.util.NbBundle.getMessage(UMLUserInterface.class, "IDS_NEW_PACKAGE_WIZARD_TITLE"));
222
        wizardDescriptor.setTitle(org.openide.util.NbBundle.getMessage(UMLUserInterface.class, "IDS_NEW_PACKAGE_WIZARD_TITLE"));
253
                wizardDescriptor.putProperty(PACKAGE_DETAILS, details);
223
        wizardDescriptor.putProperty(PACKAGE_DETAILS, details);
254
                
255
                Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
256
                dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UMLUserInterface.class, "IDS_NEW_PACKAGE_WIZARD_TITLE_DESCRIPTION"));
257
                dialog.setVisible(true);
258
                dialog.toFront();
259
                boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
260
                if (!cancelled) {
261
                    Object results = wizardDescriptor.getProperty(PACKAGE_DETAILS);                                        
262
                    
263
                    if( results != null && results instanceof NewDialogPackageDetails) {
264
                        NewDialogPackageDetails packResults = (NewDialogPackageDetails)results;
265
224
266
                        INewDialogResultProcessor processor = new NewDialogResultProcessor();
225
        Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
267
                        return processor.handleResult( packResults );         
226
        dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UMLUserInterface.class, "IDS_NEW_PACKAGE_WIZARD_TITLE_DESCRIPTION"));
268
                    }
227
        dialog.setVisible(true);
269
                }
228
        dialog.toFront();
270
                return null;
229
        boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
271
	}
230
        if (!cancelled) {
272
	
231
            Object results = wizardDescriptor.getProperty(PACKAGE_DETAILS);
273
   /* (non-Javadoc)
232
274
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#newElementDialog(org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace)
233
            if (results != null && results instanceof NewDialogPackageDetails) {
275
	*/
234
                NewDialogPackageDetails packResults = (NewDialogPackageDetails) results;
276
	public IElement newElementDialog(INamespace pDefaultNamespace)
235
277
	{
236
                INewDialogResultProcessor processor = new NewDialogResultProcessor();
237
                return processor.handleResult(packResults);
238
            }
239
        }
240
        return null;
241
    }
242
243
    /* (non-Javadoc)
244
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#newElementDialog(org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace)
245
     */
246
    public IElement newElementDialog(INamespace pDefaultNamespace) {
278
//		INewDialog diag = new NewDialog();
247
//		INewDialog diag = new NewDialog();
279
//		diag.addTab(NewDialogTabKind.NWIK_NEW_ELEMENT);
248
//		diag.addTab(NewDialogTabKind.NWIK_NEW_ELEMENT);
280
		
249
281
		INewDialogElementDetails details = new NewDialogElementDetails();
250
        INewDialogElementDetails details = new NewDialogElementDetails();
282
		details.setNamespace(pDefaultNamespace);
251
        details.setNamespace(pDefaultNamespace);
283
		
252
284
//		diag.specifyDefaults(details); 
253
//		diag.specifyDefaults(details); 
285
                
254
286
                //jyothi:                
255
        //jyothi:
287
                WizardDescriptor.Iterator iterator = new AddElementWizardIterator();
256
        WizardDescriptor.Iterator iterator = new AddElementWizardIterator();
288
                WizardDescriptor wizardDescriptor = new WizardDescriptor(iterator);
257
        WizardDescriptor wizardDescriptor = new WizardDescriptor(iterator);
289
                // {0} will be replaced by WizardDescriptor.Panel.getComponent().getName()
258
        // {0} will be replaced by WizardDescriptor.Panel.getComponent().getName()
290
                // {1} will be replaced by WizardDescriptor.Iterator.name()
259
        // {1} will be replaced by WizardDescriptor.Iterator.name()
291
                //wizardDescriptor.setTitleFormat(new MessageFormat("{0} ({1})")); 
260
        //wizardDescriptor.setTitleFormat(new MessageFormat("{0} ({1})"));
292
                wizardDescriptor.setTitleFormat(new MessageFormat("{0}")); 
261
        wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
293
                wizardDescriptor.setTitle(org.openide.util.NbBundle.getMessage(UMLUserInterface.class, "IDS_NEW_ELEMENT_WIZARD_TITLE"));
262
        wizardDescriptor.setTitle(org.openide.util.NbBundle.getMessage(UMLUserInterface.class, "IDS_NEW_ELEMENT_WIZARD_TITLE"));
294
                wizardDescriptor.putProperty(ELEMENT_DETAILS, details);
263
        wizardDescriptor.putProperty(ELEMENT_DETAILS, details);
295
                Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
264
        Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
296
                dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UMLUserInterface.class, "IDS_NEW_ELEMENT_WIZARD_TITLE_DESCRIPTION"));
265
        dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UMLUserInterface.class, "IDS_NEW_ELEMENT_WIZARD_TITLE_DESCRIPTION"));
297
                dialog.setVisible(true);
266
        dialog.setVisible(true);
298
                dialog.toFront();
267
        dialog.toFront();
299
                boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
268
        boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
300
                if (!cancelled) {
269
        if (!cancelled) {
301
                    // do something
270
            // do something
302
                    Object obj = wizardDescriptor.getProperty(ELEMENT_DETAILS);
271
            Object obj = wizardDescriptor.getProperty(ELEMENT_DETAILS);
303
                    if (obj instanceof INewDialogElementDetails ) {
272
            if (obj instanceof INewDialogElementDetails) {
304
                        INewDialogElementDetails elementResults = (INewDialogElementDetails)obj;
273
                INewDialogElementDetails elementResults = (INewDialogElementDetails) obj;
305
                        if (elementResults != null) {
274
                if (elementResults != null) {
306
                            INewDialogResultProcessor processor = new NewDialogResultProcessor();
275
                    INewDialogResultProcessor processor = new NewDialogResultProcessor();
307
                            return processor.handleResult(elementResults);
276
                    return processor.handleResult(elementResults);
308
                        }
309
                    }                
310
                }
277
                }
311
                return null;                
278
            }
312
        }
279
        }
313
	
280
        return null;
314
   /* (non-Javadoc)
281
    }
315
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#closeWorkspace()
282
316
	*/
283
    /* (non-Javadoc)
317
	public void closeWorkspace()
284
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#closeWorkspace()
318
	{
285
     */
319
		// TODO Auto-generated method stub
286
    public void closeWorkspace() {
320
		
287
        // TODO Auto-generated method stub
321
	}
288
    }
322
	
289
323
   /* (non-Javadoc)
290
    /* (non-Javadoc)
324
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#closeProject(org.netbeans.modules.uml.core.metamodel.structure.IProject)
291
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#closeProject(org.netbeans.modules.uml.core.metamodel.structure.IProject)
325
	*/
292
     */
326
	public void closeProject(IProject pProject)
293
    public void closeProject(IProject pProject) {
327
	{
294
        // TODO Auto-generated method stub
328
		// TODO Auto-generated method stub
295
    }
329
		
296
330
	}
297
    /* (non-Javadoc)
331
	
298
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#setDisableContextMenu(boolean)
332
   /* (non-Javadoc)
299
     */
333
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#setDisableContextMenu(boolean)
300
    public void setDisableContextMenu(boolean value) {
334
	*/
301
        // TODO Auto-generated method stub
335
	public void setDisableContextMenu(boolean value)
302
    }
336
	{
303
337
		// TODO Auto-generated method stub
304
    /* (non-Javadoc)
338
		
305
     * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#getDisableContextMenu()
339
	}
306
     */
340
	
307
    public boolean getDisableContextMenu() {
341
   /* (non-Javadoc)
308
        // TODO Auto-generated method stub
342
	* @see org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface#getDisableContextMenu()
309
        return false;
343
	*/
310
    }
344
	public boolean getDisableContextMenu()
311
345
	{
312
    /**
346
		// TODO Auto-generated method stub
313
     * Uses NetBeans to display the URL.
347
		return false;
314
     */
348
	}
315
    public void displayInBrowser(URL url) {
349
	
316
        HtmlBrowser.URLDisplayer displayer = HtmlBrowser.URLDisplayer.getDefault();
350
	/**
317
        displayer.showURL(url);
351
	 * Uses NetBeans to display the URL.
318
    }
352
	 */
319
353
	public void displayInBrowser(URL url)
320
    public Image getResource(String iconLocation) {
354
	{
321
        Image retVal = null;
355
		HtmlBrowser.URLDisplayer displayer = HtmlBrowser.URLDisplayer.getDefault();
322
356
		displayer.showURL(url);
323
        try {
357
	}
324
            retVal = ImageUtilities.loadImage(iconLocation);
358
	
325
        } catch (Exception e) {
359
	public Image getResource(String iconLocation)
326
            URL url = this.getClass().getClassLoader().getResource(iconLocation);
360
	{
327
            if (url != null) {
361
		Image retVal = null;
328
                retVal = Toolkit.getDefaultToolkit().createImage(url);
362
		
329
            }
363
		try
330
        }
364
		{
331
365
			retVal = ImageUtilities.loadImage(iconLocation);
332
        return retVal;
366
		}
333
    }
367
		catch(Exception e)
368
		{
369
			URL url = this.getClass().getClassLoader().getResource(iconLocation);
370
			if(url != null)
371
			{
372
				retVal = Toolkit.getDefaultToolkit().createImage(url);
373
			}
374
		}
375
		
376
		return retVal;
377
	}
378
	
379
}
334
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/common/AddJavaProjectAction.java (-206 / +163 lines)
Lines 41-51 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.common;
44
package org.netbeans.modules.uml.project.ui.common;
46
45
47
import java.util.LinkedList;
46
import java.util.LinkedList;
48
import java.util.ArrayList;
49
import java.util.List;
47
import java.util.List;
50
import java.util.Set;
48
import java.util.Set;
51
import org.netbeans.api.project.Project;
49
import org.netbeans.api.project.Project;
Lines 68-159 Link Here
68
import org.openide.util.actions.CookieAction;
66
import org.openide.util.actions.CookieAction;
69
import org.openide.util.lookup.Lookups;
67
import org.openide.util.lookup.Lookups;
70
68
71
import org.netbeans.api.project.ant.AntArtifact;
72
import org.netbeans.api.project.ant.AntArtifactQuery;
73
import java.util.Arrays;
74
import java.util.Iterator;
75
import org.netbeans.modules.uml.core.support.Debug;
76
69
77
// this would create module dependency so I am avoiding for now
70
// this would create module dependency so I am avoiding for now
78
//import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer;
71
//import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer;
79
80
/**
72
/**
81
 * Action that allows selection of the Java project to associate with UML project
73
 * Action that allows selection of the Java project to associate with UML project
82
 * @author Mike Frisino
74
 * @author Mike Frisino
83
 */
75
 */
84
public class AddJavaProjectAction extends CookieAction
76
public class AddJavaProjectAction extends CookieAction {
85
{
77
86
	
87
    // TODO - MXF 
78
    // TODO - MXF 
88
    // this class is currently not being used at all. 
79
    // this class is currently not being used at all. 
89
    // It can be removed and nothing will break.
80
    // It can be removed and nothing will break.
90
91
    // I leave it in merely as an example of code that could be used if we
81
    // I leave it in merely as an example of code that could be used if we
92
    // wanted to have an ACTION as well as the customizer.
82
    // wanted to have an ACTION as well as the customizer.
93
    // This was modeled on similar Add action in the J2EE project. Ask
83
    // This was modeled on similar Add action in the J2EE project. Ask
94
    // Chris Webster if you have questions. He is the one that pointed it out
84
    // Chris Webster if you have questions. He is the one that pointed it out
95
    // to me.
85
    // to me.
86
    private static final Class[] COOKIE_ARRAY =
87
            new Class[]{UMLProjectProperties.class};
96
88
97
    private static final Class[] COOKIE_ARRAY =
89
    public Class[] cookieClasses() {
98
        new Class[] {UMLProjectProperties.class};
99
    
100
    public Class[] cookieClasses() 
101
    {
102
        return COOKIE_ARRAY;
90
        return COOKIE_ARRAY;
103
    }
91
    }
104
    
92
105
    public int mode() 
93
    public int mode() {
106
    {
107
        return CookieAction.MODE_EXACTLY_ONE;
94
        return CookieAction.MODE_EXACTLY_ONE;
108
    }
95
    }
109
    
96
110
    public void performAction(Node[] activeNodes) 
97
    public void performAction(Node[] activeNodes) {
111
	{
98
        /* NB60TBD
112
		    /* NB60TBD
113
        try 
99
        try 
114
		{
100
        {
115
            UMLProjectProperties epp = 
101
        UMLProjectProperties epp =
116
                (UMLProjectProperties) activeNodes[0].getCookie(
102
        (UMLProjectProperties) activeNodes[0].getCookie(
117
                    UMLProjectProperties.class);
103
        UMLProjectProperties.class);
118
            
104
119
            Project targetProject = getSelectedJavaProject(epp);
105
        Project targetProject = getSelectedJavaProject(epp);
120
         
106
121
            // epp.addJ2eeSubprojects(moduleProjects);
107
        // epp.addJ2eeSubprojects(moduleProjects);
122
            // Debug.out.println("MCF - todo");
108
        // Debug.out.println("MCF - todo");
123
        }
109
        }
124
		
110
125
		catch (UserCancelException uce) 
111
        catch (UserCancelException uce)
126
        {
112
        {
127
            // this action has been cancelled
113
        // this action has been cancelled
128
        }
114
        }
129
		    */
115
         */
130
    }
116
    }
131
    
117
132
    public String getName() 
118
    public String getName() {
133
    {
134
        return NbBundle.getMessage(
119
        return NbBundle.getMessage(
135
            AddJavaProjectAction.class, "LBL_AddJavaProjectAction");
120
                AddJavaProjectAction.class, "LBL_AddJavaProjectAction");
136
    }
121
    }
137
    
122
138
    public HelpCtx getHelpCtx() 
123
    public HelpCtx getHelpCtx() {
139
    {
140
        return HelpCtx.DEFAULT_HELP;
124
        return HelpCtx.DEFAULT_HELP;
141
        // If you will provide context help then use:
125
        // If you will provide context help then use:
142
        // return new HelpCtx(AddModuleAction.class);
126
        // return new HelpCtx(AddModuleAction.class);
143
    }
127
    }
144
    
128
145
    protected boolean asynchronous() 
129
    protected boolean asynchronous() {
146
    {
147
        // performAction() should run in event thread
130
        // performAction() should run in event thread
148
        return false;
131
        return false;
149
    }
132
    }
150
    
133
151
    public static Project getSelectedJavaProject(UMLProjectProperties epp) 
134
    public static Project getSelectedJavaProject(UMLProjectProperties epp)
152
        throws UserCancelException 
135
            throws UserCancelException {
153
    {
154
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
136
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
155
        List moduleProjectNodes = new LinkedList();
137
        List moduleProjectNodes = new LinkedList();
156
        
138
157
        // Filter out the inappropriate projects
139
        // Filter out the inappropriate projects
158
        // TODO - complete filtering to best of ability
140
        // TODO - complete filtering to best of ability
159
        // eliminate other uml projects - UMLActionProvider
141
        // eliminate other uml projects - UMLActionProvider
Lines 162-413 Link Here
162
        // ?? others?
144
        // ?? others?
163
        for (int i = 0; i < allProjects.length; i++) {
145
        for (int i = 0; i < allProjects.length; i++) {
164
            if (allProjects[i].getLookup().lookup(
146
            if (allProjects[i].getLookup().lookup(
165
                UMLActionProvider.class) == null )
147
                    UMLActionProvider.class) == null) // &&
166
                // &&
148
            // allProjects[i].getLookup().lookup(
167
                // allProjects[i].getLookup().lookup(
149
            // J2eeModuleContainer.class) == null)
168
                // J2eeModuleContainer.class) == null) 
169
            {
150
            {
170
                LogicalViewProvider lvp = (LogicalViewProvider) allProjects[i]
151
                LogicalViewProvider lvp = (LogicalViewProvider) allProjects[i].getLookup().lookup(LogicalViewProvider.class);
171
                    .getLookup().lookup(LogicalViewProvider.class);
152
172
                
173
                Node mn = lvp.createLogicalView();
153
                Node mn = lvp.createLogicalView();
174
                Node n = new FilterNode(mn, new FilterNode.Children(mn), 
154
                Node n = new FilterNode(mn, new FilterNode.Children(mn),
175
                    Lookups.singleton(allProjects[i]));
155
                        Lookups.singleton(allProjects[i]));
176
                
156
177
                moduleProjectNodes.add(n);
157
                moduleProjectNodes.add(n);
178
            }
158
            }
179
        }
159
        }
180
        Children.Array children = new Children.Array();
160
        Children.Array children = new Children.Array();
181
        children.add((Node[])moduleProjectNodes.toArray(
161
        children.add((Node[]) moduleProjectNodes.toArray(
182
            new Node[moduleProjectNodes.size()]));
162
                new Node[moduleProjectNodes.size()]));
183
        
163
184
        final Node root = new AbstractNode(children);
164
        final Node root = new AbstractNode(children);
185
        String moduleSelector = NbBundle.getMessage(
165
        String moduleSelector = NbBundle.getMessage(
186
            AddJavaProjectAction.class, 
166
                AddJavaProjectAction.class,
187
            "LBL_JavaProjectSelectorTitle"); // NOI18N
167
                "LBL_JavaProjectSelectorTitle"); // NOI18N
188
        
168
189
        UMLProject parent = epp.getProject();
169
        UMLProject parent = epp.getProject();
190
        SubprojectProvider spp = (SubprojectProvider)parent.getLookup()
170
        SubprojectProvider spp = (SubprojectProvider) parent.getLookup().lookup(SubprojectProvider.class);
191
            .lookup(SubprojectProvider.class);
171
192
        
172
        if (null != spp) {
193
        if (null != spp) 
194
        {
195
            final Set s = spp.getSubprojects();
173
            final Set s = spp.getSubprojects();
196
            NodeAcceptor na = new NodeAcceptor() 
174
            NodeAcceptor na = new NodeAcceptor() {
197
            {
175
198
                public boolean acceptNodes(Node[] nodes) 
176
                public boolean acceptNodes(Node[] nodes) {
199
                {
177
                    for (int i = 0; i < nodes.length; i++) {
200
                    for (int i = 0; i < nodes.length; i++) 
178
                        if (nodes[i].getParentNode() != root) {
201
                    {
202
                        if (nodes[i].getParentNode() != root) 
203
                            return false;
179
                            return false;
204
                       
180
                        }
181
205
                        // do not put this test befor the root test...
182
                        // do not put this test befor the root test...
206
                        Project p = (Project)nodes[i]
183
                        Project p = (Project) nodes[i].getLookup().lookup(Project.class);
207
                            .getLookup().lookup(Project.class);
184
208
                        
185
                        if (null == p) {
209
                        if (null == p)
210
                            return false;
186
                            return false;
211
                        
187
                        }
212
                        if (s.contains(p)) 
188
189
                        if (s.contains(p)) {
213
                            return false;
190
                            return false;
191
                        }
214
                    }
192
                    }
215
                    
193
216
                    return nodes.length > 0;
194
                    return nodes.length > 0;
217
                }
195
                }
218
            };
196
            };
219
            
197
220
            // TODO - modify to limit selection to 1
198
            // TODO - modify to limit selection to 1
221
            root.setDisplayName(NbBundle.getMessage(
199
            root.setDisplayName(NbBundle.getMessage(
222
                AddJavaProjectAction.class, "LBL_OpenProjects")); // NOI18N
200
                    AddJavaProjectAction.class, "LBL_OpenProjects")); // NOI18N
223
            
201
224
            Node[] selected = NodeOperation.getDefault().select(
202
            Node[] selected = NodeOperation.getDefault().select(
225
                moduleSelector, root.getDisplayName(), root, na);
203
                    moduleSelector, root.getDisplayName(), root, na);
226
            
204
227
            Project[] modules = new Project[selected.length];
205
            Project[] modules = new Project[selected.length];
228
            
206
229
            for (int i = 0; i < modules.length; i++) 
207
            for (int i = 0; i < modules.length; i++) {
230
            {
208
                modules[i] = (Project) selected[i].getLookup().lookup(Project.class);
231
                modules[i] = (Project) selected[i]
232
                    .getLookup().lookup(Project.class);
233
            }
209
            }
234
            return modules[0];
210
            return modules[0];
211
        } else {
212
            return null;
235
        }
213
        }
236
        
237
        else 
238
            return null;
239
    }
214
    }
240
  
215
241
    
242
    // This can be called from wizards when the current project does not
216
    // This can be called from wizards when the current project does not
243
    // yet exist. So it needs less filtering logic.
217
    // yet exist. So it needs less filtering logic.
244
    public static Project getSelectedJavaProject() throws UserCancelException
218
    public static Project getSelectedJavaProject() throws UserCancelException {
245
    {
246
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
219
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
247
        List moduleProjectNodes = new LinkedList();
220
        List moduleProjectNodes = new LinkedList();
248
        
221
249
        // Filter out the inappropriate projects
222
        // Filter out the inappropriate projects
250
        // TODO - complete filtering to best of ability
223
        // TODO - complete filtering to best of ability
251
        // eliminate other uml projects - UMLActionProvider
224
        // eliminate other uml projects - UMLActionProvider
252
        // eliminate ear projects - J2eeModuleContainer
225
        // eliminate ear projects - J2eeModuleContainer
253
        // eliminate current project - uml covered
226
        // eliminate current project - uml covered
254
        // ?? others?
227
        // ?? others?
255
        for (int i = 0; i < allProjects.length; i++)
228
        for (int i = 0; i < allProjects.length; i++) {
256
        {
257
            if (allProjects[i].getLookup().lookup(
229
            if (allProjects[i].getLookup().lookup(
258
                UMLActionProvider.class) == null)
230
                    UMLActionProvider.class) == null) // &&
259
                // &&
231
            // allProjects[i].getLookup().lookup(
260
                // allProjects[i].getLookup().lookup(
232
            //        J2eeModuleContainer.class) == null)
261
                //        J2eeModuleContainer.class) == null)
262
            {
233
            {
263
                LogicalViewProvider lvp =
234
                LogicalViewProvider lvp =
264
                    (LogicalViewProvider)allProjects[i].getLookup()
235
                        (LogicalViewProvider) allProjects[i].getLookup().lookup(LogicalViewProvider.class);
265
                    .lookup(LogicalViewProvider.class);
236
266
                
267
                Node mn = lvp.createLogicalView();
237
                Node mn = lvp.createLogicalView();
268
                Node n = new FilterNode(mn, new FilterNode.Children(mn),
238
                Node n = new FilterNode(mn, new FilterNode.Children(mn),
269
                    Lookups.singleton(allProjects[i]));
239
                        Lookups.singleton(allProjects[i]));
270
                
240
271
                moduleProjectNodes.add(n);
241
                moduleProjectNodes.add(n);
272
            }
242
            }
273
        }
243
        }
274
        
244
275
        Children.Array children = new Children.Array();
245
        Children.Array children = new Children.Array();
276
        children.add((Node[])moduleProjectNodes.toArray(
246
        children.add((Node[]) moduleProjectNodes.toArray(
277
            new Node[moduleProjectNodes.size()]));
247
                new Node[moduleProjectNodes.size()]));
278
        
248
279
        final Node root = new AbstractNode(children);
249
        final Node root = new AbstractNode(children);
280
        String moduleSelector = NbBundle.getMessage(
250
        String moduleSelector = NbBundle.getMessage(
281
            AddJavaProjectAction.class,
251
                AddJavaProjectAction.class,
282
            "LBL_JavaProjectSelectorTitle"); // NOI18N
252
                "LBL_JavaProjectSelectorTitle"); // NOI18N
283
        
253
284
        NodeAcceptor na = new NodeAcceptor()
254
        NodeAcceptor na = new NodeAcceptor() {
285
        {
255
286
            public boolean acceptNodes(Node[] nodes)
256
            public boolean acceptNodes(Node[] nodes) {
287
            {
257
                for (int i = 0; i < nodes.length; i++) {
288
                for (int i = 0; i < nodes.length; i++)
258
                    if (nodes[i].getParentNode() != root) {
289
                {
290
                    if (nodes[i].getParentNode() != root)
291
                        return false;
259
                        return false;
292
                    
260
                    }
261
293
                    // do not put this test befor the root test...
262
                    // do not put this test befor the root test...
294
                    Project p = (Project) nodes[i].getLookup()
263
                    Project p = (Project) nodes[i].getLookup().lookup(Project.class);
295
                    .lookup(Project.class);
264
296
                    
265
                    if (null == p) {
297
                    if (null == p)
298
                        return false;
266
                        return false;
267
                    }
299
                }
268
                }
300
                
269
301
                return nodes.length > 0;
270
                return nodes.length > 0;
302
            }
271
            }
303
        };
272
        };
304
        
273
305
        // TODO - modify to limit selection to 1
274
        // TODO - modify to limit selection to 1
306
        root.setDisplayName(NbBundle.getMessage(
275
        root.setDisplayName(NbBundle.getMessage(
307
            AddJavaProjectAction.class, "LBL_OpenProjects")); // NOI18N
276
                AddJavaProjectAction.class, "LBL_OpenProjects")); // NOI18N
308
        
277
309
        Node[] selected = NodeOperation.getDefault().select(
278
        Node[] selected = NodeOperation.getDefault().select(
310
            moduleSelector, root.getDisplayName(), root, na);
279
                moduleSelector, root.getDisplayName(), root, na);
311
        
280
312
        Project[] modules = new Project[selected.length];
281
        Project[] modules = new Project[selected.length];
313
        
282
314
        for (int i = 0; i < modules.length; i++)
283
        for (int i = 0; i < modules.length; i++) {
315
        {
284
            modules[i] = (Project) selected[i].getLookup().lookup(Project.class);
316
            modules[i] = (Project) selected[i]
317
                .getLookup().lookup(Project.class);
318
        }
285
        }
319
        
286
320
        return modules[0];
287
        return modules[0];
321
        
288
322
    }
289
    }
323
    
290
324
    
325
    public Project[] getSelectedUMLProjects(UMLProjectProperties epp)
291
    public Project[] getSelectedUMLProjects(UMLProjectProperties epp)
326
    throws UserCancelException
292
            throws UserCancelException {
327
    {
328
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
293
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
329
        List moduleProjectNodes = new LinkedList();
294
        List moduleProjectNodes = new LinkedList();
330
        
295
331
        // Filter out the inappropriate target projects
296
        // Filter out the inappropriate target projects
332
        // include non uml projects -  == UMLActionProvider
297
        // include non uml projects -  == UMLActionProvider
333
        // eliminate current project -  ?? TODO
298
        // eliminate current project -  ?? TODO
334
        for (int i = 0; i < allProjects.length; i++)
299
        for (int i = 0; i < allProjects.length; i++) {
335
        {
336
            if (allProjects[i].getLookup().lookup(
300
            if (allProjects[i].getLookup().lookup(
337
                UMLActionProvider.class) != null)
301
                    UMLActionProvider.class) != null) {
338
            {
339
                LogicalViewProvider lvp =
302
                LogicalViewProvider lvp =
340
                    (LogicalViewProvider) allProjects[i].getLookup()
303
                        (LogicalViewProvider) allProjects[i].getLookup().lookup(LogicalViewProvider.class);
341
                    .lookup(LogicalViewProvider.class);
304
342
                
343
                Node mn = lvp.createLogicalView();
305
                Node mn = lvp.createLogicalView();
344
                Node n = new FilterNode(mn, new FilterNode.Children(mn),
306
                Node n = new FilterNode(mn, new FilterNode.Children(mn),
345
                    Lookups.singleton(allProjects[i]));
307
                        Lookups.singleton(allProjects[i]));
346
                
308
347
                moduleProjectNodes.add(n);
309
                moduleProjectNodes.add(n);
348
            }
310
            }
349
        }
311
        }
350
        
312
351
        Children.Array children = new Children.Array();
313
        Children.Array children = new Children.Array();
352
        children.add((Node[])moduleProjectNodes.toArray(
314
        children.add((Node[]) moduleProjectNodes.toArray(
353
            new Node[moduleProjectNodes.size()]));
315
                new Node[moduleProjectNodes.size()]));
354
        
316
355
        final Node root = new AbstractNode(children);
317
        final Node root = new AbstractNode(children);
356
        String moduleSelector = NbBundle.getMessage(
318
        String moduleSelector = NbBundle.getMessage(
357
            AddJavaProjectAction.class,
319
                AddJavaProjectAction.class,
358
            "LBL_UMLProjectSelectorTitle"); // NOI18N
320
                "LBL_UMLProjectSelectorTitle"); // NOI18N
359
        
321
360
        // Now filter out those nodes which are already included in subproject list
322
        // Now filter out those nodes which are already included in subproject list
361
        UMLProject parent = epp.getProject();
323
        UMLProject parent = epp.getProject();
362
        SubprojectProvider spp = (SubprojectProvider)parent.getLookup()
324
        SubprojectProvider spp = (SubprojectProvider) parent.getLookup().lookup(SubprojectProvider.class);
363
        .lookup(SubprojectProvider.class);
325
364
        
326
        if (null != spp) {
365
        if (null != spp)
366
        {
367
            final Set s = spp.getSubprojects();
327
            final Set s = spp.getSubprojects();
368
            
328
369
            NodeAcceptor na = new NodeAcceptor()
329
            NodeAcceptor na = new NodeAcceptor() {
370
            {
330
371
                public boolean acceptNodes(Node[] nodes)
331
                public boolean acceptNodes(Node[] nodes) {
372
                {
332
                    for (int i = 0; i < nodes.length; i++) {
373
                    for (int i = 0; i < nodes.length; i++)
333
                        if (nodes[i].getParentNode() != root) {
374
                    {
375
                        if (nodes[i].getParentNode() != root)
376
                            return false;
334
                            return false;
377
                        
335
                        }
336
378
                        // do not put this test befor the root test...
337
                        // do not put this test befor the root test...
379
                        Project p = (Project) nodes[i].getLookup()
338
                        Project p = (Project) nodes[i].getLookup().lookup(Project.class);
380
                        .lookup(Project.class);
339
381
                        
340
                        if (null == p) {
382
                        if (null == p)
383
                            return false;
341
                            return false;
384
                        
342
                        }
385
                        if (s.contains(p))
343
344
                        if (s.contains(p)) {
386
                            return false;
345
                            return false;
346
                        }
387
                    }
347
                    }
388
                    
348
389
                    return nodes.length > 0;
349
                    return nodes.length > 0;
390
                }
350
                }
391
            };
351
            };
392
            
352
393
            root.setDisplayName(NbBundle.getMessage(
353
            root.setDisplayName(NbBundle.getMessage(
394
                AddJavaProjectAction.class, "LBL_OpenProjects")); // NOI18N
354
                    AddJavaProjectAction.class, "LBL_OpenProjects")); // NOI18N
395
            
355
396
            Node[] selected = NodeOperation.getDefault().select(
356
            Node[] selected = NodeOperation.getDefault().select(
397
                moduleSelector, root.getDisplayName(), root, na);
357
                    moduleSelector, root.getDisplayName(), root, na);
398
            
358
399
            Project[] modules = new Project[selected.length];
359
            Project[] modules = new Project[selected.length];
400
            
360
401
            for (int i = 0; i < modules.length; i++)
361
            for (int i = 0; i < modules.length; i++) {
402
            {
362
                modules[i] = (Project) selected[i].getLookup().lookup(Project.class);
403
                modules[i] = (Project) selected[i]
404
                    .getLookup().lookup(Project.class);
405
            }
363
            }
406
            
364
407
            return modules;
365
            return modules;
366
        } else {
367
            return new Project[0];
408
        }
368
        }
409
        
369
    }
410
        else
411
            return new Project[0];
412
    }    
413
}
370
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/common/CommonUiSupport.java (-90 / +77 lines)
Lines 41-145 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
package org.netbeans.modules.uml.project.ui.common;
44
45
45
package org.netbeans.modules.uml.project.ui.common;
46
import org.netbeans.modules.uml.project.UMLProject;
46
import org.netbeans.modules.uml.project.UMLProject;
47
import java.util.ResourceBundle;
47
import java.util.ResourceBundle;
48
import javax.swing.ComboBoxModel;
48
import javax.swing.ComboBoxModel;
49
import javax.swing.DefaultComboBoxModel;
49
import javax.swing.DefaultComboBoxModel;
50
import org.openide.util.NbBundle;
50
import org.openide.util.NbBundle;
51
51
52
53
/**
52
/**
54
 * Support class for uml common ui (wizard and customizer)
53
 * Support class for uml common ui (wizard and customizer)
55
 * @author mike frisino
54
 * @author mike frisino
56
 */
55
 */
57
public class CommonUiSupport
56
public class CommonUiSupport {
58
{
57
59
	
58
    // TODO - MCF - add the support for the Language Source Level
60
	// TODO - MCF - add the support for the Language Source Level
59
    // You can copy the source level code from J2SE if needed.
61
	// You can copy the source level code from J2SE if needed.
60
    // TODO - MCF - be careful, the Source Level should be unchangeable when in
62
	
61
    // Implementation mode - i.e. it should defer to the Source Level of the
63
	// TODO - MCF - be careful, the Source Level should be unchangeable when in
62
    // target Java project.
64
	// Implementation mode - i.e. it should defer to the Source Level of the
63
    // So really the only time the user should be able to 'select" the Source
65
	// target Java project.
64
    // level is in the case where the Mode is "Design".
66
	// So really the only time the user should be able to 'select" the Source 
65
    private CommonUiSupport() {
67
	// level is in the case where the Mode is "Design".
66
    }
68
	
67
69
	private CommonUiSupport()
68
    /**
70
	{
69
     * Creates {@link ComboBoxModel} of modeling modes
71
	}
70
     * @param modelingModeComboBoxModel the platform's model used for listenning
72
	
71
     * @param initialValue initial source level value
73
	/**
72
     * @return {@link ComboBoxModel} of {@link SpecificationVersion}
74
	 * Creates {@link ComboBoxModel} of modeling modes
73
     */
75
	 * @param modelingModeComboBoxModel the platform's model used for listenning
74
    public static ComboBoxModel createModelingModeComboBoxModel(
76
	 * @param initialValue initial source level value
75
            String initialValue) {
77
	 * @return {@link ComboBoxModel} of {@link SpecificationVersion}
76
78
	 */
77
        DefaultComboBoxModel model = new DefaultComboBoxModel(new String[]{
79
	public static ComboBoxModel createModelingModeComboBoxModel(
78
                    NbBundle.getMessage(CommonUiSupport.class,
80
		String initialValue)
79
                    "LBL_ProjectMode_Analysis"), // NOI18N
81
	{
80
                    NbBundle.getMessage(CommonUiSupport.class,
82
		
81
                    "LBL_ProjectMode_Design"), // NOI18N
83
		DefaultComboBoxModel model = new DefaultComboBoxModel(new String[]
82
                    NbBundle.getMessage(CommonUiSupport.class,
84
		{
83
                    "LBL_ProjectMode_Implementation") // NOI18N
85
			NbBundle.getMessage(CommonUiSupport.class,
84
                });
86
				"LBL_ProjectMode_Analysis"), // NOI18N
85
87
				NbBundle.getMessage(CommonUiSupport.class,
86
        if (initialValue == null) {
88
				"LBL_ProjectMode_Design"), // NOI18N
87
            // need to specify the translated string since all options in the
89
				NbBundle.getMessage(CommonUiSupport.class,
88
            //  combobox are translated already
90
				"LBL_ProjectMode_Implementation") // NOI18N
89
            // model.setSelectedItem(UMLProject.PROJECT_MODE_DEFAULT_STR);
91
		});
90
            model.setSelectedItem(NbBundle.getMessage(
92
		
91
                    CommonUiSupport.class, "LBL_ProjectMode_Analysis")); // NOI18N
93
		if (initialValue == null)
92
        } else {
94
		{
93
            model.setSelectedItem(initialValue);
95
			// need to specify the translated string since all options in the
94
        }
96
			//  combobox are translated already
95
97
			// model.setSelectedItem(UMLProject.PROJECT_MODE_DEFAULT_STR);
96
        return model;
98
			model.setSelectedItem(NbBundle.getMessage(
97
    }
99
				CommonUiSupport.class, "LBL_ProjectMode_Analysis")); // NOI18N
98
100
		}
99
    public static String getModeProgramName(String localizedName) {
101
		
100
        String retVal = UMLProject.PROJECT_MODE_IMPL_STR;
102
		else
101
103
			model.setSelectedItem(initialValue);
102
        ResourceBundle bundle = NbBundle.getBundle(CommonUiSupport.class);
104
		
103
105
		return model;
104
        if (localizedName.equals(
106
	}
105
                bundle.getString("LBL_ProjectMode_Analysis"))) // NOI18N
107
	
106
        {
108
	public static String getModeProgramName(String localizedName)
107
            retVal = UMLProject.PROJECT_MODE_ANALYSIS_STR;
109
	{
108
        } else if (localizedName.equals(
110
		String retVal = UMLProject.PROJECT_MODE_IMPL_STR;
109
                bundle.getString("LBL_ProjectMode_Design"))) // NOI18N
111
		
110
        {
112
		ResourceBundle bundle = NbBundle.getBundle(CommonUiSupport.class);
111
            retVal = UMLProject.PROJECT_MODE_DESIGN_STR;
113
		
112
        }
114
		if (localizedName.equals(
113
115
			bundle.getString("LBL_ProjectMode_Analysis"))) // NOI18N
114
        return retVal;
116
		{
115
    }
117
			retVal = UMLProject.PROJECT_MODE_ANALYSIS_STR;
116
118
		}
117
    /**
119
		
118
     * Creates {@link ComboBoxModel} of modeling modes
120
		else if (localizedName.equals(
119
     * @param modelingModeComboBoxModel the platform's model used for listenning
121
			bundle.getString("LBL_ProjectMode_Design"))) // NOI18N
120
     * @param initialValue initial source level value
122
		{
121
     * @return {@link ComboBoxModel} of {@link SpecificationVersion}
123
			retVal = UMLProject.PROJECT_MODE_DESIGN_STR;
122
     */
124
		}
123
    public static ComboBoxModel createModelingModeComboBoxModel() {
125
		
124
        return createModelingModeComboBoxModel(
126
		return retVal;
125
                // need to specify the translated string since all options in the
127
	}
126
                //  combobox are translated already
128
	
127
                // UMLProject.PROJECT_MODE_DEFAULT_STR);
129
	/**
128
                NbBundle.getMessage(
130
	 * Creates {@link ComboBoxModel} of modeling modes
129
                CommonUiSupport.class, "LBL_ProjectMode_Analysis")); // NOI18N
131
	 * @param modelingModeComboBoxModel the platform's model used for listenning
130
132
	 * @param initialValue initial source level value
131
    }
133
	 * @return {@link ComboBoxModel} of {@link SpecificationVersion}
134
	 */
135
	public static ComboBoxModel createModelingModeComboBoxModel()
136
	{
137
		return createModelingModeComboBoxModel(
138
			// need to specify the translated string since all options in the
139
			//  combobox are translated already
140
			// UMLProject.PROJECT_MODE_DEFAULT_STR);
141
			NbBundle.getMessage(
142
				CommonUiSupport.class, "LBL_ProjectMode_Analysis")); // NOI18N
143
		
144
	}
145
}
132
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/common/JavaSourceRootsUI.java (-195 / +143 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.common;
44
package org.netbeans.modules.uml.project.ui.common;
46
45
47
import java.awt.*;
46
import java.awt.*;
Lines 49-57 Link Here
49
import java.util.Set;
48
import java.util.Set;
50
import java.text.MessageFormat;
49
import java.text.MessageFormat;
51
import javax.swing.*;
50
import javax.swing.*;
52
import javax.swing.table.DefaultTableCellRenderer;
53
import javax.swing.table.DefaultTableModel;
51
import javax.swing.table.DefaultTableModel;
54
import javax.swing.table.TableCellRenderer;
55
52
56
import org.netbeans.api.project.FileOwnerQuery;
53
import org.netbeans.api.project.FileOwnerQuery;
57
import org.netbeans.api.project.Project;
54
import org.netbeans.api.project.Project;
Lines 62-81 Link Here
62
import org.netbeans.api.project.Sources;
59
import org.netbeans.api.project.Sources;
63
import org.openide.util.Lookup;
60
import org.openide.util.Lookup;
64
61
65
66
/** Handles adding, removing, reordering of source roots.
62
/** Handles adding, removing, reordering of source roots.
67
 *
63
 *
68
 * @author Mike Frisino
64
 * @author Mike Frisino
69
 */
65
 */
70
public class JavaSourceRootsUI
66
public class JavaSourceRootsUI {
71
{
67
72
    
73
    public static final int NUM_COLS = 3;
68
    public static final int NUM_COLS = 3;
74
    public static final int COL_INCLUDE_FLAG = 0;
69
    public static final int COL_INCLUDE_FLAG = 0;
75
    public static final int COL_SOURCE_GROUP = 1;
70
    public static final int COL_SOURCE_GROUP = 1;
76
    public static final int COL_SOURCE_GROUP_DISPLAY_NAME = 2;
71
    public static final int COL_SOURCE_GROUP_DISPLAY_NAME = 2;
77
    
72
78
    
79
    /*
73
    /*
80
     * MCF
74
     * MCF
81
     * ths version can be called from wizards when we have not yet constructed
75
     * ths version can be called from wizards when we have not yet constructed
Lines 84-98 Link Here
84
     *
78
     *
85
     */
79
     */
86
    public static JavaSourceRootsModel createModel(
80
    public static JavaSourceRootsModel createModel(
87
        ReferencedJavaProjectModel javaRefModel,
81
            ReferencedJavaProjectModel javaRefModel,
88
        DefaultListModel jsrm)
82
            DefaultListModel jsrm) {
89
    {
90
        Object[][] data = new Object[0][NUM_COLS];
83
        Object[][] data = new Object[0][NUM_COLS];
91
        SourceGroup[] sourceGroups = new SourceGroup[0];
84
        SourceGroup[] sourceGroups = new SourceGroup[0];
92
        Project javaProject = javaRefModel.getProject();
85
        Project javaProject = javaRefModel.getProject();
93
        
86
94
        if (javaRefModel.isBroken() || javaProject == null)
87
        if (javaRefModel.isBroken() || javaProject == null) {
95
        {
96
            // must handle the condition where the project is not available
88
            // must handle the condition where the project is not available
97
            // because it has not been mounted.
89
            // because it has not been mounted.
98
            // so we can't compare to actual mounts, we can only list the
90
            // so we can't compare to actual mounts, we can only list the
Lines 100-115 Link Here
100
            // abbreviated form.
92
            // abbreviated form.
101
            data = new Object[jsrm.getSize()][NUM_COLS];
93
            data = new Object[jsrm.getSize()][NUM_COLS];
102
            sourceGroups = new SourceGroup[jsrm.getSize()];
94
            sourceGroups = new SourceGroup[jsrm.getSize()];
103
            
95
104
            for (int i=0; i< jsrm.getSize(); i++)
96
            for (int i = 0; i < jsrm.getSize(); i++) {
105
            {
106
                data[i][COL_INCLUDE_FLAG] = Boolean.valueOf(true);
97
                data[i][COL_INCLUDE_FLAG] = Boolean.valueOf(true);
107
                
98
108
                Object obj = jsrm.getElementAt(i);
99
                Object obj = jsrm.getElementAt(i);
109
                if(obj instanceof SourceGroup)
100
                if (obj instanceof SourceGroup) {
110
                {
101
                    SourceGroup group = (SourceGroup) obj;
111
                    SourceGroup group = (SourceGroup)obj;
102
112
                    
113
                    // TODO figure out what to disply in the display name. It is
103
                    // TODO figure out what to disply in the display name. It is
114
                    // not knowable since the ref project is not mounted
104
                    // not knowable since the ref project is not mounted
115
                    data[i][COL_SOURCE_GROUP] = group.getRootFolder().getName();
105
                    data[i][COL_SOURCE_GROUP] = group.getRootFolder().getName();
Lines 117-318 Link Here
117
//                    sourceGroups[i] = (SourceGroup)jsrm.getElementAt(i);
107
//                    sourceGroups[i] = (SourceGroup)jsrm.getElementAt(i);
118
                }
108
                }
119
            }
109
            }
120
        }
110
        } else {
121
        
122
        else
123
        {
124
            // we are good, java proj is mounted, so we can compose
111
            // we are good, java proj is mounted, so we can compose
125
            // list against actual sources
112
            // list against actual sources
126
            Sources srcs =
113
            Sources srcs =
127
                (Sources)javaProject.getLookup().lookup(Sources.class);
114
                    (Sources) javaProject.getLookup().lookup(Sources.class);
128
            
115
129
            if (srcs == null)
116
            if (srcs == null) {
130
            {
131
                // TODO Do we need to do anything at this point?
117
                // TODO Do we need to do anything at this point?
132
                // yes, something is out of sync with old values and real srcs
118
                // yes, something is out of sync with old values and real srcs
133
                return new JavaSourceRootsModel(data, sourceGroups);
119
                return new JavaSourceRootsModel(data, sourceGroups);
134
            }
120
            }
135
            
121
136
            // now check for Java sources
122
            // now check for Java sources
137
            SourceGroup[] javaSrcGrps =
123
            SourceGroup[] javaSrcGrps =
138
                srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
124
                    srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
139
            
125
140
            data = new Object[javaSrcGrps.length][NUM_COLS];
126
            data = new Object[javaSrcGrps.length][NUM_COLS];
141
            sourceGroups = new SourceGroup[javaSrcGrps.length];
127
            sourceGroups = new SourceGroup[javaSrcGrps.length];
142
            
128
143
            if (javaSrcGrps.length == 0 && jsrm.getSize() == 0)
129
            if (javaSrcGrps.length == 0 && jsrm.getSize() == 0) {
144
            {
145
                // This is ok, this is a case where there are no src groups
130
                // This is ok, this is a case where there are no src groups
146
                // and there were none previously. It is not a good case
131
                // and there were none previously. It is not a good case
147
                // for the association b/t uml and java, but that is to
132
                // for the association b/t uml and java, but that is to
148
                // be handled elsewhere
133
                // be handled elsewhere
149
                return new JavaSourceRootsModel(data, sourceGroups);
134
                return new JavaSourceRootsModel(data, sourceGroups);
150
            }
135
            }
151
            
136
152
            if (javaSrcGrps.length == 0 || javaSrcGrps.length < jsrm.getSize())
137
            if (javaSrcGrps.length == 0 || javaSrcGrps.length < jsrm.getSize()) {
153
            {
154
                // TODO Do we need to do anything at this point?
138
                // TODO Do we need to do anything at this point?
155
                // yes, this is a problem because our jsrm suggests that there
139
                // yes, this is a problem because our jsrm suggests that there
156
                // were more src groups before? Where have they gone?
140
                // were more src groups before? Where have they gone?
157
                return new JavaSourceRootsModel(data, sourceGroups);
141
                return new JavaSourceRootsModel(data, sourceGroups);
158
            }
142
            }
159
            
143
160
            // Ok, this is the normative situation, now we go through
144
            // Ok, this is the normative situation, now we go through
161
            // and reconcile the list of prior selections with the
145
            // and reconcile the list of prior selections with the
162
            // available src groups
146
            // available src groups
163
            for (int i=0; i < javaSrcGrps.length; i++)
147
            for (int i = 0; i < javaSrcGrps.length; i++) {
164
            {
165
                // check to see if the group is already included in selc
148
                // check to see if the group is already included in selc
166
                
149
167
                if (jsrm.contains(javaSrcGrps[i].getName()))
150
                if (jsrm.contains(javaSrcGrps[i].getName())) {
168
                    data[i][COL_INCLUDE_FLAG] = Boolean.valueOf(true);
151
                    data[i][COL_INCLUDE_FLAG] = Boolean.valueOf(true);
169
                
152
                } else {
170
                else
171
                    data[i][COL_INCLUDE_FLAG] = Boolean.valueOf(false);
153
                    data[i][COL_INCLUDE_FLAG] = Boolean.valueOf(false);
172
                
154
                }
173
                
155
156
174
                data[i][COL_SOURCE_GROUP] =
157
                data[i][COL_SOURCE_GROUP] =
175
                    javaSrcGrps[i].getRootFolder().getName();
158
                        javaSrcGrps[i].getRootFolder().getName();
176
                
159
177
                data[i][COL_SOURCE_GROUP_DISPLAY_NAME] =
160
                data[i][COL_SOURCE_GROUP_DISPLAY_NAME] =
178
                    javaSrcGrps[i].getDisplayName();
161
                        javaSrcGrps[i].getDisplayName();
179
                
162
180
                sourceGroups[i] = javaSrcGrps[i];
163
                sourceGroups[i] = javaSrcGrps[i];
181
            }
164
            }
182
        }
165
        }
183
        
166
184
        return new JavaSourceRootsModel(data, sourceGroups);
167
        return new JavaSourceRootsModel(data, sourceGroups);
185
    }
168
    }
186
    
169
187
    
188
    // this is the version called from wizard
170
    // this is the version called from wizard
189
    public static JavaSourceRootsModel createModel(Project javaProject)
171
    public static JavaSourceRootsModel createModel(Project javaProject) {
190
    {
191
        Object[][] data = new Object[0][NUM_COLS];
172
        Object[][] data = new Object[0][NUM_COLS];
192
        SourceGroup[] sourceGroups = new SourceGroup[0];
173
        SourceGroup[] sourceGroups = new SourceGroup[0];
193
        Sources srcs = retrieveJavaProjectSources(javaProject);
174
        Sources srcs = retrieveJavaProjectSources(javaProject);
194
        
175
195
        if (srcs == null)
176
        if (srcs == null) {
196
            return new JavaSourceRootsModel(data);
177
            return new JavaSourceRootsModel(data);
197
        
178
        }
179
198
        SourceGroup[] javaSrcGrps = retrieveJavaProjectSourceGroups(srcs);
180
        SourceGroup[] javaSrcGrps = retrieveJavaProjectSourceGroups(srcs);
199
        
181
200
        data = new Object[javaSrcGrps.length][NUM_COLS];
182
        data = new Object[javaSrcGrps.length][NUM_COLS];
201
        sourceGroups = new SourceGroup[javaSrcGrps.length];
183
        sourceGroups = new SourceGroup[javaSrcGrps.length];
202
        
184
203
        for (int i=0; i< javaSrcGrps.length; i++)
185
        for (int i = 0; i < javaSrcGrps.length; i++) {
204
        {
205
            // check to see if the group is already included in selc
186
            // check to see if the group is already included in selc
206
            data[i][COL_INCLUDE_FLAG] = Boolean.valueOf(true);
187
            data[i][COL_INCLUDE_FLAG] = Boolean.valueOf(true);
207
            
188
208
            data[i][COL_SOURCE_GROUP] =
189
            data[i][COL_SOURCE_GROUP] =
209
                javaSrcGrps[i].getRootFolder().getName();
190
                    javaSrcGrps[i].getRootFolder().getName();
210
            
191
211
            data[i][COL_SOURCE_GROUP_DISPLAY_NAME] =
192
            data[i][COL_SOURCE_GROUP_DISPLAY_NAME] =
212
                javaSrcGrps[i].getDisplayName();
193
                    javaSrcGrps[i].getDisplayName();
213
            
194
214
            sourceGroups[i] = javaSrcGrps[i];
195
            sourceGroups[i] = javaSrcGrps[i];
215
        }
196
        }
216
        
197
217
        return new JavaSourceRootsModel(data, sourceGroups);
198
        return new JavaSourceRootsModel(data, sourceGroups);
218
    }
199
    }
219
200
220
    public static SourceGroup[] retrieveJavaProjectSourceGroups(final Sources srcs)
201
    public static SourceGroup[] retrieveJavaProjectSourceGroups(final Sources srcs) {
221
    {
222
        return srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
202
        return srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
223
    }
203
    }
224
204
225
    public static Sources retrieveJavaProjectSources(Project javaProject)
205
    public static Sources retrieveJavaProjectSources(Project javaProject) {
226
    {
206
        Lookup lookup = javaProject.getLookup();
227
        Lookup lookup=javaProject.getLookup();
207
        return (Sources) lookup.lookup(Sources.class);
228
        return (Sources)lookup.lookup(Sources.class);
229
    }
208
    }
230
    
209
231
    
210
    public static DefaultTableModel createEmptyModel() {
232
    public static DefaultTableModel createEmptyModel()
233
    {
234
        Object[][] data = new Object[0][NUM_COLS];
211
        Object[][] data = new Object[0][NUM_COLS];
235
        SourceGroup[] sourceGroups = new SourceGroup[0];
212
        SourceGroup[] sourceGroups = new SourceGroup[0];
236
        
213
237
        return new JavaSourceRootsModel(data, sourceGroups);
214
        return new JavaSourceRootsModel(data, sourceGroups);
238
    }
215
    }
239
    
216
240
    
217
    public static class JavaSourceRootsModel extends DefaultTableModel {
241
    public static class JavaSourceRootsModel extends DefaultTableModel
218
242
    {
243
        SourceGroup[] sourceGroups = null;
219
        SourceGroup[] sourceGroups = null;
244
        
245
        static String colCheck =
220
        static String colCheck =
246
            (NbBundle.getMessage(JavaSourceRootsUI.class,
221
                (NbBundle.getMessage(JavaSourceRootsUI.class,
247
            "LBL_SourceGroupsColCheck")); //NOI18N
222
                "LBL_SourceGroupsColCheck")); //NOI18N
248
        
249
        static String colCheckAlt =
223
        static String colCheckAlt =
250
            (NbBundle.getMessage(JavaSourceRootsUI.class,
224
                (NbBundle.getMessage(JavaSourceRootsUI.class,
251
            "LBL_SourceGroupsColCheckAlt")); //NOI18N
225
                "LBL_SourceGroupsColCheckAlt")); //NOI18N
252
        
253
        static String colGroupFolder =
226
        static String colGroupFolder =
254
            (NbBundle.getMessage(JavaSourceRootsUI.class,
227
                (NbBundle.getMessage(JavaSourceRootsUI.class,
255
            "LBL_SourceGroupsColFolder")); //NOI18N
228
                "LBL_SourceGroupsColFolder")); //NOI18N
256
        
257
        static String colGroupLabel =
229
        static String colGroupLabel =
258
            (NbBundle.getMessage(JavaSourceRootsUI.class,
230
                (NbBundle.getMessage(JavaSourceRootsUI.class,
259
            "LBL_SourceGroupsColLabel")); //NOI18N
231
                "LBL_SourceGroupsColLabel")); //NOI18N
260
        
232
261
        
233
        public JavaSourceRootsModel(Object[][] data) {
262
        public JavaSourceRootsModel(Object[][] data)
263
        {
264
            super(data, new Object[]{colCheck, colGroupFolder, colGroupLabel});
234
            super(data, new Object[]{colCheck, colGroupFolder, colGroupLabel});
265
        }
235
        }
266
        
236
267
        public JavaSourceRootsModel(Object[][] data, SourceGroup[] sourceGroups)
237
        public JavaSourceRootsModel(Object[][] data, SourceGroup[] sourceGroups) {
268
        {
269
            super(data, new Object[]{colCheck, colGroupFolder, colGroupLabel});
238
            super(data, new Object[]{colCheck, colGroupFolder, colGroupLabel});
270
            this.sourceGroups = sourceGroups;
239
            this.sourceGroups = sourceGroups;
271
        }
240
        }
272
        
241
273
        
242
        public boolean isCellEditable(int row, int column) {
274
        public boolean isCellEditable(int row, int column)
275
        {
276
            return column == 0;
243
            return column == 0;
277
        }
244
        }
278
        
245
279
        public Class getColumnClass(int columnIndex)
246
        public Class getColumnClass(int columnIndex) {
280
        {
247
            switch (columnIndex) {
281
            switch (columnIndex)
282
            {
283
                case JavaSourceRootsUI.COL_INCLUDE_FLAG:
248
                case JavaSourceRootsUI.COL_INCLUDE_FLAG:
284
                    return Boolean.class;
249
                    return Boolean.class;
285
                    
250
286
                case JavaSourceRootsUI.COL_SOURCE_GROUP:
251
                case JavaSourceRootsUI.COL_SOURCE_GROUP:
287
                    return String.class;
252
                    return String.class;
288
                    
253
289
                case JavaSourceRootsUI.COL_SOURCE_GROUP_DISPLAY_NAME:
254
                case JavaSourceRootsUI.COL_SOURCE_GROUP_DISPLAY_NAME:
290
                    return String.class;
255
                    return String.class;
291
                    
256
292
                default:
257
                default:
293
                    return super.getColumnClass(columnIndex);
258
                    return super.getColumnClass(columnIndex);
294
            }
259
            }
295
        }
260
        }
296
        
261
297
        public SourceGroup[] getSourceGroups()
262
        public SourceGroup[] getSourceGroups() {
298
        {
299
            return sourceGroups;
263
            return sourceGroups;
300
        }
264
        }
301
        
265
302
        public SourceGroup getSourceGroup(int index)
266
        public SourceGroup getSourceGroup(int index) {
303
        {
267
            if (sourceGroups == null) {
304
            if (sourceGroups == null)
305
                return null;
268
                return null;
306
            
269
            }
270
307
            return sourceGroups[index];
271
            return sourceGroups[index];
308
        }
272
        }
309
    }
273
    }
310
    
274
311
    
312
    
313
    // Inner Classes
275
    // Inner Classes
314
    ////////////////
276
    ////////////////
315
    
316
//	protected static class SourceGroupRenderer extends DefaultTableCellRenderer
277
//	protected static class SourceGroupRenderer extends DefaultTableCellRenderer
317
//	{
278
//	{
318
//		public SourceGroupRenderer()
279
//		public SourceGroupRenderer()
Lines 345-351 Link Here
345
//					table, rootFolderName, isSelected, hasFocus, row, column);
306
//					table, rootFolderName, isSelected, hasFocus, row, column);
346
//		}
307
//		}
347
//	}
308
//	}
348
    
349
//	protected static class SourceGroupLabelRenderer extends JLabel
309
//	protected static class SourceGroupLabelRenderer extends JLabel
350
//		implements TableCellRenderer
310
//		implements TableCellRenderer
351
//	{
311
//	{
Lines 386-412 Link Here
386
//		public void firePropertyChange(
346
//		public void firePropertyChange(
387
//				String propertyName, boolean oldValue, boolean newValue) {}
347
//				String propertyName, boolean oldValue, boolean newValue) {}
388
//	}
348
//	}
389
    
349
    private static class WarningDlg extends JPanel {
390
    private static class WarningDlg extends JPanel
350
391
    {
351
        public WarningDlg(Set invalidRoots) {
392
        
393
        public WarningDlg(Set invalidRoots)
394
        {
395
            this.initGui(invalidRoots);
352
            this.initGui(invalidRoots);
396
        }
353
        }
397
        
354
398
        private void initGui(Set invalidRoots)
355
        private void initGui(Set invalidRoots) {
399
        {
356
            setLayout(new GridBagLayout());
400
            setLayout( new GridBagLayout());
401
            JLabel label = new JLabel();
357
            JLabel label = new JLabel();
402
            
358
403
            label.setText(NbBundle.getMessage(
359
            label.setText(NbBundle.getMessage(
404
                JavaSourceRootsUI.class,"LBL_InvalidRoot")); //NOI18N
360
                    JavaSourceRootsUI.class, "LBL_InvalidRoot")); //NOI18N
405
            
361
406
            label.setDisplayedMnemonic(NbBundle.getMessage(
362
            label.setDisplayedMnemonic(NbBundle.getMessage(
407
                JavaSourceRootsUI.class,
363
                    JavaSourceRootsUI.class,
408
                "MNE_InvalidRoot").charAt(0)); //NOI18N
364
                    "MNE_InvalidRoot").charAt(0)); //NOI18N
409
            
365
410
            GridBagConstraints c = new GridBagConstraints();
366
            GridBagConstraints c = new GridBagConstraints();
411
            c.gridx = GridBagConstraints.RELATIVE;
367
            c.gridx = GridBagConstraints.RELATIVE;
412
            c.gridy = GridBagConstraints.RELATIVE;
368
            c.gridy = GridBagConstraints.RELATIVE;
Lines 414-421 Link Here
414
            c.fill = GridBagConstraints.HORIZONTAL;
370
            c.fill = GridBagConstraints.HORIZONTAL;
415
            c.anchor = GridBagConstraints.NORTHWEST;
371
            c.anchor = GridBagConstraints.NORTHWEST;
416
            c.weightx = 1.0;
372
            c.weightx = 1.0;
417
            c.insets = new Insets(12,0,6,0);
373
            c.insets = new Insets(12, 0, 6, 0);
418
            ((GridBagLayout)this.getLayout()).setConstraints(label,c);
374
            ((GridBagLayout) this.getLayout()).setConstraints(label, c);
419
            this.add(label);
375
            this.add(label);
420
            JList roots = new JList(invalidRoots.toArray());
376
            JList roots = new JList(invalidRoots.toArray());
421
            roots.setCellRenderer(new InvalidRootRenderer(true));
377
            roots.setCellRenderer(new InvalidRootRenderer(true));
Lines 427-446 Link Here
427
            c.fill = GridBagConstraints.BOTH;
383
            c.fill = GridBagConstraints.BOTH;
428
            c.anchor = GridBagConstraints.NORTHWEST;
384
            c.anchor = GridBagConstraints.NORTHWEST;
429
            c.weightx = c.weighty = 1.0;
385
            c.weightx = c.weighty = 1.0;
430
            c.insets = new Insets(0,0,12,0);
386
            c.insets = new Insets(0, 0, 12, 0);
431
            ((GridBagLayout)this.getLayout()).setConstraints(p,c);
387
            ((GridBagLayout) this.getLayout()).setConstraints(p, c);
432
            this.add(p);
388
            this.add(p);
433
            label.setLabelFor(roots);
389
            label.setLabelFor(roots);
434
            
390
435
            roots.getAccessibleContext().setAccessibleDescription(
391
            roots.getAccessibleContext().setAccessibleDescription(
436
                NbBundle.getMessage(
392
                    NbBundle.getMessage(
437
                JavaSourceRootsUI.class, "AD_InvalidRoot")); //NOI18N
393
                    JavaSourceRootsUI.class, "AD_InvalidRoot")); //NOI18N
438
            
394
439
            JLabel label2 = new JLabel();
395
            JLabel label2 = new JLabel();
440
            
396
441
            label2.setText(NbBundle.getMessage(
397
            label2.setText(NbBundle.getMessage(
442
                JavaSourceRootsUI.class,"MSG_InvalidRoot2")); //NOI18N
398
                    JavaSourceRootsUI.class, "MSG_InvalidRoot2")); //NOI18N
443
            
399
444
            c = new GridBagConstraints();
400
            c = new GridBagConstraints();
445
            c.gridx = GridBagConstraints.RELATIVE;
401
            c.gridx = GridBagConstraints.RELATIVE;
446
            c.gridy = GridBagConstraints.RELATIVE;
402
            c.gridy = GridBagConstraints.RELATIVE;
Lines 448-507 Link Here
448
            c.fill = GridBagConstraints.HORIZONTAL;
404
            c.fill = GridBagConstraints.HORIZONTAL;
449
            c.anchor = GridBagConstraints.NORTHWEST;
405
            c.anchor = GridBagConstraints.NORTHWEST;
450
            c.weightx = 1.0;
406
            c.weightx = 1.0;
451
            c.insets = new Insets(0,0,0,0);
407
            c.insets = new Insets(0, 0, 0, 0);
452
            ((GridBagLayout)this.getLayout()).setConstraints(label2,c);
408
            ((GridBagLayout) this.getLayout()).setConstraints(label2, c);
453
            this.add(label2);
409
            this.add(label2);
454
        }
410
        }
455
        
411
456
        private static class InvalidRootRenderer extends DefaultListCellRenderer
412
        private static class InvalidRootRenderer extends DefaultListCellRenderer {
457
        {
413
458
            
459
            private boolean projectConflict;
414
            private boolean projectConflict;
460
            
415
461
            public InvalidRootRenderer(boolean projectConflict)
416
            public InvalidRootRenderer(boolean projectConflict) {
462
            {
463
                this.projectConflict = projectConflict;
417
                this.projectConflict = projectConflict;
464
            }
418
            }
465
            
419
466
            public Component getListCellRendererComponent(
420
            public Component getListCellRendererComponent(
467
                JList list,
421
                    JList list,
468
                Object value,
422
                    Object value,
469
                int index,
423
                    int index,
470
                boolean isSelected,
424
                    boolean isSelected,
471
                boolean cellHasFocus)
425
                    boolean cellHasFocus) {
472
            {
473
                File f = (File) value;
426
                File f = (File) value;
474
                String message = f.getAbsolutePath();
427
                String message = f.getAbsolutePath();
475
                
428
476
                if (projectConflict)
429
                if (projectConflict) {
477
                {
478
                    Project p = FileOwnerQuery.getOwner(f.toURI());
430
                    Project p = FileOwnerQuery.getOwner(f.toURI());
479
                    
431
480
                    if (p!=null)
432
                    if (p != null) {
481
                    {
433
                        ProjectInformation pi = (ProjectInformation) p.getLookup().lookup(ProjectInformation.class);
482
                        ProjectInformation pi = (ProjectInformation)
434
483
                        p.getLookup().lookup(ProjectInformation.class);
435
                        if (pi != null) {
484
                        
485
                        if (pi != null)
486
                        {
487
                            String projectName = pi.getDisplayName();
436
                            String projectName = pi.getDisplayName();
488
                            
437
489
                            if (projectName != null)
438
                            if (projectName != null) {
490
                            {
491
                                message = MessageFormat.format(
439
                                message = MessageFormat.format(
492
                                    NbBundle.getMessage(
440
                                        NbBundle.getMessage(
493
                                    JavaSourceRootsUI.class,
441
                                        JavaSourceRootsUI.class,
494
                                    "TXT_RootOwnedByProject"), //NOI18N
442
                                        "TXT_RootOwnedByProject"), //NOI18N
495
                                    new Object[] {
443
                                        new Object[]{
496
                                    message,
444
                                            message,
497
                                    projectName});
445
                                            projectName});
498
                            }
446
                            }
499
                        }
447
                        }
500
                    }
448
                    }
501
                }
449
                }
502
                
450
503
                return super.getListCellRendererComponent(
451
                return super.getListCellRendererComponent(
504
                    list, message, index, isSelected, cellHasFocus);
452
                        list, message, index, isSelected, cellHasFocus);
505
            }
453
            }
506
        }
454
        }
507
    }
455
    }
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/common/ReferencedJavaProjectModel.java (-107 / +80 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on March 20, 2005, 3:51 PM
48
 * Created on March 20, 2005, 3:51 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.common;
50
package org.netbeans.modules.uml.project.ui.common;
52
51
53
import java.io.File;
52
import java.io.File;
Lines 57-75 Link Here
57
 *
56
 *
58
 * @author Mike
57
 * @author Mike
59
 */
58
 */
60
public class ReferencedJavaProjectModel
59
public class ReferencedJavaProjectModel {
61
{
62
60
63
    /** Creates a new instance of PropertydProjectModel */
61
    /** Creates a new instance of PropertydProjectModel */
64
    public ReferencedJavaProjectModel()
62
    public ReferencedJavaProjectModel() {
65
    {
66
        super();
63
        super();
67
    }
64
    }
68
69
70
    // Property to a broken object
65
    // Property to a broken object
71
    private static final String BROKEN = "BrokenProperty"; // NOI18N
66
    private static final String BROKEN = "BrokenProperty"; // NOI18N
72
73
    private Project project;
67
    private Project project;
74
    // private URI artifactURI;
68
    // private URI artifactURI;
75
    // private int type;
69
    // private int type;
Lines 77-239 Link Here
77
    private File projFile;
71
    private File projFile;
78
    private String expectedLocation = ""; // NOI18N
72
    private String expectedLocation = ""; // NOI18N
79
    private ReferenceStatus refStatus = ReferenceStatus.REF_STATUS_UNSET;
73
    private ReferenceStatus refStatus = ReferenceStatus.REF_STATUS_UNSET;
80
    
74
81
    public enum ReferenceStatus
75
    public enum ReferenceStatus {
82
    {
76
83
        REF_STATUS_BROKEN,
77
        REF_STATUS_BROKEN,
84
        REF_STATUS_MOUNTED,
78
        REF_STATUS_MOUNTED,
85
        REF_STATUS_UNMOUNTED,
79
        REF_STATUS_UNMOUNTED,
86
        REF_STATUS_UNSET;
80
        REF_STATUS_UNSET;
87
    }
81
    }
88
    
82
89
    
90
    
91
    private ReferencedJavaProjectModel(
83
    private ReferencedJavaProjectModel(
92
        String property,  String expectedLocation,
84
            String property, String expectedLocation,
93
        File projFile, Project project, ReferenceStatus refStatus)
85
            File projFile, Project project, ReferenceStatus refStatus) {
94
    {
95
        this.project = project;
86
        this.project = project;
96
        this.property = property;
87
        this.property = property;
97
        this.projFile = projFile;
88
        this.projFile = projFile;
98
        this.expectedLocation = expectedLocation;
89
        this.expectedLocation = expectedLocation;
99
        this.refStatus = refStatus;
90
        this.refStatus = refStatus;
100
    }
91
    }
101
    
92
102
    
103
    // Factory methods -----------------------------------------------------
93
    // Factory methods -----------------------------------------------------
104
    
105
    
106
    public static ReferencedJavaProjectModel createMounted(String property,
94
    public static ReferencedJavaProjectModel createMounted(String property,
107
        Project project )
95
            Project project) {
108
    {
96
        if (property == null || project == null) {
109
        if (property == null || project == null)
110
        {
111
            throw new IllegalArgumentException(
97
            throw new IllegalArgumentException(
112
                "property and project must not be null" ); // NOI18N
98
                    "property and project must not be null"); // NOI18N
113
        }
99
        }
114
        
100
115
        return new ReferencedJavaProjectModel(
101
        return new ReferencedJavaProjectModel(
116
            property, null, null, project, ReferenceStatus.REF_STATUS_MOUNTED);
102
                property, null, null, project, ReferenceStatus.REF_STATUS_MOUNTED);
117
    }
103
    }
118
    
104
119
    
105
    public static ReferencedJavaProjectModel createUnset(String property) {
120
    public static ReferencedJavaProjectModel createUnset(String property )
106
        if (property == null) {
121
    {
122
        if (property == null)
123
        {
124
            throw new IllegalArgumentException(
107
            throw new IllegalArgumentException(
125
                "property must not be null" ); // NOI18N
108
                    "property must not be null"); // NOI18N
126
        }
109
        }
127
        
110
128
        return new ReferencedJavaProjectModel(
111
        return new ReferencedJavaProjectModel(
129
            property, null, null, null, ReferenceStatus.REF_STATUS_UNSET);
112
                property, null, null, null, ReferenceStatus.REF_STATUS_UNSET);
130
    }
113
    }
131
    
114
132
    public static ReferencedJavaProjectModel createMounted(
115
    public static ReferencedJavaProjectModel createMounted(
133
        String property, String expectedLocation,
116
            String property, String expectedLocation,
134
        File projectFile, Project project )
117
            File projectFile, Project project) {
135
    {
118
        if (property == null) {
136
        if (property == null)
119
            throw new IllegalArgumentException(
137
        {
120
                    "property must not be null"); // NOI18N
138
            throw new IllegalArgumentException( 
139
                "property must not be null" ); // NOI18N
140
        }
121
        }
141
        
122
142
        return new ReferencedJavaProjectModel(property, expectedLocation,
123
        return new ReferencedJavaProjectModel(property, expectedLocation,
143
            projectFile, project, ReferenceStatus.REF_STATUS_MOUNTED);
124
                projectFile, project, ReferenceStatus.REF_STATUS_MOUNTED);
144
    }
125
    }
145
    
126
146
    public static ReferencedJavaProjectModel createUnmounted(
127
    public static ReferencedJavaProjectModel createUnmounted(
147
        String property, String expectedLocation,
128
            String property, String expectedLocation,
148
        File projectFile)
129
            File projectFile) {
149
    {
130
        if (property == null) {
150
        if (property == null)
131
            throw new IllegalArgumentException(
151
        {
132
                    "property must not be null"); // NOI18N
152
            throw new IllegalArgumentException( 
153
                "property must not be null" ); // NOI18N
154
        }
133
        }
155
        
134
156
        return new ReferencedJavaProjectModel(property, expectedLocation,
135
        return new ReferencedJavaProjectModel(property, expectedLocation,
157
            projectFile, null, ReferenceStatus.REF_STATUS_UNMOUNTED);
136
                projectFile, null, ReferenceStatus.REF_STATUS_UNMOUNTED);
158
    }
137
    }
159
    
138
160
    public static ReferencedJavaProjectModel createBroken(
139
    public static ReferencedJavaProjectModel createBroken(
161
        String property, String expectedLocation)
140
            String property, String expectedLocation) {
162
    {
141
        if (property == null) {
163
        if (property == null)
142
            throw new IllegalArgumentException(
164
        {
143
                    "property must not be null in broken items"); // NOI18N
165
            throw new IllegalArgumentException( 
166
                "property must not be null in broken items" ); // NOI18N
167
        }
144
        }
168
        
145
169
        return new ReferencedJavaProjectModel(property, expectedLocation,
146
        return new ReferencedJavaProjectModel(property, expectedLocation,
170
            null, null, ReferenceStatus.REF_STATUS_BROKEN);
147
                null, null, ReferenceStatus.REF_STATUS_BROKEN);
171
    }
148
    }
172
    
149
173
    // Instance methods ----------------------------------------------------
150
    // Instance methods ----------------------------------------------------
174
    
151
    public ReferenceStatus getRefStatus() {
175
    public ReferenceStatus getRefStatus()
176
    {
177
        return refStatus;
152
        return refStatus;
178
    }
153
    }
179
    
154
180
    
155
    public Project getProject() {
181
    public Project getProject()
182
    {
183
        return project;
156
        return project;
184
    }
157
    }
185
    
158
186
    public String getProperty()
159
    public String getProperty() {
187
    {
188
        return property;
160
        return property;
189
    }
161
    }
190
    
162
191
    public String getExpectedLocation()
163
    public String getExpectedLocation() {
192
    {
193
        return expectedLocation;
164
        return expectedLocation;
194
    }
165
    }
195
    
166
196
    public File getProjectFile()
167
    public File getProjectFile() {
197
    {
198
        return projFile;
168
        return projFile;
199
    }
169
    }
200
    
170
201
    public boolean isBroken()
171
    public boolean isBroken() {
202
    {
203
        return refStatus == ReferenceStatus.REF_STATUS_BROKEN;
172
        return refStatus == ReferenceStatus.REF_STATUS_BROKEN;
204
    }
173
    }
205
    
174
206
    public int hashCode()
175
    public int hashCode() {
207
    {
208
        int hash = 0;
176
        int hash = 0;
209
        
177
210
        if ( isBroken())
178
        if (isBroken()) {
211
            return BROKEN.hashCode();
179
            return BROKEN.hashCode();
212
        
180
        }
213
        if( project != null)
181
182
        if (project != null) {
214
            hash += project.hashCode();
183
            hash += project.hashCode();
184
        }
215
185
216
        hash += property.hashCode();
186
        hash += property.hashCode();
217
        
187
218
        return hash;
188
        return hash;
219
    }
189
    }
220
    
190
221
    public boolean equals(Object itemObject)
191
    public boolean equals(Object itemObject) {
222
    {
192
        if (!(itemObject instanceof ReferencedJavaProjectModel)) {
223
        if (!(itemObject instanceof ReferencedJavaProjectModel))
224
            return false;
193
            return false;
225
        
194
        }
226
        ReferencedJavaProjectModel item = (ReferencedJavaProjectModel)itemObject;
195
227
        
196
        ReferencedJavaProjectModel item = (ReferencedJavaProjectModel) itemObject;
228
        if (isBroken() != item.isBroken())
197
198
        if (isBroken() != item.isBroken()) {
229
            return false;
199
            return false;
230
        
200
        }
231
        if (isBroken())
201
202
        if (isBroken()) {
232
            return getProperty().equals(item.getProperty());
203
            return getProperty().equals(item.getProperty());
233
        
204
        }
234
        if (!getProperty().equals(item.getProperty()))
205
206
        if (!getProperty().equals(item.getProperty())) {
235
            return false;
207
            return false;
236
        
208
        }
209
237
        return getProject() == item.getProject();
210
        return getProject() == item.getProject();
238
    }
211
    }
239
}
212
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/common/ReferencedJavaProjectPanel.form (-3 / +5 lines)
Lines 1-4 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.1" encoding="UTF-8" ?>
2
2
3
<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <NonVisualComponents>
4
  <NonVisualComponents>
Lines 6-11 Link Here
6
    </Component>
6
    </Component>
7
  </NonVisualComponents>
7
  </NonVisualComponents>
8
  <AuxValues>
8
  <AuxValues>
9
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
12
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
13
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
Lines 39-51 Link Here
39
              <Group type="102" alignment="1" attributes="0">
41
              <Group type="102" alignment="1" attributes="0">
40
                  <EmptySpace max="-2" attributes="0"/>
42
                  <EmptySpace max="-2" attributes="0"/>
41
                  <Group type="103" groupAlignment="1" attributes="0">
43
                  <Group type="103" groupAlignment="1" attributes="0">
42
                      <Component id="sourceRootsScrollPane" alignment="0" pref="523" max="32767" attributes="0"/>
44
                      <Component id="sourceRootsScrollPane" alignment="0" pref="525" max="32767" attributes="0"/>
43
                      <Group type="102" alignment="0" attributes="0">
45
                      <Group type="102" alignment="0" attributes="0">
44
                          <Component id="javaProjectLabel" min="-2" max="-2" attributes="0"/>
46
                          <Component id="javaProjectLabel" min="-2" max="-2" attributes="0"/>
45
                          <EmptySpace max="-2" attributes="0"/>
47
                          <EmptySpace max="-2" attributes="0"/>
46
                          <Component id="projectsComboBox" pref="444" max="32767" attributes="0"/>
48
                          <Component id="projectsComboBox" pref="444" max="32767" attributes="0"/>
47
                      </Group>
49
                      </Group>
48
                      <Component id="sourceRootsLabel" alignment="1" pref="523" max="32767" attributes="0"/>
50
                      <Component id="sourceRootsLabel" alignment="1" pref="525" max="32767" attributes="0"/>
49
                  </Group>
51
                  </Group>
50
                  <EmptySpace max="-2" attributes="0"/>
52
                  <EmptySpace max="-2" attributes="0"/>
51
              </Group>
53
              </Group>
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/common/ReferencedJavaProjectPanel.java (-226 / +149 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on September 12, 2006, 12:45 PM
48
 * Created on September 12, 2006, 12:45 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.common;
50
package org.netbeans.modules.uml.project.ui.common;
52
51
53
import java.awt.Component;
52
import java.awt.Component;
Lines 78-150 Link Here
78
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
77
import org.netbeans.modules.uml.project.ui.customizer.UMLProjectProperties;
79
import org.netbeans.modules.uml.project.ui.wizards.NewUMLProjectWizardIterator;
78
import org.netbeans.modules.uml.project.ui.wizards.NewUMLProjectWizardIterator;
80
79
81
82
/**
80
/**
83
 *
81
 *
84
 * @author Mike Frisino
82
 * @author Mike Frisino
85
 * @author Craig Conover, craig.conover@sun.com
83
 * @author Craig Conover, craig.conover@sun.com
86
 */
84
 */
87
public class ReferencedJavaProjectPanel extends javax.swing.JPanel
85
public class ReferencedJavaProjectPanel extends javax.swing.JPanel
88
    implements PropertyChangeListener, TableModelListener
86
        implements PropertyChangeListener, TableModelListener {
89
{
87
90
    public ReferencedJavaProjectPanel(PanelConfigureProject panel)
88
    public ReferencedJavaProjectPanel(PanelConfigureProject panel) {
91
    {
92
        this(panel, NewUMLProjectWizardIterator.TYPE_UML, null, null);
89
        this(panel, NewUMLProjectWizardIterator.TYPE_UML, null, null);
93
    }
90
    }
94
    
91
95
    public ReferencedJavaProjectPanel(PanelConfigureProject panel, int type)
92
    public ReferencedJavaProjectPanel(PanelConfigureProject panel, int type) {
96
    {
97
        this(panel, type, null, null);
93
        this(panel, type, null, null);
98
    }
94
    }
99
    
95
100
    // TODO - I originally hoped to eliminate this constructor
96
    // TODO - I originally hoped to eliminate this constructor
101
    // and have the same code path for both wizard and customizer.
97
    // and have the same code path for both wizard and customizer.
102
    // But as craig said, we have "visual" reuse, but not "model" reuse
98
    // But as craig said, we have "visual" reuse, but not "model" reuse
103
    // It would be nice to unify, but if its not broken don't fix it
99
    // It would be nice to unify, but if its not broken don't fix it
104
    // unless time permits.
100
    // unless time permits.
105
    
106
    // this is the version invoked by the wizard.
101
    // this is the version invoked by the wizard.
107
    public ReferencedJavaProjectPanel(
102
    public ReferencedJavaProjectPanel(
108
        PanelConfigureProject projectConfigurePanel,
103
            PanelConfigureProject projectConfigurePanel,
109
        int type, 
104
            int type,
110
        Project currRefProj, 
105
            Project currRefProj,
111
        JavaSourceRootsUI.JavaSourceRootsModel rootsModel)
106
            JavaSourceRootsUI.JavaSourceRootsModel rootsModel) {
112
    {
113
        panel = projectConfigurePanel;
107
        panel = projectConfigurePanel;
114
        isWizard = true;
108
        isWizard = true;
115
        uiProperties = null;
109
        uiProperties = null;
116
        initComponents();
110
        initComponents();
117
        
111
118
        if (rootsModel == null)
112
        if (rootsModel == null) {
119
            sourceRoots.setModel(JavaSourceRootsUI.createEmptyModel());
113
            sourceRoots.setModel(JavaSourceRootsUI.createEmptyModel());
114
        } else {
115
            sourceRoots.setModel(rootsModel);
116
        }
120
117
121
        else
122
            sourceRoots.setModel(rootsModel);
123
        
124
        sourceRootsScrollPane.getViewport().setBackground(
118
        sourceRootsScrollPane.getViewport().setBackground(
125
            sourceRoots.getBackground());
119
                sourceRoots.getBackground());
126
        
120
127
        sourceRoots.getTableHeader().setReorderingAllowed(false);
121
        sourceRoots.getTableHeader().setReorderingAllowed(false);
128
        sourceRoots.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
122
        sourceRoots.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
129
        initValues(currRefProj);
123
        initValues(currRefProj);
130
    }
124
    }
131
    
125
132
    
133
    // this is the version invoked by the customizer.
126
    // this is the version invoked by the customizer.
134
    public ReferencedJavaProjectPanel(UMLProjectProperties uiProperties)
127
    public ReferencedJavaProjectPanel(UMLProjectProperties uiProperties) {
135
    {
136
        this.uiProperties = uiProperties;
128
        this.uiProperties = uiProperties;
137
        initComponents();
129
        initComponents();
138
        
130
139
        if (uiProperties == null )
131
        if (uiProperties == null) {
140
        {
141
            // this means it was called from wizard before props are available
132
            // this means it was called from wizard before props are available
142
            isWizard = true;
133
            isWizard = true;
143
            sourceRoots.setModel(JavaSourceRootsUI.createEmptyModel());
134
            sourceRoots.setModel(JavaSourceRootsUI.createEmptyModel());
144
        }
135
        } else {
145
        
146
        else
147
        {
148
            // this mean we are called from customizer
136
            // this mean we are called from customizer
149
            isWizard = false;
137
            isWizard = false;
150
            javaRefModel = uiProperties.referencedJavaProjectModel;
138
            javaRefModel = uiProperties.referencedJavaProjectModel;
Lines 152-297 Link Here
152
            setSelectedProject(javaRefModel.getProject());
140
            setSelectedProject(javaRefModel.getProject());
153
            sourceRoots.setModel(javaRefSrcsModel);
141
            sourceRoots.setModel(javaRefSrcsModel);
154
        }
142
        }
155
        
143
156
        sourceRoots.getModel().addTableModelListener(this);
144
        sourceRoots.getModel().addTableModelListener(this);
157
        
145
158
        sourceRootsScrollPane.getViewport().setBackground(
146
        sourceRootsScrollPane.getViewport().setBackground(
159
            sourceRoots.getBackground());
147
                sourceRoots.getBackground());
160
        
148
161
        sourceRoots.getTableHeader().setReorderingAllowed(false);
149
        sourceRoots.getTableHeader().setReorderingAllowed(false);
162
        
150
163
        // populate the combobox with the reference java project and 
151
        // populate the combobox with the reference java project and 
164
        // disable the combbobox for read-only
152
        // disable the combbobox for read-only
165
        ProjectCellRenderer projectCellRenderer = new ProjectCellRenderer();
153
        ProjectCellRenderer projectCellRenderer = new ProjectCellRenderer();
166
        projectsComboBox.setRenderer(projectCellRenderer);
154
        projectsComboBox.setRenderer(projectCellRenderer);
167
        
155
168
        DefaultComboBoxModel projectsModel = new DefaultComboBoxModel( 
156
        DefaultComboBoxModel projectsModel = new DefaultComboBoxModel(
169
            new Project[] {javaRefModel.getProject()});
157
                new Project[]{javaRefModel.getProject()});
170
        
158
171
        projectsComboBox.setModel(projectsModel);
159
        projectsComboBox.setModel(projectsModel);
172
        projectsComboBox.setEnabled(false);
160
        projectsComboBox.setEnabled(false);
173
    }
161
    }
174
    
162
175
    private void initValues(Project prj)
163
    private void initValues(Project prj) {
176
    {
177
        ProjectCellRenderer projectCellRenderer = new ProjectCellRenderer();
164
        ProjectCellRenderer projectCellRenderer = new ProjectCellRenderer();
178
        projectsComboBox.setRenderer(projectCellRenderer);
165
        projectsComboBox.setRenderer(projectCellRenderer);
179
        
166
180
        // Populate the combo box with list of projects
167
        // Populate the combo box with list of projects
181
        Project[] openProjects = ProjectUtil.getOpenJavaProjects();
168
        Project[] openProjects = ProjectUtil.getOpenJavaProjects();
182
        
169
183
        Project[] selectedProjects = 
170
        Project[] selectedProjects =
184
            ProjectUtil.getSelectedProjects(Project.class);
171
                ProjectUtil.getSelectedProjects(Project.class);
185
        
172
186
        DefaultComboBoxModel projectsModel = 
173
        DefaultComboBoxModel projectsModel =
187
            new DefaultComboBoxModel(openProjects);
174
                new DefaultComboBoxModel(openProjects);
188
        
175
189
        projectsComboBox.setModel(projectsModel);
176
        projectsComboBox.setModel(projectsModel);
190
        
177
191
        Project proj = null;
178
        Project proj = null;
192
        if (prj!=null)
179
        if (prj != null) {
193
            proj = prj;
180
            proj = prj;
194
        
181
        } else if (openProjects.length > 0 && selectedProjects.length > 0) {
195
        else if (openProjects.length > 0 && selectedProjects.length > 0)
196
            proj = selectedProjects[0];
182
            proj = selectedProjects[0];
197
        
183
        }
184
198
        this.selectProject(proj);
185
        this.selectProject(proj);
199
    }
186
    }
200
    
187
201
    
188
    private void selectProject(Project prj) {
202
    private void selectProject(Project prj)
189
        if (prj != null) {
203
    {
204
        if (prj != null)
205
        {
206
            projectsComboBox.setSelectedItem(prj);
190
            projectsComboBox.setSelectedItem(prj);
191
        } else {
192
            if (ProjectUtil.getOpenJavaProjects().length > 0) {
193
                projectsComboBox.setSelectedIndex(0);
194
            }
207
        }
195
        }
208
        
196
209
        else
210
        {
211
            if (ProjectUtil.getOpenJavaProjects().length > 0)
212
                projectsComboBox.setSelectedIndex(0);
213
        }
214
        
215
        updateState();
197
        updateState();
216
    }
198
    }
217
    
199
218
    
200
    public void tableChanged(TableModelEvent e) {
219
    public void tableChanged(TableModelEvent e)
220
    {
221
        boolean enableButton = isAtLeastOneSrcFolderSelected();
201
        boolean enableButton = isAtLeastOneSrcFolderSelected();
222
        
202
223
        firePropertyChange(SOURCE_GROUP_CHANGED_PROP, 
203
        firePropertyChange(SOURCE_GROUP_CHANGED_PROP,
224
            "dontCareOldValue", Boolean.valueOf(enableButton)); // NOI18N
204
                "dontCareOldValue", Boolean.valueOf(enableButton)); // NOI18N
225
    }
205
    }
226
    
206
227
    
228
    // Check to see if at one src folder is selected; return true if at least one is selected.
207
    // Check to see if at one src folder is selected; return true if at least one is selected.
229
    // if none is selected, return false
208
    // if none is selected, return false
230
    private boolean isAtLeastOneSrcFolderSelected()
209
    private boolean isAtLeastOneSrcFolderSelected() {
231
    {
232
        boolean selected = false;
210
        boolean selected = false;
233
        TableModel tModel = sourceRoots.getModel();
211
        TableModel tModel = sourceRoots.getModel();
234
        
212
235
        if ( tModel !=  null)
213
        if (tModel != null) {
236
        {
237
            int rowCount = tModel.getRowCount();
214
            int rowCount = tModel.getRowCount();
238
            for (int i = 0; i < rowCount; i++ )
215
            for (int i = 0; i < rowCount; i++) {
239
            {
216
                selected = selected || ((Boolean) tModel.getValueAt(
240
                selected  = selected || ((Boolean)tModel.getValueAt(
217
                        i, JavaSourceRootsUI.COL_INCLUDE_FLAG));
241
                    i,JavaSourceRootsUI.COL_INCLUDE_FLAG));
218
242
                
219
                if (selected) {  // if there's at least one src folder selected, exit the loop
243
                if (selected)
244
                {  // if there's at least one src folder selected, exit the loop
245
                    break;
220
                    break;
246
                }
221
                }
247
            }
222
            }
248
        }
223
        }
249
        
224
250
        return selected;
225
        return selected;
251
    }
226
    }
252
    
227
253
    
228
    public void propertyChange(PropertyChangeEvent event) {
254
    public void propertyChange(PropertyChangeEvent event)
229
255
    {
256
        
257
        // Debug.out.println("MCF table propertyChange - " + event);
230
        // Debug.out.println("MCF table propertyChange - " + event);
258
        /* MCF - change this to whatever prop we care about re bulletproofing
231
        /* MCF - change this to whatever prop we care about re bulletproofing
259
        if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) {
232
        if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) {
260
                String newProjectName = NewUMLProjectWizardIterator.getPackageName((String) event.getNewValue());
233
        String newProjectName = NewUMLProjectWizardIterator.getPackageName((String) event.getNewValue());
261
                this.mainClassTextField.setText (MessageFormat.format(
234
        this.mainClassTextField.setText (MessageFormat.format(
262
                        NbBundle.getMessage (ReferencedJavaProjectPanel.class,"TXT_ClassName"), new Object[] {newProjectName}
235
        NbBundle.getMessage (ReferencedJavaProjectPanel.class,"TXT_ClassName"), new Object[] {newProjectName}
263
                ));
236
        ));
264
        }
237
        }
265
         */
238
         */
266
        
239
267
        if (PanelOptionsVisual.MODE_CHANGED_PROP.equals(event.getPropertyName()))
240
        if (PanelOptionsVisual.MODE_CHANGED_PROP.equals(event.getPropertyName())) {
268
        {
241
            if (event.getNewValue().equals(UMLProject.PROJECT_MODE_IMPL_STR)) {
269
            if (event.getNewValue().equals(UMLProject.PROJECT_MODE_IMPL_STR))
242
                if (ProjectUtil.getOpenJavaProjects().length > 0) {
270
            {
271
                if (ProjectUtil.getOpenJavaProjects().length > 0)
272
                {
273
                    initValues(null);
243
                    initValues(null);
274
244
275
                    // must be in wizard as well for the project combobox
245
                    // must be in wizard as well for the project combobox
276
                    // to be enabled. it should disabled in customizer
246
                    // to be enabled. it should disabled in customizer
277
                    projectsComboBox.setEnabled(isWizard);
247
                    projectsComboBox.setEnabled(isWizard);
278
                }
248
                }
279
            }
249
            } else if (event.getNewValue().equals(UMLProject.PROJECT_MODE_DESIGN_STR)) {
280
281
            else if (event.getNewValue()
282
                .equals(UMLProject.PROJECT_MODE_DESIGN_STR))
283
            {
284
                projectsComboBox.setSelectedItem(null);
250
                projectsComboBox.setSelectedItem(null);
285
                projectsComboBox.setEnabled(false);
251
                projectsComboBox.setEnabled(false);
286
            }
252
            }
287
        }
253
        } else if (ASSOCIATED_JAVA_PROJ_PROP.equals(event.getPropertyName())) {
288
289
        else if (ASSOCIATED_JAVA_PROJ_PROP.equals(event.getPropertyName()))
290
        {
291
            updateSourceRootsTable();
254
            updateSourceRootsTable();
292
        }
255
        }
293
    }
256
    }
294
    
257
295
    /** This method is called from within the constructor to
258
    /** This method is called from within the constructor to
296
     * initialize the form.
259
     * initialize the form.
297
     * WARNING: Do NOT modify this code. The content of this method is
260
     * WARNING: Do NOT modify this code. The content of this method is
Lines 404-424 Link Here
404
367
405
    private void projectsComboBoxItemStateChanged(java.awt.event.ItemEvent evt)//GEN-FIRST:event_projectsComboBoxItemStateChanged
368
    private void projectsComboBoxItemStateChanged(java.awt.event.ItemEvent evt)//GEN-FIRST:event_projectsComboBoxItemStateChanged
406
    {//GEN-HEADEREND:event_projectsComboBoxItemStateChanged
369
    {//GEN-HEADEREND:event_projectsComboBoxItemStateChanged
407
        setSelectedProject((Project)projectsComboBox.getSelectedItem());
370
        setSelectedProject((Project) projectsComboBox.getSelectedItem());
408
        updateSourceRootsTable();
371
        updateSourceRootsTable();
409
    }//GEN-LAST:event_projectsComboBoxItemStateChanged
372
    }//GEN-LAST:event_projectsComboBoxItemStateChanged
410
    
373
411
    
412
    // only called by wizard
374
    // only called by wizard
413
    public Project getSelectedProject()
375
    public Project getSelectedProject() {
414
    {
415
        return javaSrcProj;
376
        return javaSrcProj;
416
    }
377
    }
417
    
378
418
    
419
    // only called by wizard
379
    // only called by wizard
420
    public void setSelectedProject(Project prj)
380
    public void setSelectedProject(Project prj) {
421
    {
422
        // MCF - i had to change this because Trey was not setting the
381
        // MCF - i had to change this because Trey was not setting the
423
        // javaSrcProj before firing the event. And the wizard
382
        // javaSrcProj before firing the event. And the wizard
424
        // listener was checking calling isValid, which was calling
383
        // listener was checking calling isValid, which was calling
Lines 429-578 Link Here
429
        firePropertyChange(ASSOCIATED_JAVA_PROJ_PROP, oldVal, javaSrcProj);
388
        firePropertyChange(ASSOCIATED_JAVA_PROJ_PROP, oldVal, javaSrcProj);
430
    }
389
    }
431
390
432
    
391
    private void updateState() {
433
    private void updateState()
392
        if (projectsComboBox.getSelectedItem() == null) {
434
    {
435
        if (projectsComboBox.getSelectedItem() == null)
436
        {
437
            sourceRoots.setModel(JavaSourceRootsUI.createEmptyModel());
393
            sourceRoots.setModel(JavaSourceRootsUI.createEmptyModel());
438
            setSelectedProject(null);
394
            setSelectedProject(null);
439
            return;
395
            return;
440
        }
396
        }
441
        
397
442
        setSelectedProject((Project)projectsComboBox.getSelectedItem());
398
        setSelectedProject((Project) projectsComboBox.getSelectedItem());
443
        updateSourceRootsTable();
399
        updateSourceRootsTable();
444
    }
400
    }
445
401
446
    private void updateSourceRootsTable()
402
    private void updateSourceRootsTable() {
447
    {
448
        // conditionalized for wizard vs customizer
403
        // conditionalized for wizard vs customizer
449
        if (uiProperties == null)
404
        if (uiProperties == null) {
450
        {
451
            sourceRoots.setModel(
405
            sourceRoots.setModel(
452
                JavaSourceRootsUI.createModel(getSelectedProject()));
406
                    JavaSourceRootsUI.createModel(getSelectedProject()));
453
            
407
454
            sourceRoots.getModel().addTableModelListener(this);
408
            sourceRoots.getModel().addTableModelListener(this);
455
        }
409
        } else {
456
        
457
        else
458
        {
459
            uiProperties.referencedJavaProjectModel =
410
            uiProperties.referencedJavaProjectModel =
460
                ReferencedJavaProjectModel.createMounted(
411
                    ReferencedJavaProjectModel.createMounted(
461
                    uiProperties.REFERENCED_JAVA_PROJECT,
412
                    uiProperties.REFERENCED_JAVA_PROJECT,
462
                    getSelectedProject());
413
                    getSelectedProject());
463
            
414
464
            uiProperties.referencedJavaSourceRootsModel =
415
            uiProperties.referencedJavaSourceRootsModel =
465
                javaRefSrcsModel = JavaSourceRootsUI
416
                    javaRefSrcsModel = JavaSourceRootsUI.createModel(getSelectedProject());
466
                    .createModel(getSelectedProject());
417
467
            
468
            sourceRoots.setModel(
418
            sourceRoots.setModel(
469
                uiProperties.referencedJavaSourceRootsModel);
419
                    uiProperties.referencedJavaSourceRootsModel);
470
            
420
471
            sourceRoots.getModel().addTableModelListener(this);
421
            sourceRoots.getModel().addTableModelListener(this);
472
//            firePropertyChange(JAVA_PROJECT_CHANGED_PROP, 
422
//            firePropertyChange(JAVA_PROJECT_CHANGED_PROP, 
473
//                oldVal, getSelectedProject());
423
//                oldVal, getSelectedProject());
474
        }
424
        }
475
    }
425
    }
476
    
426
477
    
478
    /*
427
    /*
479
     * returns a map where the key is a SourceGroup and the value is a Boolean
428
     * returns a map where the key is a SourceGroup and the value is a Boolean
480
     * indicating whether it was a selected or deselected SourceGroup
429
     * indicating whether it was a selected or deselected SourceGroup
481
     *
430
     *
482
     */
431
     */
483
    public JavaSourceRootsUI.JavaSourceRootsModel getJavaSourceRootsModel()
432
    public JavaSourceRootsUI.JavaSourceRootsModel getJavaSourceRootsModel() {
484
    {
433
        return (JavaSourceRootsUI.JavaSourceRootsModel) sourceRoots.getModel();
485
        return (JavaSourceRootsUI.JavaSourceRootsModel)sourceRoots.getModel();
486
    }
434
    }
487
    
435
488
    
436
    public boolean valid(WizardDescriptor settings) {
489
    public boolean valid(WizardDescriptor settings)
490
    {
491
        // conditionalized for wizard vs customizer
437
        // conditionalized for wizard vs customizer
492
        if (uiProperties == null)
438
        if (uiProperties == null) {
493
        {
439
            if (getSelectedProject() == null) {
494
            if (getSelectedProject() == null)
495
            {
496
                settings.putProperty(
440
                settings.putProperty(
497
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
441
                        NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
498
                    NbBundle.getMessage(ReferencedJavaProjectPanel.class,
442
                        NbBundle.getMessage(ReferencedJavaProjectPanel.class,
499
                    "ReverseEngineer_Warning")); //NOI18N
443
                        "ReverseEngineer_Warning")); //NOI18N
444
445
                return false;
446
            } else if (sourceRoots.getModel() == null
447
                    || !isAtLeastOneSrcFolderSelected()) {
448
                settings.putProperty(
449
                        NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
450
                        NbBundle.getMessage(ReferencedJavaProjectPanel.class,
451
                        "SourceGroup_Warning")); //NOI18N
500
452
501
                return false;
453
                return false;
502
            }
454
            }
503
455
504
            else if (sourceRoots.getModel() == null || 
505
                !isAtLeastOneSrcFolderSelected())
506
            {
507
                settings.putProperty(
508
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
509
                    NbBundle.getMessage(ReferencedJavaProjectPanel.class,
510
                    "SourceGroup_Warning")); //NOI18N
511
512
                return false;
513
            }
514
            
515
            settings.putProperty(
456
            settings.putProperty(
516
                NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, ""); // NOI18N
457
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, ""); // NOI18N
517
458
518
            return true;
459
            return true;
519
        }
460
        }
520
        
461
521
        return true;
462
        return true;
522
    }
463
    }
523
464
524
    public void itemStateChanged(ItemEvent e)
465
    public void itemStateChanged(ItemEvent e) {
525
    {
526
    }
466
    }
527
    
467
528
    private static class ProjectCellRenderer extends JLabel 
468
    private static class ProjectCellRenderer extends JLabel
529
        implements ListCellRenderer
469
            implements ListCellRenderer {
530
    {
470
531
        public ProjectCellRenderer()
471
        public ProjectCellRenderer() {
532
        {
533
            setOpaque(true);
472
            setOpaque(true);
534
        }
473
        }
535
        
474
536
        public Component getListCellRendererComponent(
475
        public Component getListCellRendererComponent(
537
            JList list,
476
                JList list,
538
            Object value,
477
                Object value,
539
            int index,
478
                int index,
540
            boolean isSelected,
479
                boolean isSelected,
541
            boolean cellHasFocus)
480
                boolean cellHasFocus) {
542
        {
481
543
            
482
            if (value instanceof Project) {
544
            if ( value instanceof Project )
483
                ProjectInformation pi =
545
            {
484
                        ProjectUtils.getInformation((Project) value);
546
                ProjectInformation pi = 
485
547
                    ProjectUtils.getInformation((Project)value);
548
                
549
                setText(pi.getDisplayName());
486
                setText(pi.getDisplayName());
550
                setIcon(pi.getIcon());
487
                setIcon(pi.getIcon());
488
            } else {
489
                setText(value == null ? " " : value.toString()); // NOI18N
490
                setIcon(null);
551
            }
491
            }
552
            
492
553
            else
493
            if (isSelected) {
554
            {
555
                setText( value == null ? " " : value.toString() ); // NOI18N
556
                setIcon( null );
557
            }
558
            
559
            if (isSelected)
560
            {
561
                setBackground(list.getSelectionBackground());
494
                setBackground(list.getSelectionBackground());
562
                setForeground(list.getSelectionForeground());
495
                setForeground(list.getSelectionForeground());
563
            }
496
            } else {
564
            
565
            else
566
            {
567
                setBackground(list.getBackground());
497
                setBackground(list.getBackground());
568
                setForeground(list.getForeground());
498
                setForeground(list.getForeground());
569
            }
499
            }
570
            
500
571
            return this;
501
            return this;
572
        }
502
        }
573
    }
503
    }
574
    
575
    
576
    // Variables declaration - do not modify//GEN-BEGIN:variables
504
    // Variables declaration - do not modify//GEN-BEGIN:variables
577
    private javax.swing.JLabel javaProjectLabel;
505
    private javax.swing.JLabel javaProjectLabel;
578
    private javax.swing.ButtonGroup modelTypeButtonGroup;
506
    private javax.swing.ButtonGroup modelTypeButtonGroup;
Lines 582-588 Link Here
582
    private javax.swing.JPanel sourceRootsPanel;
510
    private javax.swing.JPanel sourceRootsPanel;
583
    private javax.swing.JScrollPane sourceRootsScrollPane;
511
    private javax.swing.JScrollPane sourceRootsScrollPane;
584
    // End of variables declaration//GEN-END:variables
512
    // End of variables declaration//GEN-END:variables
585
    
586
    // Some of these would not be needed if we had unified code path.
513
    // Some of these would not be needed if we had unified code path.
587
    private Project javaSrcProj;
514
    private Project javaSrcProj;
588
    private String javaSrcProjName;
515
    private String javaSrcProjName;
Lines 593-605 Link Here
593
    private JavaSourceRootsModel javaRefSrcsModel;
520
    private JavaSourceRootsModel javaRefSrcsModel;
594
    private PanelConfigureProject panel;
521
    private PanelConfigureProject panel;
595
    public static boolean mIsImplementationMode = true;
522
    public static boolean mIsImplementationMode = true;
596
523
    private java.util.ResourceBundle bundle =
597
    private java.util.ResourceBundle bundle = 
524
            NbBundle.getBundle(ReferencedJavaProjectPanel.class);
598
        NbBundle.getBundle(ReferencedJavaProjectPanel.class);
599
600
    
601
    public static final String ASSOCIATED_JAVA_PROJ_PROP = "ReferencedProjectProperty"; //NOI18N
525
    public static final String ASSOCIATED_JAVA_PROJ_PROP = "ReferencedProjectProperty"; //NOI18N
602
    public final static String SOURCE_GROUP_CHANGED_PROP = "SOURCE_GROUP_CHANGED";  //NOI18N
526
    public final static String SOURCE_GROUP_CHANGED_PROP = "SOURCE_GROUP_CHANGED";  //NOI18N
603
    public final static String JAVA_PROJECT_CHANGED_PROP = "JAVA_PROJ_CHANGED"; // NOI18N
527
    public final static String JAVA_PROJECT_CHANGED_PROP = "JAVA_PROJ_CHANGED"; // NOI18N
604
605
}
528
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/common/ReferencedJavaProjectSupport.java (-90 / +66 lines)
Lines 47-54 Link Here
47
 *
47
 *
48
 * Created on March 14, 2005, 6:40 PM
48
 * Created on March 14, 2005, 6:40 PM
49
 */
49
 */
50
package org.netbeans.modules.uml.project.ui.common;
50
51
51
package org.netbeans.modules.uml.project.ui.common;
52
import org.netbeans.modules.uml.project.ui.common.JavaSourceRootsUI.JavaSourceRootsModel;
52
import org.netbeans.modules.uml.project.ui.common.JavaSourceRootsUI.JavaSourceRootsModel;
53
import java.io.File;
53
import java.io.File;
54
import java.util.ArrayList;
54
import java.util.ArrayList;
Lines 69-213 Link Here
69
 *
69
 *
70
 * @author Mike
70
 * @author Mike
71
 */
71
 */
72
public class ReferencedJavaProjectSupport
72
public class ReferencedJavaProjectSupport {
73
{
73
74
    
75
    /** Creates a new instance of ReferencedJavaProjectSupport */
74
    /** Creates a new instance of ReferencedJavaProjectSupport */
76
    public ReferencedJavaProjectSupport()
75
    public ReferencedJavaProjectSupport() {
77
    {
78
    }
76
    }
79
    
80
    private PropertyEvaluator evaluator;
77
    private PropertyEvaluator evaluator;
81
    private ReferenceHelper referenceHelper;
78
    private ReferenceHelper referenceHelper;
82
    private AntProjectHelper antProjectHelper;
79
    private AntProjectHelper antProjectHelper;
83
    private Set /*<String>*/ sourceGroups;
80
    private Set /*<String>*/ sourceGroups;
84
    private String antArtifactPrefix;
81
    private String antArtifactPrefix;
85
    
82
86
    /** Creates a new instance of ClassPathSupport */
83
    /** Creates a new instance of ClassPathSupport */
87
    public  ReferencedJavaProjectSupport(
84
    public ReferencedJavaProjectSupport(
88
        PropertyEvaluator evaluator,
85
            PropertyEvaluator evaluator,
89
        ReferenceHelper referenceHelper,
86
            ReferenceHelper referenceHelper,
90
        AntProjectHelper antProjectHelper,
87
            AntProjectHelper antProjectHelper,
91
        String sourceGroups[],
88
            String sourceGroups[],
92
        String antArtifactPrefix )
89
            String antArtifactPrefix) {
93
    {
94
        this.evaluator = evaluator;
90
        this.evaluator = evaluator;
95
        this.referenceHelper = referenceHelper;
91
        this.referenceHelper = referenceHelper;
96
        this.antProjectHelper = antProjectHelper;
92
        this.antProjectHelper = antProjectHelper;
97
        
93
98
        this.sourceGroups = sourceGroups == null 
94
        this.sourceGroups = sourceGroups == null
99
            ? null 
95
                ? null
100
            : new HashSet(Arrays.asList(sourceGroups));
96
                : new HashSet(Arrays.asList(sourceGroups));
101
        
97
102
        this.antArtifactPrefix = antArtifactPrefix;
98
        this.antArtifactPrefix = antArtifactPrefix;
103
    }
99
    }
104
    
100
105
    
106
    
107
    public ReferencedJavaProjectModel createReferencedJavaProjectModel(
101
    public ReferencedJavaProjectModel createReferencedJavaProjectModel(
108
        String property, String propertyValue)
102
            String property, String propertyValue) {
109
    {
103
110
        
111
        ReferencedJavaProjectModel model = null;
104
        ReferencedJavaProjectModel model = null;
112
        Project project = null;
105
        Project project = null;
113
        
106
114
        if (propertyValue == null || propertyValue.length() == 0)
107
        if (propertyValue == null || propertyValue.length() == 0) {
115
            return  ReferencedJavaProjectModel.createUnset(property);
108
            return ReferencedJavaProjectModel.createUnset(property);
116
        
109
        }
110
117
        String expectedLocation = evaluator.evaluate(propertyValue);
111
        String expectedLocation = evaluator.evaluate(propertyValue);
118
        
112
119
        
113
120
        // following other examples we would compare the expected location
114
        // following other examples we would compare the expected location
121
        // with the actual location
115
        // with the actual location
122
        File projFile =
116
        File projFile =
123
            antProjectHelper.resolveFile(expectedLocation);
117
                antProjectHelper.resolveFile(expectedLocation);
124
        
118
125
        if (projFile == null || !(projFile.exists()))
119
        if (projFile == null || !(projFile.exists())) {
126
        {
127
            // project file not on local system, probably moved
120
            // project file not on local system, probably moved
128
            return ReferencedJavaProjectModel.createBroken(
121
            return ReferencedJavaProjectModel.createBroken(
129
                property, expectedLocation);
122
                    property, expectedLocation);
130
        }
123
        }
131
        
124
132
        // This will determine if other project is mounted
125
        // This will determine if other project is mounted
133
        FileObject projFo =
126
        FileObject projFo =
134
            antProjectHelper.resolveFileObject(expectedLocation);
127
                antProjectHelper.resolveFileObject(expectedLocation);
135
        
128
136
        if (projFo == null)
129
        if (projFo == null) {
137
        {
138
            // project file exists but is not mounted
130
            // project file exists but is not mounted
139
            return ReferencedJavaProjectModel.createUnmounted(
131
            return ReferencedJavaProjectModel.createUnmounted(
140
                property, expectedLocation, projFile);
132
                    property, expectedLocation, projFile);
141
        }
133
        } else {
142
        
134
            try {
143
        else
144
        {
145
            try
146
            {
147
                project = ProjectManager.getDefault().findProject(projFo);
135
                project = ProjectManager.getDefault().findProject(projFo);
148
                
136
149
                return ReferencedJavaProjectModel.createMounted(
137
                return ReferencedJavaProjectModel.createMounted(
150
                    property, expectedLocation, projFile, project);
138
                        property, expectedLocation, projFile, project);
151
            }
139
            } catch (Exception e) {
152
            
153
            catch(Exception e)
154
            {
155
                
156
                // TODO - FIX THIS - bulletproof
140
                // TODO - FIX THIS - bulletproof
157
                //  Debug.out.println("MCF - createReferencedJeavaProjectModel : "
141
                //  Debug.out.println("MCF - createReferencedJeavaProjectModel : "
158
                //         + e);
142
                //         + e);
159
            }
143
            }
160
        }
144
        }
161
        
145
162
        // not sure what to do if we get here
146
        // not sure what to do if we get here
163
        return ReferencedJavaProjectModel.createBroken(
147
        return ReferencedJavaProjectModel.createBroken(
164
            property, expectedLocation);
148
                property, expectedLocation);
165
    }
149
    }
166
    
150
167
    
168
    // propValue is assumed to be a unparsed string
151
    // propValue is assumed to be a unparsed string
169
    public JavaSourceRootsModel createReferencedJavaSourceRootsModel(
152
    public JavaSourceRootsModel createReferencedJavaSourceRootsModel(
170
        ReferencedJavaProjectModel projModel,
153
            ReferencedJavaProjectModel projModel,
171
        String propertyValue)
154
            String propertyValue) {
172
    {
155
173
        
174
        DefaultListModel jsrm = new DefaultListModel();
156
        DefaultListModel jsrm = new DefaultListModel();
175
        
157
176
        if (propertyValue != null)
158
        if (propertyValue != null) {
177
        {
159
178
    
179
            String token = "$";  // NOI18N
160
            String token = "$";  // NOI18N
180
            StringTokenizer tokenizer =
161
            StringTokenizer tokenizer =
181
                new StringTokenizer(propertyValue, token);
162
                    new StringTokenizer(propertyValue, token);
182
            
163
183
            while(tokenizer.hasMoreTokens())
164
            while (tokenizer.hasMoreTokens()) {
184
            {
165
                String nextVal = token.concat((String) tokenizer.nextElement());
185
                String nextVal = token.concat((String)tokenizer.nextElement());
186
                jsrm.addElement(nextVal);
166
                jsrm.addElement(nextVal);
187
            }
167
            }
188
        }
168
        }
189
        
169
190
        return JavaSourceRootsUI.createModel(projModel, jsrm );
170
        return JavaSourceRootsUI.createModel(projModel, jsrm);
191
    }
171
    }
192
    
172
193
    
173
    public String[] encodeSrcGroupsToStrings(JavaSourceRootsModel model) {
194
    public String[] encodeSrcGroupsToStrings(JavaSourceRootsModel model)
195
    {
196
        ArrayList result = new ArrayList();
174
        ArrayList result = new ArrayList();
197
        
175
198
        for (int i = 0; i <  model.getRowCount(); i++)
176
        for (int i = 0; i < model.getRowCount(); i++) {
199
        {
177
            Boolean isChecked = (Boolean) model.getValueAt(i, JavaSourceRootsUI.COL_INCLUDE_FLAG);
200
            Boolean isChecked = (Boolean)model
178
201
                .getValueAt(i, JavaSourceRootsUI.COL_INCLUDE_FLAG);
179
            if (isChecked != null && isChecked) {
202
            
180
                SourceGroup sg = (SourceGroup) model.getSourceGroup(i);
203
            if (isChecked != null && isChecked)
181
                if (sg != null) {
204
            {
205
                SourceGroup sg = (SourceGroup)model.getSourceGroup(i);
206
                if (sg != null)
207
                    result.add(sg.getName());
182
                    result.add(sg.getName());
183
                }
208
            }
184
            }
209
        }
185
        }
210
        
186
211
        return (String[]) result.toArray(new String[result.size()]);
187
        return (String[]) result.toArray(new String[result.size()]);
212
    }
188
    }
213
}
189
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/common/UMLProjectChooser.java (-7 lines)
Lines 45-51 Link Here
45
package org.netbeans.modules.uml.project.ui.common;
45
package org.netbeans.modules.uml.project.ui.common;
46
46
47
import java.util.LinkedList;
47
import java.util.LinkedList;
48
import java.util.ArrayList;
49
import java.util.List;
48
import java.util.List;
50
import java.util.Set;
49
import java.util.Set;
51
import org.netbeans.api.project.Project;
50
import org.netbeans.api.project.Project;
Lines 61-77 Link Here
61
import org.openide.nodes.Node;
60
import org.openide.nodes.Node;
62
import org.openide.nodes.NodeAcceptor;
61
import org.openide.nodes.NodeAcceptor;
63
import org.openide.nodes.NodeOperation;
62
import org.openide.nodes.NodeOperation;
64
import org.openide.util.HelpCtx;
65
import org.openide.util.NbBundle;
63
import org.openide.util.NbBundle;
66
import org.openide.util.UserCancelException;
64
import org.openide.util.UserCancelException;
67
//import org.openide.util.actions.CallableSystemAction;
65
//import org.openide.util.actions.CallableSystemAction;
68
import org.openide.util.actions.CookieAction;
69
import org.openide.util.lookup.Lookups;
66
import org.openide.util.lookup.Lookups;
70
67
71
import org.netbeans.api.project.ant.AntArtifact;
72
import org.netbeans.api.project.ant.AntArtifactQuery;
73
import java.util.Arrays;
74
import java.util.Iterator;
75
68
76
// this would create module dependency
69
// this would create module dependency
77
//import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer;
70
//import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer;
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/cookies/DocumentationCookie.java (-11 / +10 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on April 20, 2005, 1:35 PM
48
 * Created on April 20, 2005, 1:35 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.cookies;
50
package org.netbeans.modules.uml.project.ui.cookies;
52
51
53
import org.openide.nodes.Node;
52
import org.openide.nodes.Node;
Lines 58-72 Link Here
58
 *
57
 *
59
 * @author Trey Spiva
58
 * @author Trey Spiva
60
 */
59
 */
61
public interface DocumentationCookie extends Node.Cookie
60
public interface DocumentationCookie extends Node.Cookie {
62
{
63
   /**
64
    * Retreive the documentation from the node.
65
    */
66
   public String getDocumentation();
67
61
68
   /**
62
    /**
69
    * Sets the documentation for the node.
63
     * Retreive the documentation from the node.
70
    */
64
     */
71
   public void setDocumentation(String retVal);
65
    public String getDocumentation();
66
67
    /**
68
     * Sets the documentation for the node.
69
     */
70
    public void setDocumentation(String retVal);
72
}
71
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/cookies/ImportedElementCookie.java (-5 / +4 lines)
Lines 41-51 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.cookies;
44
package org.netbeans.modules.uml.project.ui.cookies;
47
45
48
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
49
import org.netbeans.modules.uml.core.metamodel.structure.IProject;
46
import org.netbeans.modules.uml.core.metamodel.structure.IProject;
50
import org.openide.nodes.Node;
47
import org.openide.nodes.Node;
51
48
Lines 53-61 Link Here
53
 *
50
 *
54
 * @author Sheryl
51
 * @author Sheryl
55
 */
52
 */
56
public interface ImportedElementCookie extends Node.Cookie
53
public interface ImportedElementCookie extends Node.Cookie {
57
{
54
58
    public IProject getReferencingProject();
55
    public IProject getReferencingProject();
56
59
    public String getElementXMIID();
57
    public String getElementXMIID();
58
60
    public void removeImportedElement();
59
    public void removeImportedElement();
61
}
60
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/CustomizerModeling.form (-2 / +4 lines)
Lines 1-11 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.1" encoding="UTF-8" ?>
2
2
3
<Form version="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AccessibilityProperties>
4
  <AccessibilityProperties>
5
    <Property name="AccessibleContext.accessibleName" type="java.lang.String" value=""/>
5
    <Property name="AccessibleContext.accessibleName" type="java.lang.String" value=""/>
6
    <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
6
    <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
7
  </AccessibilityProperties>
7
  </AccessibilityProperties>
8
  <AuxValues>
8
  <AuxValues>
9
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
12
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
13
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/CustomizerModeling.java (-87 / +64 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.customizer;
44
package org.netbeans.modules.uml.project.ui.customizer;
46
45
47
import java.awt.Component;
46
import java.awt.Component;
Lines 60-77 Link Here
60
import org.netbeans.modules.uml.project.ui.common.ReferencedJavaProjectModel;
59
import org.netbeans.modules.uml.project.ui.common.ReferencedJavaProjectModel;
61
import org.netbeans.modules.uml.project.ui.customizer.uiapi.CustomizerPane;
60
import org.netbeans.modules.uml.project.ui.customizer.uiapi.CustomizerPane;
62
61
63
64
/**
62
/**
65
 *
63
 *
66
 * @author  Mike Frisino
64
 * @author  Mike Frisino
67
 */
65
 */
68
public class CustomizerModeling extends javax.swing.JPanel 
66
public class CustomizerModeling extends javax.swing.JPanel
69
    implements HelpCtx.Provider
67
        implements HelpCtx.Provider {
70
{
68
71
    UMLProjectProperties mUIProperties = null;
69
    UMLProjectProperties mUIProperties = null;
72
    
70
73
    public CustomizerModeling(UMLProjectProperties uiProperties)
71
    public CustomizerModeling(UMLProjectProperties uiProperties) {
74
    {
75
        mUIProperties = uiProperties;
72
        mUIProperties = uiProperties;
76
        initComponents();
73
        initComponents();
77
        addJavaProjectPanel(uiProperties);
74
        addJavaProjectPanel(uiProperties);
Lines 80-104 Link Here
80
        File pf = FileUtil.toFile(projectFolder);
77
        File pf = FileUtil.toFile(projectFolder);
81
        projectLocation.setText(pf == null ? "" : pf.getPath()); // NOI18N
78
        projectLocation.setText(pf == null ? "" : pf.getPath()); // NOI18N
82
        String modelingMode = uiProperties.getCurrentProjectMode();
79
        String modelingMode = uiProperties.getCurrentProjectMode();
83
        
80
84
        if (modelingMode != null && modelingMode.equals(UMLProject.PROJECT_MODE_ANALYSIS_STR)) 
81
        if (modelingMode != null && modelingMode.equals(UMLProject.PROJECT_MODE_ANALYSIS_STR)) {
85
             disableAllComponents();
82
            disableAllComponents();
86
        
83
        }
87
        testBroken();        
84
85
        testBroken();
88
    }
86
    }
89
    
87
90
    public HelpCtx getHelpCtx()
88
    public HelpCtx getHelpCtx() {
91
    {
92
        return new HelpCtx(CustomizerModeling.class);
89
        return new HelpCtx(CustomizerModeling.class);
93
    }
90
    }
94
91
95
    
96
    /** This method is called from within the constructor to
92
    /** This method is called from within the constructor to
97
     * initialize the form.
93
     * initialize the form.
98
     * WARNING: Do NOT modify this code. The content of this method is
94
     * WARNING: Do NOT modify this code. The content of this method is
99
     * always regenerated by the Form Editor.
95
     * always regenerated by the Form Editor.
100
     */
96
     */
101
102
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
97
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
103
    private void initComponents()
98
    private void initComponents()
104
    {
99
    {
Lines 161-183 Link Here
161
156
162
    }// </editor-fold>//GEN-END:initComponents
157
    }// </editor-fold>//GEN-END:initComponents
163
158
164
    private void addJavaProjectPanel(UMLProjectProperties uiProperties)
159
    private void addJavaProjectPanel(UMLProjectProperties uiProperties) {
165
    {
166
        javaProjectPanel = new ReferencedJavaProjectPanel(uiProperties);
160
        javaProjectPanel = new ReferencedJavaProjectPanel(uiProperties);
167
        jPanelCentral.add(javaProjectPanel, java.awt.BorderLayout.CENTER);
161
        jPanelCentral.add(javaProjectPanel, java.awt.BorderLayout.CENTER);
168
        javaProjectPanel.addPropertyChangeListener(mChangeListener);
162
        javaProjectPanel.addPropertyChangeListener(mChangeListener);
169
        
163
170
        javaProjectPanel.addPropertyChangeListener(
164
        javaProjectPanel.addPropertyChangeListener(
171
            ReferencedJavaProjectPanel.JAVA_PROJECT_CHANGED_PROP, 
165
                ReferencedJavaProjectPanel.JAVA_PROJECT_CHANGED_PROP,
172
            mChangeListener);
166
                mChangeListener);
173
        
167
174
        javaProjectPanel.addPropertyChangeListener(
168
        javaProjectPanel.addPropertyChangeListener(
175
            ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP, 
169
                ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP,
176
            mChangeListener);
170
                mChangeListener);
177
    }
171
    }
178
    
172
179
    private void addMessageLabel(UMLProjectProperties uiProperties)
173
    private void addMessageLabel(UMLProjectProperties uiProperties) {
180
    {   
181
        //messageLabel = new JTextArea();
174
        //messageLabel = new JTextArea();
182
        messageLabel = new JLabel();
175
        messageLabel = new JLabel();
183
//        messageLabel.setLineWrap(true);
176
//        messageLabel.setLineWrap(true);
Lines 186-290 Link Here
186
//        messageLabel.setEditable(false);
179
//        messageLabel.setEditable(false);
187
//        messageLabel.setRows(2);
180
//        messageLabel.setRows(2);
188
        jPanelCentral.add(messageLabel, java.awt.BorderLayout.SOUTH);
181
        jPanelCentral.add(messageLabel, java.awt.BorderLayout.SOUTH);
189
        
182
190
    }
183
    }
191
    
184
192
    private void disablePanel (javax.swing.JPanel panel) 
185
    private void disablePanel(javax.swing.JPanel panel) {
193
    {
194
        Component[] components = panel.getComponents();
186
        Component[] components = panel.getComponents();
195
        for (Component comp : components)
187
        for (Component comp : components) {
196
        {
188
            if (!(comp instanceof javax.swing.JLabel)) {
197
            if (!(comp instanceof javax.swing.JLabel)) 
189
                if (comp.isEnabled()) {
198
            {
199
                if (comp.isEnabled())
200
                    comp.setEnabled(false);
190
                    comp.setEnabled(false);
191
                }
201
            }
192
            }
202
        }
193
        }
203
    }
194
    }
204
        
195
205
    private void disableAllComponents() {
196
    private void disableAllComponents() {
206
//        disablePanel(codeGenPanel);
197
//        disablePanel(codeGenPanel);
207
        disablePanel(javaProjectPanel);
198
        disablePanel(javaProjectPanel);
208
    }
199
    }
209
        
200
210
    private void testBroken()
201
    private void testBroken() {
211
    {
212
        boolean isBroken = false;
202
        boolean isBroken = false;
213
        
203
214
        if (mUIProperties.referencedJavaProjectModel.getRefStatus() == 
204
        if (mUIProperties.referencedJavaProjectModel.getRefStatus()
215
            ReferencedJavaProjectModel.ReferenceStatus.REF_STATUS_BROKEN)
205
                == ReferencedJavaProjectModel.ReferenceStatus.REF_STATUS_BROKEN) {
216
        {
217
            isBroken = true;
206
            isBroken = true;
218
        }
207
        }
219
        
208
220
        if (isBroken == true)
209
        if (isBroken == true) {
221
        {
222
            messageLabel.setText(
210
            messageLabel.setText(
223
                NbBundle.getMessage(
211
                    NbBundle.getMessage(
224
                CustomizerModeling.class, 
212
                    CustomizerModeling.class,
225
                "LBL_CustomizeModeling_Reference_Error"));
213
                    "LBL_CustomizeModeling_Reference_Error"));
214
        } else {
215
            messageLabel.setText(" ");
226
        }
216
        }
227
        
228
        else
229
            messageLabel.setText(" ");
230
    }
217
    }
231
    
232
233
    // Variables declaration - do not modify//GEN-BEGIN:variables
218
    // Variables declaration - do not modify//GEN-BEGIN:variables
234
    private javax.swing.JLabel jLabel1;
219
    private javax.swing.JLabel jLabel1;
235
    private javax.swing.JPanel jPanel1;
220
    private javax.swing.JPanel jPanel1;
236
    private javax.swing.JPanel jPanelCentral;
221
    private javax.swing.JPanel jPanelCentral;
237
    private javax.swing.JTextField projectLocation;
222
    private javax.swing.JTextField projectLocation;
238
    // End of variables declaration//GEN-END:variables
223
    // End of variables declaration//GEN-END:variables
239
    
240
//    private PanelProjectMode projectModePanel;
224
//    private PanelProjectMode projectModePanel;
241
//    private PanelCodeGen codeGenPanel;
225
//    private PanelCodeGen codeGenPanel;
242
    private ReferencedJavaProjectPanel javaProjectPanel;
226
    private ReferencedJavaProjectPanel javaProjectPanel;
243
    //private JTextArea messageLabel = null;
227
    //private JTextArea messageLabel = null;
244
    private JLabel messageLabel = null;
228
    private JLabel messageLabel = null;
245
    private ModeChangeListener mChangeListener = new ModeChangeListener();
229
    private ModeChangeListener mChangeListener = new ModeChangeListener();
246
    
230
247
    public class ModeChangeListener implements PropertyChangeListener
231
    public class ModeChangeListener implements PropertyChangeListener {
248
    {
232
249
        private boolean mIsEnabled = true;
233
        private boolean mIsEnabled = true;
250
        
234
251
        public void propertyChange(PropertyChangeEvent evt)
235
        public void propertyChange(PropertyChangeEvent evt) {
252
        {
236
            if (ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP.equals(evt.getPropertyName()) == true) {
253
            if (ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP
254
                .equals(evt.getPropertyName()) == true)
255
            {
256
                testBroken();
237
                testBroken();
257
                
238
258
                firePropertyChange(
239
                firePropertyChange(
259
                    CustomizerPane.OK_ENABLE_PROPERTY, mIsEnabled, true);
240
                        CustomizerPane.OK_ENABLE_PROPERTY, mIsEnabled, true);
260
                
241
261
                mIsEnabled = true;
242
                mIsEnabled = true;
262
            }
243
            } else if (ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP.equals(evt.getPropertyName())) {
263
            
264
            else if (ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP
265
                .equals(evt.getPropertyName())) 
266
            {  
267
                String message = "";
244
                String message = "";
268
                Object newVal = evt.getNewValue();
245
                Object newVal = evt.getNewValue();
269
                boolean enabled = true;
246
                boolean enabled = true;
270
                
247
271
                if (newVal instanceof Boolean) 
248
                if (newVal instanceof Boolean) {
272
                    enabled = ((Boolean) newVal).booleanValue();
249
                    enabled = ((Boolean) newVal).booleanValue();
273
 
250
                }
274
                if (!enabled) 
251
275
                {
252
                if (!enabled) {
276
                    message = NbBundle.getMessage(
253
                    message = NbBundle.getMessage(
277
                        CustomizerModeling.class, "SourceGroup_Warning"); //NOI18N 
254
                            CustomizerModeling.class, "SourceGroup_Warning"); //NOI18N
278
                }
255
                }
279
                
256
280
                messageLabel.setText(message); 
257
                messageLabel.setText(message);
281
                
258
282
                firePropertyChange(
259
                firePropertyChange(
283
                    CustomizerPane.OK_ENABLE_PROPERTY, mIsEnabled, enabled);
260
                        CustomizerPane.OK_ENABLE_PROPERTY, mIsEnabled, enabled);
284
                
261
285
                mIsEnabled = enabled;
262
                mIsEnabled = enabled;
286
            }
263
            }
287
            
264
288
//            else if(ReferencedJavaProjectPanel.JAVA_PROJECT_CHANGED_PROP
265
//            else if(ReferencedJavaProjectPanel.JAVA_PROJECT_CHANGED_PROP
289
//                .equals(evt.getPropertyName()))
266
//                .equals(evt.getPropertyName()))
290
//            {
267
//            {
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/CustomizerProviderImpl.java (-97 / +68 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.customizer;
44
package org.netbeans.modules.uml.project.ui.customizer;
46
45
47
import java.awt.Dialog;
46
import java.awt.Dialog;
Lines 73-146 Link Here
73
import org.openide.util.Lookup;
72
import org.openide.util.Lookup;
74
import org.openide.util.lookup.Lookups;
73
import org.openide.util.lookup.Lookups;
75
74
76
77
/** Customization of UML project
75
/** Customization of UML project
78
 *
76
 *
79
 * @author Mike Frisino
77
 * @author Mike Frisino
80
 */
78
 */
81
public class CustomizerProviderImpl implements CustomizerProvider
79
public class CustomizerProviderImpl implements CustomizerProvider {
82
{
80
83
    private final Project project;
81
    private final Project project;
84
    private final UMLProjectHelper projectHelper;
82
    private final UMLProjectHelper projectHelper;
85
    private final PropertyEvaluator evaluator;
83
    private final PropertyEvaluator evaluator;
86
    private final ReferenceHelper refHelper;
84
    private final ReferenceHelper refHelper;
87
    
88
    private ProjectCustomizer.Category categories[];
85
    private ProjectCustomizer.Category categories[];
89
    private ProjectCustomizer.CategoryComponentProvider panelProvider;
86
    private ProjectCustomizer.CategoryComponentProvider panelProvider;
90
    public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-uml-project/Customizer"; //NO18N
87
    public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-uml-project/Customizer"; //NO18N
88
    private static Map /*<Project,Dialog>*/ project2Dialog = new HashMap();
91
89
92
    private static Map /*<Project,Dialog>*/project2Dialog = new HashMap();
93
    
94
    public CustomizerProviderImpl(
90
    public CustomizerProviderImpl(
95
        Project project,
91
            Project project,
96
        UMLProjectHelper projectHelper,
92
            UMLProjectHelper projectHelper,
97
        PropertyEvaluator evaluator,
93
            PropertyEvaluator evaluator,
98
        ReferenceHelper refHelper)
94
            ReferenceHelper refHelper) {
99
    {
100
        this.project = project;
95
        this.project = project;
101
        this.projectHelper = projectHelper;
96
        this.projectHelper = projectHelper;
102
        this.evaluator = evaluator;
97
        this.evaluator = evaluator;
103
        this.refHelper = refHelper;
98
        this.refHelper = refHelper;
104
    }
99
    }
105
    
100
106
    public void showCustomizer()
101
    public void showCustomizer() {
107
    {
102
        showCustomizer(null);
108
        showCustomizer( null );
109
    }
103
    }
110
    
104
111
    
105
    public void showCustomizer(String preselectedCategory) {
112
    public void showCustomizer(String preselectedCategory)
113
    {
114
        showCustomizer(preselectedCategory, null);
106
        showCustomizer(preselectedCategory, null);
115
    }
107
    }
116
    
108
117
    public void showCustomizer(
109
    public void showCustomizer(
118
        String preselectedCategory, String preselectedSubCategory)
110
            String preselectedCategory, String preselectedSubCategory) {
119
    {
111
        Dialog dialog = (Dialog) project2Dialog.get(project);
120
        Dialog dialog = (Dialog)project2Dialog.get(project);
121
112
122
        if (dialog != null)
113
        if (dialog != null) {
123
        {
124
            dialog.setVisible(true);
114
            dialog.setVisible(true);
125
            return;
115
            return;
126
        }
116
        } else {
117
            UMLProjectProperties uiProperties = new UMLProjectProperties(
118
                    (UMLProject) project, projectHelper, evaluator, refHelper);
127
119
128
        else
120
            Lookup context = Lookups.fixed(new Object[]{
129
        {
121
                        project,
130
            UMLProjectProperties uiProperties = new UMLProjectProperties(
122
                        uiProperties,
131
                (UMLProject)project, projectHelper, evaluator, refHelper);
123
                        new SubCategoryProvider(preselectedCategory, preselectedSubCategory)
132
            
124
                    });
133
            Lookup context = Lookups.fixed(new Object[] {
134
                project,
135
                uiProperties,
136
                new SubCategoryProvider(preselectedCategory, preselectedSubCategory)
137
            });
138
//            init(uiProperties);
125
//            init(uiProperties);
139
            
126
140
            OptionListener listener = new OptionListener( project, uiProperties );
127
            OptionListener listener = new OptionListener(project, uiProperties);
141
            
128
142
            HelpCtx helpCtx = new HelpCtx(
129
            HelpCtx helpCtx = new HelpCtx(
143
                "org.netbeans.modules.uml.project.ui.customizer.UMLCustomizer" ); // NOI18N
130
                    "org.netbeans.modules.uml.project.ui.customizer.UMLCustomizer"); // NOI18N
144
131
145
//            if (preselectedCategory != null && preselectedSubCategory != null)
132
//            if (preselectedCategory != null && preselectedSubCategory != null)
146
//            {
133
//            {
Lines 165-185 Link Here
165
//            dialog = UMLCustomizerDialog.createCustomizerDialog(
152
//            dialog = UMLCustomizerDialog.createCustomizerDialog(
166
//                categories, panelProvider, 
153
//                categories, panelProvider, 
167
//                preselectedCategory, listener, helpCtx);
154
//                preselectedCategory, listener, helpCtx);
168
            dialog = ProjectCustomizer.createCustomizerDialog( CUSTOMIZER_FOLDER_PATH, context, preselectedCategory, listener, null );
155
            dialog = ProjectCustomizer.createCustomizerDialog(CUSTOMIZER_FOLDER_PATH, context, preselectedCategory, listener, null);
169
            
156
170
            dialog.addWindowListener(listener);
157
            dialog.addWindowListener(listener);
171
            
158
172
            dialog.setTitle(MessageFormat.format(
159
            dialog.setTitle(MessageFormat.format(
173
                NbBundle.getMessage(
160
                    NbBundle.getMessage(
174
                    CustomizerProviderImpl.class, "LBL_Customizer_Title"), // NOI18N
161
                    CustomizerProviderImpl.class, "LBL_Customizer_Title"), // NOI18N
175
                    new Object[] 
162
                    new Object[]{ProjectUtils.getInformation(project).getDisplayName()}));
176
                        {ProjectUtils.getInformation(project).getDisplayName()}));
163
177
            
178
            project2Dialog.put(project, dialog);
164
            project2Dialog.put(project, dialog);
179
            dialog.setVisible(true);
165
            dialog.setVisible(true);
180
        }
166
        }
181
    }
167
    }
182
    
168
183
//    // Names of categories
169
//    // Names of categories
184
//    private static final String MODELING_CATEGORY = "ModelingCategory"; // NOI18N
170
//    private static final String MODELING_CATEGORY = "ModelingCategory"; // NOI18N
185
//    private static final String IMPORTS_CATEGORY = "ImportsCategory"; // NOI18N
171
//    private static final String IMPORTS_CATEGORY = "ImportsCategory"; // NOI18N
Lines 237-338 Link Here
237
//            return panel == null ? EMPTY_PANEL : panel;
223
//            return panel == null ? EMPTY_PANEL : panel;
238
//        }
224
//        }
239
//    }
225
//    }
240
    
241
    /** Listens to the actions on the Customizer's option buttons */
226
    /** Listens to the actions on the Customizer's option buttons */
242
    private class OptionListener extends WindowAdapter implements ActionListener
227
    private class OptionListener extends WindowAdapter implements ActionListener {
243
    {
228
244
        private Project project;
229
        private Project project;
245
        private UMLProjectProperties uiProperties;
230
        private UMLProjectProperties uiProperties;
246
        
231
247
        OptionListener( Project project, UMLProjectProperties uiProperties )
232
        OptionListener(Project project, UMLProjectProperties uiProperties) {
248
        {
249
            this.project = project;
233
            this.project = project;
250
            this.uiProperties = uiProperties;
234
            this.uiProperties = uiProperties;
251
        }
235
        }
252
        
236
253
        // Listening to OK button ----------------------------------------------
237
        // Listening to OK button ----------------------------------------------
254
        
238
        public void actionPerformed(ActionEvent e) {
255
        public void actionPerformed( ActionEvent e )
256
        {
257
            ReferencedJavaProjectModel m = uiProperties.referencedJavaProjectModel;
239
            ReferencedJavaProjectModel m = uiProperties.referencedJavaProjectModel;
258
            
240
259
            if (uiProperties.getProjectMode().equals(UMLProject.PROJECT_MODE_IMPL_STR) &&
241
            if (uiProperties.getProjectMode().equals(UMLProject.PROJECT_MODE_IMPL_STR)
260
                m.getRefStatus() != ReferencedJavaProjectModel.ReferenceStatus.REF_STATUS_BROKEN)
242
                    && m.getRefStatus() != ReferencedJavaProjectModel.ReferenceStatus.REF_STATUS_BROKEN) {
261
            {
262
                // Store the properties into project
243
                // Store the properties into project
263
                AssociatedSourceProvider asp = 
244
                AssociatedSourceProvider asp =
264
                    (AssociatedSourceProvider) uiProperties.getProject()
245
                        (AssociatedSourceProvider) uiProperties.getProject().getLookup().lookup(AssociatedSourceProvider.class);
265
                    .getLookup().lookup(AssociatedSourceProvider.class);
246
266
                
267
                Project oldProject = asp.getAssociatedSourceProject();
247
                Project oldProject = asp.getAssociatedSourceProject();
268
                SourceGroup[] oldGroup =asp.getSourceGroups();
248
                SourceGroup[] oldGroup = asp.getSourceGroups();
269
                uiProperties.save();
249
                uiProperties.save();
270
                Project newProject = asp.getAssociatedSourceProject();
250
                Project newProject = asp.getAssociatedSourceProject();
271
                SourceGroup[] newGroup =asp.getSourceGroups();
251
                SourceGroup[] newGroup = asp.getSourceGroups();
272
                
252
273
                if (oldProject!=null && !oldProject.equals(newProject))
253
                if (oldProject != null && !oldProject.equals(newProject)) {
274
                {
275
                    Log.out("Project is changed in the Customizer");
254
                    Log.out("Project is changed in the Customizer");
276
                    MDREventProcessor.getInstance().fireChanged(oldGroup,newGroup);
255
                    MDREventProcessor.getInstance().fireChanged(oldGroup, newGroup);
277
                }
256
                } else if (newProject != null && oldProject == null) {
278
                
279
                else if (newProject!=null && oldProject == null)
280
                {
281
                    Log.out("Project is changed in the Customizer");
257
                    Log.out("Project is changed in the Customizer");
282
                    MDREventProcessor.getInstance().fireChanged(null,newGroup);
258
                    MDREventProcessor.getInstance().fireChanged(null, newGroup);
283
                }
259
                }
284
            }
260
            }
285
            
261
286
            // uiProperties.setCodeGenTemplates();
262
            // uiProperties.setCodeGenTemplates();
287
263
288
            
264
289
            // Close & dispose the dialog
265
            // Close & dispose the dialog
290
            Dialog dialog = (Dialog)project2Dialog.get( project );
266
            Dialog dialog = (Dialog) project2Dialog.get(project);
291
            if (dialog != null)
267
            if (dialog != null) {
292
            {
293
                dialog.setVisible(false);
268
                dialog.setVisible(false);
294
                dialog.dispose();
269
                dialog.dispose();
295
            }
270
            }
296
        }
271
        }
297
        
272
298
        // Listening to window events ------------------------------------------
273
        // Listening to window events ------------------------------------------
299
        
274
        public void windowClosed(WindowEvent e) {
300
        public void windowClosed( WindowEvent e)
275
            project2Dialog.remove(project);
301
        {
302
            project2Dialog.remove( project );
303
        }
276
        }
304
        
277
305
        public void windowClosing(WindowEvent e)
278
        public void windowClosing(WindowEvent e) {
306
        {
307
            //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
279
            //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
308
            //may not be called
280
            //may not be called
309
            Dialog dialog = (Dialog)project2Dialog.get( project );
281
            Dialog dialog = (Dialog) project2Dialog.get(project);
310
            if (dialog != null)
282
            if (dialog != null) {
311
            {
312
                dialog.setVisible(false);
283
                dialog.setVisible(false);
313
                dialog.dispose();
284
                dialog.dispose();
314
            }
285
            }
315
        }
286
        }
316
    }
287
    }
317
    
288
318
//    static interface SubCategoryProvider
289
//    static interface SubCategoryProvider
319
//    {
290
//    {
320
//        public void showSubCategory(String name);
291
//        public void showSubCategory(String name);
321
//    }
292
//    }
322
    
323
    static final class SubCategoryProvider {
293
    static final class SubCategoryProvider {
324
294
325
        private String subcategory;
295
        private String subcategory;
326
327
        private String category;
296
        private String category;
328
297
329
        SubCategoryProvider(String category, String subcategory) {
298
        SubCategoryProvider(String category, String subcategory) {
330
            this.category = category;
299
            this.category = category;
331
            this.subcategory = subcategory;
300
            this.subcategory = subcategory;
332
        }
301
        }
302
333
        public String getCategory() {
303
        public String getCategory() {
334
            return category;
304
            return category;
335
        }
305
        }
306
336
        public String getSubcategory() {
307
        public String getSubcategory() {
337
            return subcategory;
308
            return subcategory;
338
        }
309
        }
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/ImportElementListener.java (-5 / +3 lines)
Lines 51-62 Link Here
51
 * the Source Creation and Management node. Right-click the template and choose
51
 * the Source Creation and Management node. Right-click the template and choose
52
 * Open. You can then make changes to the template in the Source Editor.
52
 * Open. You can then make changes to the template in the Source Editor.
53
 */
53
 */
54
55
package org.netbeans.modules.uml.project.ui.customizer;
54
package org.netbeans.modules.uml.project.ui.customizer;
56
55
57
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElementImport;
56
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElementImport;
58
import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackageImport;
57
import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackageImport;
59
import org.netbeans.modules.uml.project.UMLProject;
60
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
58
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
61
import org.netbeans.modules.uml.core.metamodel.structure.IProject;
59
import org.netbeans.modules.uml.core.metamodel.structure.IProject;
62
60
Lines 64-73 Link Here
64
 *
62
 *
65
 * @author Trey Spiva
63
 * @author Trey Spiva
66
 */
64
 */
67
public interface ImportElementListener
65
public interface ImportElementListener {
68
{
66
69
    public void elementImported(IProject project, IElement element, IElementImport importElement);
67
    public void elementImported(IProject project, IElement element, IElementImport importElement);
70
    
68
71
    public void elementDeleted(IProject project, IElement element);
69
    public void elementDeleted(IProject project, IElement element);
72
70
73
    public void packageImported(IProject project, IElement element, IPackageImport importElement);
71
    public void packageImported(IProject project, IElement element, IPackageImport importElement);
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/PanelUmlImports.form (-1 / +3 lines)
Lines 1-4 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.1" encoding="UTF-8" ?>
2
2
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AccessibilityProperties>
4
  <AccessibilityProperties>
Lines 6-11 Link Here
6
    <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
6
    <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
7
  </AccessibilityProperties>
7
  </AccessibilityProperties>
8
  <AuxValues>
8
  <AuxValues>
9
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
11
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
10
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
12
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
13
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/PanelUmlImports.java (-4 lines)
Lines 44-56 Link Here
44
44
45
package org.netbeans.modules.uml.project.ui.customizer;
45
package org.netbeans.modules.uml.project.ui.customizer;
46
46
47
import java.awt.Image;
48
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeEvent;
49
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyChangeListener;
50
import java.net.URL;
51
49
52
import javax.swing.Icon;
50
import javax.swing.Icon;
53
import javax.swing.ImageIcon;
54
import javax.swing.JPanel;
51
import javax.swing.JPanel;
55
import javax.swing.table.DefaultTableCellRenderer;
52
import javax.swing.table.DefaultTableCellRenderer;
56
import javax.swing.table.TableColumn;
53
import javax.swing.table.TableColumn;
Lines 58-64 Link Here
58
import org.netbeans.modules.uml.resources.images.ImageUtil;
55
import org.netbeans.modules.uml.resources.images.ImageUtil;
59
import org.netbeans.modules.uml.project.UMLProject;
56
import org.netbeans.modules.uml.project.UMLProject;
60
57
61
import org.openide.util.Utilities;
62
58
63
59
64
60
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/UMLImportsSupport.java (-2 lines)
Lines 47-54 Link Here
47
import java.io.File;
47
import java.io.File;
48
import java.net.URI;
48
import java.net.URI;
49
import java.util.ArrayList;
49
import java.util.ArrayList;
50
import java.util.Arrays;
51
import java.util.HashSet;
52
import java.util.Iterator;
50
import java.util.Iterator;
53
import java.util.List;
51
import java.util.List;
54
import java.util.Set;
52
import java.util.Set;
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/UMLImportsUiSupport.java (-276 / +205 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
package org.netbeans.modules.uml.project.ui.customizer;
44
45
45
package org.netbeans.modules.uml.project.ui.customizer;
46
import org.netbeans.modules.uml.project.ProjectUtil;
46
import org.netbeans.modules.uml.project.ProjectUtil;
47
import org.netbeans.modules.uml.project.UMLProject;
47
import org.netbeans.modules.uml.project.UMLProject;
48
import org.netbeans.modules.uml.project.UMLProjectHelper;
48
import org.netbeans.modules.uml.project.UMLProjectHelper;
Lines 63-69 Link Here
63
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElementImport;
63
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElementImport;
64
import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
64
import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
65
import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackageImport;
65
import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackageImport;
66
import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
67
import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackage;
66
import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackage;
68
import org.netbeans.modules.uml.core.metamodel.profiles.IProfile;
67
import org.netbeans.modules.uml.core.metamodel.profiles.IProfile;
69
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
68
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
Lines 83-107 Link Here
83
 *
82
 *
84
 * @author Mike Frisino
83
 * @author Mike Frisino
85
 */
84
 */
86
public class UMLImportsUiSupport
85
public class UMLImportsUiSupport {
87
{
86
88
    
89
    //TODO - fix the table values so that they are user friendly instead of
87
    //TODO - fix the table values so that they are user friendly instead of
90
    // current object.toString
88
    // current object.toString
91
    
92
    private UMLImportsSupport importSupport;
89
    private UMLImportsSupport importSupport;
93
    private ImportListener impListener;
90
    private ImportListener impListener;
94
    public static final int COL_UML_PROJECT_NAME = 0;
91
    public static final int COL_UML_PROJECT_NAME = 0;
95
    public static final int COL_UML_PROJECT_FOLDER = 1;
92
    public static final int COL_UML_PROJECT_FOLDER = 1;
96
    
97
    private UMLProject mProject = null;
93
    private UMLProject mProject = null;
98
    private ArrayList < ImportElementListener > mImportListeners = new ArrayList <ImportElementListener> ();
94
    private ArrayList<ImportElementListener> mImportListeners = new ArrayList<ImportElementListener>();
99
    private HashMap importedElements = null;
95
    private HashMap importedElements = null;
100
    
96
101
    public UMLImportsUiSupport(UMLProject project)
97
    public UMLImportsUiSupport(UMLProject project) {
102
    {
103
        mProject = project;
98
        mProject = project;
104
        
99
105
////        RequestProcessor.getDefault().post(new Runnable()
100
////        RequestProcessor.getDefault().post(new Runnable()
106
////        {
101
////        {
107
////            public void run()
102
////            public void run()
Lines 120-243 Link Here
120
////        DispatchHelper helper = new DispatchHelper();
115
////        DispatchHelper helper = new DispatchHelper();
121
////        helper.registerForImportEventsSink(new ImportListener());
116
////        helper.registerForImportEventsSink(new ImportListener());
122
    }
117
    }
123
            
118
124
    public void initializeProject()
119
    public void initializeProject() {
125
    {
126
//        System.err.println("UMLImportsUiSupport:Loading");
120
//        System.err.println("UMLImportsUiSupport:Loading");
127
        impListener = new ImportListener();
121
        impListener = new ImportListener();
128
        IElementChangeEventDispatcher disp = null;
122
        IElementChangeEventDispatcher disp = null;
129
        IElementLifeTimeEventDispatcher lifeTimeDisp = null;
123
        IElementLifeTimeEventDispatcher lifeTimeDisp = null;
130
        EventDispatchRetriever ret = EventDispatchRetriever.instance();
124
        EventDispatchRetriever ret = EventDispatchRetriever.instance();
131
        disp = (IElementChangeEventDispatcher)ret.getDispatcher(EventDispatchNameKeeper.modifiedName());
125
        disp = (IElementChangeEventDispatcher) ret.getDispatcher(EventDispatchNameKeeper.modifiedName());
132
        lifeTimeDisp = (IElementLifeTimeEventDispatcher)ret.getDispatcher(EventDispatchNameKeeper.lifeTime());
126
        lifeTimeDisp = (IElementLifeTimeEventDispatcher) ret.getDispatcher(EventDispatchNameKeeper.lifeTime());
133
        disp.registerForImportEventsSink(impListener);
127
        disp.registerForImportEventsSink(impListener);
134
        lifeTimeDisp.registerForLifeTimeEvents(impListener);
128
        lifeTimeDisp.registerForLifeTimeEvents(impListener);
135
    }
129
    }
136
130
137
    public void unInitializeProject()
131
    public void unInitializeProject() {
138
    {
139
        IElementChangeEventDispatcher disp = null;
132
        IElementChangeEventDispatcher disp = null;
140
        IElementLifeTimeEventDispatcher lifeTimeDisp = null;
133
        IElementLifeTimeEventDispatcher lifeTimeDisp = null;
141
        EventDispatchRetriever ret = EventDispatchRetriever.instance();
134
        EventDispatchRetriever ret = EventDispatchRetriever.instance();
142
        disp = (IElementChangeEventDispatcher)ret.getDispatcher(EventDispatchNameKeeper.modifiedName());
135
        disp = (IElementChangeEventDispatcher) ret.getDispatcher(EventDispatchNameKeeper.modifiedName());
143
        lifeTimeDisp = (IElementLifeTimeEventDispatcher)ret.getDispatcher(EventDispatchNameKeeper.lifeTime());
136
        lifeTimeDisp = (IElementLifeTimeEventDispatcher) ret.getDispatcher(EventDispatchNameKeeper.lifeTime());
144
        disp.revokeImportEventsSink(impListener);
137
        disp.revokeImportEventsSink(impListener);
145
        lifeTimeDisp.revokeLifeTimeSink(impListener);
138
        lifeTimeDisp.revokeLifeTimeSink(impListener);
146
    }
139
    }
147
    
140
148
    public void addImportElementListener(ImportElementListener listener)
141
    public void addImportElementListener(ImportElementListener listener) {
149
    {
150
        mImportListeners.add(listener);
142
        mImportListeners.add(listener);
151
    }
143
    }
152
    
144
153
    public void removeImportElementListener(ImportElementListener listener)
145
    public void removeImportElementListener(ImportElementListener listener) {
154
    {
155
        mImportListeners.remove(listener);
146
        mImportListeners.remove(listener);
156
    }
147
    }
157
    
148
158
    public void fireElementImported(IProject project, 
149
    public void fireElementImported(IProject project,
159
                                    IElement element,
150
            IElement element,
160
                                    IElementImport importElement)
151
            IElementImport importElement) {
161
    {
152
        for (ImportElementListener listener : mImportListeners) {
162
        for(ImportElementListener listener : mImportListeners)
163
        {
164
            listener.elementImported(project, element, importElement);
153
            listener.elementImported(project, element, importElement);
165
        }
154
        }
166
    }
155
    }
167
    
156
168
    public void firePackageImported(IProject project, 
157
    public void firePackageImported(IProject project,
169
                                    IElement element,
158
            IElement element,
170
                                    IPackageImport importElement)
159
            IPackageImport importElement) {
171
    {
160
        for (ImportElementListener listener : mImportListeners) {
172
        for(ImportElementListener listener : mImportListeners)
173
        {
174
            listener.packageImported(project, element, importElement);
161
            listener.packageImported(project, element, importElement);
175
        }
162
        }
176
    }
163
    }
177
    
164
178
    public void fireElementDeleted(IProject project, IElement element)
165
    public void fireElementDeleted(IProject project, IElement element) {
179
    {
166
        for (ImportElementListener listener : mImportListeners) {
180
        for(ImportElementListener listener : mImportListeners)
181
        {
182
            listener.elementDeleted(project, element);
167
            listener.elementDeleted(project, element);
183
        }
168
        }
184
    }
169
    }
185
    
170
186
    ////////////////////////////////////////////////////////////////////////////
171
    ////////////////////////////////////////////////////////////////////////////
187
    // Methods for working with list models ------------------------------------
172
    // Methods for working with list models ------------------------------------
188
    
173
    public static DefaultTableModel createTableModel(Iterator it) {
189
    public static DefaultTableModel createTableModel( Iterator it )
174
190
    {
191
        
192
        DefaultTableModel model = new UMLImportsModel(new Object[0][0]);
175
        DefaultTableModel model = new UMLImportsModel(new Object[0][0]);
193
        
176
194
        
177
195
        while( it.hasNext() )
178
        while (it.hasNext()) {
196
        {
197
            Object curItem = it.next();
179
            Object curItem = it.next();
198
            
180
199
            Object[] data = new Object[2];
181
            Object[] data = new Object[2];
200
            data[COL_UML_PROJECT_NAME] = curItem;
182
            data[COL_UML_PROJECT_NAME] = curItem;
201
            if(curItem instanceof UMLImportsSupport.Item)
183
            if (curItem instanceof UMLImportsSupport.Item) {
202
            {
184
                UMLImportsSupport.Item item = (UMLImportsSupport.Item) curItem;
203
                UMLImportsSupport.Item item = (UMLImportsSupport.Item)curItem;                
204
                data[COL_UML_PROJECT_FOLDER] = item.getDirectoryLocation();
185
                data[COL_UML_PROJECT_FOLDER] = item.getDirectoryLocation();
205
            }
186
            } else {
206
            else
207
            {
208
                data[COL_UML_PROJECT_FOLDER] = "";
187
                data[COL_UML_PROJECT_FOLDER] = "";
209
            }
188
            }
210
            
189
211
            model.addRow(data);
190
            model.addRow(data);
212
        }
191
        }
213
        
192
214
        return model;
193
        return model;
215
    }
194
    }
216
    
195
217
    
196
    public static class UMLImportsModel extends DefaultTableModel {
218
    public static class UMLImportsModel extends DefaultTableModel
197
219
    {
220
        
221
        
222
        static String colProjLabel = (NbBundle.getMessage(UMLImportsUiSupport.class,
198
        static String colProjLabel = (NbBundle.getMessage(UMLImportsUiSupport.class,
223
                "LBL_ImportedProjectsColProject")); //NOI18N
199
                "LBL_ImportedProjectsColProject")); //NOI18N
224
        static String colProjFolder = (NbBundle.getMessage(UMLImportsUiSupport.class,
200
        static String colProjFolder = (NbBundle.getMessage(UMLImportsUiSupport.class,
225
                "LBL_ImportedProjectsColFolder")); //NOI18N
201
                "LBL_ImportedProjectsColFolder")); //NOI18N
226
        
202
227
        public UMLImportsModel(Object[][] data)
203
        public UMLImportsModel(Object[][] data) {
228
        {
204
            super(data, new Object[]{colProjLabel, colProjFolder});
229
            super(data, new Object[]{colProjLabel,colProjFolder});
230
        }
205
        }
231
        
206
232
        public boolean isCellEditable(int row, int column)
207
        public boolean isCellEditable(int row, int column) {
233
        {
234
            return false;
208
            return false;
235
        }
209
        }
236
        
210
237
        public Class getColumnClass(int columnIndex)
211
        public Class getColumnClass(int columnIndex) {
238
        {
212
            switch (columnIndex) {
239
            switch (columnIndex)
240
            {
241
                case COL_UML_PROJECT_NAME:
213
                case COL_UML_PROJECT_NAME:
242
                    return Object.class;
214
                    return Object.class;
243
                case COL_UML_PROJECT_FOLDER:
215
                case COL_UML_PROJECT_FOLDER:
Lines 247-399 Link Here
247
            }
219
            }
248
        }
220
        }
249
    }
221
    }
250
    
222
251
    
223
    public static Iterator getIterator(DefaultTableModel model) {
252
    
253
    public static Iterator getIterator( DefaultTableModel model )
254
    {
255
        // XXX Better performing impl. would be nice
224
        // XXX Better performing impl. would be nice
256
        return getList( model ).iterator();
225
        return getList(model).iterator();
257
    }
226
    }
258
    
227
259
    public static List getList( DefaultTableModel model )
228
    public static List getList(DefaultTableModel model) {
260
    {
229
261
        
262
        List list = new ArrayList();
230
        List list = new ArrayList();
263
        for(int i=0; i< model.getRowCount(); i++)
231
        for (int i = 0; i < model.getRowCount(); i++) {
264
        {
232
            list.add(model.getValueAt(i, COL_UML_PROJECT_NAME));
265
            list.add(model.getValueAt(i,COL_UML_PROJECT_NAME));
266
        }
233
        }
267
        return list;
234
        return list;
268
    }
235
    }
269
    
236
270
    
237
    public static int[] addArtifacts(DefaultTableModel tableModel, AntArtifactChooser.ArtifactItem artifactItems[]) {
271
    
238
272
    public static int[] addArtifacts( DefaultTableModel tableModel, AntArtifactChooser.ArtifactItem artifactItems[] )
273
    {
274
        
275
        // int lastIndex = indices == null || indices.length == 0 ? -1 : indices[indices.length - 1];
239
        // int lastIndex = indices == null || indices.length == 0 ? -1 : indices[indices.length - 1];
276
        int[] indexes = new int[artifactItems.length];
240
        int[] indexes = new int[artifactItems.length];
277
        for( int i = 0; i < artifactItems.length; i++ )
241
        for (int i = 0; i < artifactItems.length; i++) {
278
        {
242
279
            
280
            //   int current = lastIndex + 1 + i;
243
            //   int current = lastIndex + 1 + i;
281
            UMLImportsSupport.Item item = UMLImportsSupport.Item.create(
244
            UMLImportsSupport.Item item = UMLImportsSupport.Item.create(
282
                    artifactItems[i].getArtifact(), artifactItems[i].getArtifactURI(), null ) ;
245
                    artifactItems[i].getArtifact(), artifactItems[i].getArtifactURI(), null);
283
            boolean alreadyListed = false;
246
            boolean alreadyListed = false;
284
            for(int j=0; j<tableModel.getRowCount();j ++)
247
            for (int j = 0; j < tableModel.getRowCount(); j++) {
285
            {
248
286
                
249
                if (tableModel.getValueAt(j, COL_UML_PROJECT_NAME) == item) {
287
                if (tableModel.getValueAt(j, COL_UML_PROJECT_NAME) == item )
288
                {
289
                    alreadyListed = true;
250
                    alreadyListed = true;
290
                    break;
251
                    break;
291
                }
252
                }
292
            }
253
            }
293
            if(! alreadyListed)
254
            if (!alreadyListed) {
294
                tableModel.addRow(new Object[] {item, "TODO"} );
255
                tableModel.addRow(new Object[]{item, "TODO"});
295
                
256
            }
257
296
        }
258
        }
297
        return indexes;
259
        return indexes;
298
    }
260
    }
299
    
261
300
    protected boolean inSameProject(IElement element)
262
    protected boolean inSameProject(IElement element) {
301
    {
302
        boolean retVal = false;
263
        boolean retVal = false;
303
        
264
304
        if((element != null) && (mProject != null))
265
        if ((element != null) && (mProject != null)) {
305
        {
266
            UMLProjectHelper helper = (UMLProjectHelper) mProject.getLookup().lookup(UMLProjectHelper.class);
306
            UMLProjectHelper helper = (UMLProjectHelper)mProject.getLookup().lookup(UMLProjectHelper.class);
267
            if (helper != null) {
307
            if(helper != null)
308
            {
309
                IProject project = helper.getProject();
268
                IProject project = helper.getProject();
310
                retVal = element.inSameProject(project);
269
                retVal = element.inSameProject(project);
311
            }
270
            }
312
        }
271
        }
313
        
272
314
        return retVal;
273
        return retVal;
315
    }
274
    }
316
    
275
317
    protected void modelElementImported(IPackage importingPackage, 
276
    protected void modelElementImported(IPackage importingPackage,
318
                                        IElement element,
277
            IElement element,
319
                                        IElementImport importedElement)
278
            IElementImport importedElement) {
320
    {
321
//        if((element != null) && (inSameProject(importingPackage) == true))
279
//        if((element != null) && (inSameProject(importingPackage) == true))
322
//        {
280
//        {
323
            IProject p = ProjectUtil.getOwningProjectOfImportedElement(element);
281
        IProject p = ProjectUtil.getOwningProjectOfImportedElement(element);
324
            Project foundProject = ProjectUtil.findElementOwner(p);
282
        Project foundProject = ProjectUtil.findElementOwner(p);
325
            Project referencingProject = ProjectUtil.findReferencingProject(importedElement);
283
        Project referencingProject = ProjectUtil.findReferencingProject(importedElement);
326
            
327
            // add reference to the project only if it differes from the owner
328
            if((foundProject instanceof UMLProject) && 
329
               (referencingProject  instanceof UMLProject) && 
330
               (foundProject != referencingProject))
331
            {
332
                UMLProject umlProject = (UMLProject)foundProject;   
333
                UMLProject umlRefProject = (UMLProject)referencingProject;
334
                fireElementImported(umlProject.getLookup().lookup(UMLProjectHelper.class).getProject(), element, importedElement);
335
284
336
                // Check if a reference to the refrence project already
285
        // add reference to the project only if it differes from the owner
337
                // exist.  If a reference already exist do not create a new
286
        if ((foundProject instanceof UMLProject)
338
                // reference.
287
                && (referencingProject instanceof UMLProject)
339
                if(doesReferenceExist(umlRefProject, umlProject) == false)
288
                && (foundProject != referencingProject)) {
340
                {   
289
            UMLProject umlProject = (UMLProject) foundProject;
341
                    boolean foundOne = doesReferenceExist(umlProject, umlRefProject);    
290
            UMLProject umlRefProject = (UMLProject) referencingProject;
342
                    if(foundOne == false)
291
            fireElementImported(umlProject.getLookup().lookup(UMLProjectHelper.class).getProject(), element, importedElement);
343
                    {                    
292
344
                        AntArtifact[] artifacts = AntArtifactQuery.findArtifactsByType( umlProject, UMLProject.ARTIFACT_TYPE_UML_PROJ );
293
            // Check if a reference to the refrence project already
345
                        AntArtifactChooser.ArtifactItem[] items = new AntArtifactChooser.ArtifactItem[artifacts.length];
294
            // exist.  If a reference already exist do not create a new
346
                        for( int i = 0; i < artifacts.length; i++ )
295
            // reference.
347
                        {
296
            if (doesReferenceExist(umlRefProject, umlProject) == false) {
348
                            URI uris[] = artifacts[i].getArtifactLocations();
297
                boolean foundOne = doesReferenceExist(umlProject, umlRefProject);
349
                            for( int y = 0; y < uris.length; y++ )
298
                if (foundOne == false) {
350
                            {
299
                    AntArtifact[] artifacts = AntArtifactQuery.findArtifactsByType(umlProject, UMLProject.ARTIFACT_TYPE_UML_PROJ);
351
                                items[i] = new AntArtifactChooser.ArtifactItem(artifacts[i], uris[y]);
300
                    AntArtifactChooser.ArtifactItem[] items = new AntArtifactChooser.ArtifactItem[artifacts.length];
352
                            }
301
                    for (int i = 0; i < artifacts.length; i++) {
302
                        URI uris[] = artifacts[i].getArtifactLocations();
303
                        for (int y = 0; y < uris.length; y++) {
304
                            items[i] = new AntArtifactChooser.ArtifactItem(artifacts[i], uris[y]);
353
                        }
305
                        }
306
                    }
354
307
355
                        UMLProjectProperties properties = umlRefProject.getUMLProjectProperties();
308
                    UMLProjectProperties properties = umlRefProject.getUMLProjectProperties();
356
                        UMLImportsUiSupport.addArtifacts(properties.umlProjectImportsModel, items);
309
                    UMLImportsUiSupport.addArtifacts(properties.umlProjectImportsModel, items);
357
                        properties.save();
310
                    properties.save();
358
                    }
359
                }
311
                }
360
            }
312
            }
313
        }
361
//        }
314
//        }
362
    }
315
    }
363
    
316
364
    protected void modelPackageImported(IPackage importingPackage, 
317
    protected void modelPackageImported(IPackage importingPackage,
365
                                        IElement element,
318
            IElement element,
366
                                        IPackageImport importedElement)
319
            IPackageImport importedElement) {
367
    {
320
        if ((element != null) && (inSameProject(importingPackage) == true)) {
368
        if((element != null) && (inSameProject(importingPackage) == true))
369
        {
370
            Project foundProject = ProjectUtil.findElementOwner(element);
321
            Project foundProject = ProjectUtil.findElementOwner(element);
371
            Project referencingProject = ProjectUtil.findReferencingProject(element);
322
            Project referencingProject = ProjectUtil.findReferencingProject(element);
372
            
323
373
            // add reference to the project only if it differes from the owner
324
            // add reference to the project only if it differes from the owner
374
            if((foundProject instanceof UMLProject) && 
325
            if ((foundProject instanceof UMLProject)
375
               (referencingProject  instanceof UMLProject) && 
326
                    && (referencingProject instanceof UMLProject)
376
               (foundProject != referencingProject))
327
                    && (foundProject != referencingProject)) {
377
            {
328
                UMLProject umlProject = (UMLProject) foundProject;
378
                UMLProject umlProject = (UMLProject)foundProject;   
329
                UMLProject umlRefProject = (UMLProject) referencingProject;
379
                UMLProject umlRefProject = (UMLProject)referencingProject;
380
                firePackageImported(umlProject.getLookup().lookup(UMLProjectHelper.class).getProject(), element, importedElement);
330
                firePackageImported(umlProject.getLookup().lookup(UMLProjectHelper.class).getProject(), element, importedElement);
381
331
382
                // Check if a reference to the refrence project already
332
                // Check if a reference to the refrence project already
383
                // exist.  If a reference already exist do not create a new
333
                // exist.  If a reference already exist do not create a new
384
                // reference.
334
                // reference.
385
                if(doesReferenceExist(umlRefProject, umlProject) == false)
335
                if (doesReferenceExist(umlRefProject, umlProject) == false) {
386
                {   
336
                    boolean foundOne = doesReferenceExist(umlProject, umlRefProject);
387
                    boolean foundOne = doesReferenceExist(umlProject, umlRefProject);    
337
                    if (foundOne == false) {
388
                    if(foundOne == false)
338
                        AntArtifact[] artifacts = AntArtifactQuery.findArtifactsByType(umlProject, UMLProject.ARTIFACT_TYPE_UML_PROJ);
389
                    {                    
390
                        AntArtifact[] artifacts = AntArtifactQuery.findArtifactsByType( umlProject, UMLProject.ARTIFACT_TYPE_UML_PROJ );
391
                        AntArtifactChooser.ArtifactItem[] items = new AntArtifactChooser.ArtifactItem[artifacts.length];
339
                        AntArtifactChooser.ArtifactItem[] items = new AntArtifactChooser.ArtifactItem[artifacts.length];
392
                        for( int i = 0; i < artifacts.length; i++ )
340
                        for (int i = 0; i < artifacts.length; i++) {
393
                        {
394
                            URI uris[] = artifacts[i].getArtifactLocations();
341
                            URI uris[] = artifacts[i].getArtifactLocations();
395
                            for( int y = 0; y < uris.length; y++ )
342
                            for (int y = 0; y < uris.length; y++) {
396
                            {
397
                                items[i] = new AntArtifactChooser.ArtifactItem(artifacts[i], uris[y]);
343
                                items[i] = new AntArtifactChooser.ArtifactItem(artifacts[i], uris[y]);
398
                            }
344
                            }
399
                        }
345
                        }
Lines 406-595 Link Here
406
            }
352
            }
407
        }
353
        }
408
    }
354
    }
409
    
355
410
    /**
356
    /**
411
     * Check if the project that will be referenced already has a dependency on 
357
     * Check if the project that will be referenced already has a dependency on 
412
     * the project that will be referencing the referenced project.
358
     * the project that will be referencing the referenced project.
413
     */
359
     */
414
    protected boolean doesReferenceExist(UMLProject referencedProject,
360
    protected boolean doesReferenceExist(UMLProject referencedProject,
415
                                         UMLProject refereningProject)
361
            UMLProject refereningProject) {
416
    {
417
        boolean retVal = false;
362
        boolean retVal = false;
418
        
363
419
        UMLProjectProperties properties = referencedProject.getUMLProjectProperties();
364
        UMLProjectProperties properties = referencedProject.getUMLProjectProperties();
420
        
365
421
        // First check if the project as already been added to the table.        
366
        // First check if the project as already been added to the table.        
422
        DefaultTableModel tableModel = properties.umlProjectImportsModel;
367
        DefaultTableModel tableModel = properties.umlProjectImportsModel;
423
        for(int i = 0; i < tableModel.getRowCount(); i++)
368
        for (int i = 0; i < tableModel.getRowCount(); i++) {
424
        {
369
            UMLImportsSupport.Item curItem = (UMLImportsSupport.Item) tableModel.getValueAt(i, COL_UML_PROJECT_NAME);
425
            UMLImportsSupport.Item curItem = (UMLImportsSupport.Item)tableModel.getValueAt(i, COL_UML_PROJECT_NAME);
426
            AntArtifact artifact = curItem.getArtifact();
370
            AntArtifact artifact = curItem.getArtifact();
427
            if(artifact != null)
371
            if (artifact != null) {
428
            {
429
                Project curProject = artifact.getProject();
372
                Project curProject = artifact.getProject();
430
                if(curProject.getProjectDirectory().equals(refereningProject.getProjectDirectory()))
373
                if (curProject.getProjectDirectory().equals(refereningProject.getProjectDirectory())) {
431
                {
432
                    retVal = true;
374
                    retVal = true;
433
                    break;
375
                    break;
434
                }
376
                }
435
            }
377
            }
436
        }
378
        }
437
        
379
438
        return retVal;
380
        return retVal;
439
    }
381
    }
440
    
382
441
    protected void modelElementDeleted(IElement element) {
383
    protected void modelElementDeleted(IElement element) {
442
        if (element == null)
384
        if (element == null) {
443
            return;
385
            return;
444
        
386
        }
387
445
//        Project foundProject = ProjectUtil.findElementOwner(element);
388
//        Project foundProject = ProjectUtil.findElementOwner(element);
446
389
447
//        if (foundProject instanceof UMLProject) {
390
//        if (foundProject instanceof UMLProject) {
448
//            UMLProject umlProject = (UMLProject)foundProject;   
391
//            UMLProject umlProject = (UMLProject)foundProject;   
449
            fireElementDeleted(element.getProject(), element);
392
        fireElementDeleted(element.getProject(), element);
450
//        }
393
//        }
451
    }
394
    }
452
    
395
453
    protected synchronized Map getImportedElements() {
396
    protected synchronized Map getImportedElements() {
454
        if (importedElements == null) {
397
        if (importedElements == null) {
455
            importedElements = new HashMap();
398
            importedElements = new HashMap();
456
            UMLProjectHelper helper = (UMLProjectHelper)mProject.getLookup().lookup(UMLProjectHelper.class);
399
            UMLProjectHelper helper = (UMLProjectHelper) mProject.getLookup().lookup(UMLProjectHelper.class);
457
            IProject project = helper.getProject();
400
            IProject project = helper.getProject();
458
            ETList < INamespace > packages = project.getImportedPackages();
401
            ETList<INamespace> packages = project.getImportedPackages();
459
            if(packages != null) {
402
            if (packages != null) {
460
                for(INamespace ns : packages) {
403
                for (INamespace ns : packages) {
461
                    importedElements.put(new ElementWrapper(ns), ns);
404
                    importedElements.put(new ElementWrapper(ns), ns);
462
                }
405
                }
463
            }
406
            }
464
407
465
            ETList < IElement > elements = project.getImportedElements();
408
            ETList<IElement> elements = project.getImportedElements();
466
            if(elements != null) {
409
            if (elements != null) {
467
                for(IElement elem : elements) {
410
                for (IElement elem : elements) {
468
                    importedElements.put(new ElementWrapper(elem), elem);
411
                    importedElements.put(new ElementWrapper(elem), elem);
469
                }
412
                }
470
            }
413
            }
471
        }
414
        }
472
        return importedElements;
415
        return importedElements;
473
    }
416
    }
474
    
417
475
    public class ImportListener implements IImportEventsSink, IElementLifeTimeEventsSink
418
    public class ImportListener implements IImportEventsSink, IElementLifeTimeEventsSink {
476
    {
477
        // IImportEventsSink interface implementation ...........................
419
        // IImportEventsSink interface implementation ...........................
478
        
420
479
        public void onElementImported(IElementImport elImport, IResultCell cell)
421
        public void onElementImported(IElementImport elImport, IResultCell cell) {
480
        {
422
            if (inSameProject(elImport) == true) {
481
            if (inSameProject(elImport) == true)
482
            {
483
                modelElementImported(elImport.getImportingPackage(),
423
                modelElementImported(elImport.getImportingPackage(),
484
                        elImport.getImportedElement(), elImport);
424
                        elImport.getImportedElement(), elImport);
485
            }
425
            }
486
        }
426
        }
487
427
488
        public void onPackageImported(IPackageImport packImport, IResultCell cell)
428
        public void onPackageImported(IPackageImport packImport, IResultCell cell) {
489
        {
429
            if (!(packImport instanceof IProfile)) {
490
            if(!(packImport instanceof IProfile))
491
            {
492
                modelPackageImported(packImport.getImportingPackage(),
430
                modelPackageImported(packImport.getImportingPackage(),
493
                                     packImport.getImportedPackage(),
431
                        packImport.getImportedPackage(),
494
                                     packImport);
432
                        packImport);
495
            }
433
            }
496
        }
434
        }
497
435
498
        public void onPreElementImport(IPackage importingPackage, 
436
        public void onPreElementImport(IPackage importingPackage,
499
                                       IElement element, 
437
                IElement element,
500
                                       INamespace owner,
438
                INamespace owner,
501
                                       IResultCell cell)
439
                IResultCell cell) {
502
        {        
440
            if (importingPackage == null || owner == null) {
503
            if (importingPackage == null || owner == null)
504
                return;
441
                return;
442
            }
505
            Project referencedProject = ProjectUtil.findNetBeansProjectForModel(owner.getProject());
443
            Project referencedProject = ProjectUtil.findNetBeansProjectForModel(owner.getProject());
506
            Project referencingProject = ProjectUtil.findNetBeansProjectForModel(importingPackage.getProject());
444
            Project referencingProject = ProjectUtil.findNetBeansProjectForModel(importingPackage.getProject());
507
            
445
508
            if(referencedProject.equals(referencingProject) == false)
446
            if (referencedProject.equals(referencingProject) == false) {
509
            {
447
                if (mProject.equals(referencingProject) == true) {
510
                if(mProject.equals(referencingProject) == true)
448
                    if (ProjectUtils.hasSubprojectCycles(mProject, referencedProject)) {
511
                {
449
                        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
512
                    if ( ProjectUtils.hasSubprojectCycles( mProject, referencedProject ) )
450
                                NbBundle.getMessage(AntArtifactChooser.class, "MSG_AACH_Cycles"),
513
                    {
451
                                NotifyDescriptor.INFORMATION_MESSAGE));
514
                        DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message(
515
                                NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_Cycles" ),
516
                                NotifyDescriptor.INFORMATION_MESSAGE ) );
517
                        cell.setContinue(false);
452
                        cell.setContinue(false);
518
                    }
453
                    }
519
                }
454
                }
520
            }
455
            }
521
            
456
522
        }
457
        }
523
458
524
        public void onPrePackageImport(IPackage importingPackage, 
459
        public void onPrePackageImport(IPackage importingPackage,
525
                                       IPackage importedPackage,
460
                IPackage importedPackage,
526
                                       INamespace owner,
461
                INamespace owner,
527
                                       IResultCell cell)
462
                IResultCell cell) {
528
        {
463
            if (owner == null) {
529
            if (owner == null)
530
                return;
464
                return;
465
            }
531
            Project referencedProject = ProjectUtil.findNetBeansProjectForModel(owner.getProject());
466
            Project referencedProject = ProjectUtil.findNetBeansProjectForModel(owner.getProject());
532
            Project referencingProject = ProjectUtil.findNetBeansProjectForModel(importingPackage.getProject());
467
            Project referencingProject = ProjectUtil.findNetBeansProjectForModel(importingPackage.getProject());
533
            
468
534
            if(referencedProject.equals(referencingProject) == false)
469
            if (referencedProject.equals(referencingProject) == false) {
535
            {
470
                if (mProject.equals(referencingProject) == true) {
536
                if(mProject.equals(referencingProject) == true)
471
                    if (ProjectUtils.hasSubprojectCycles(mProject, referencedProject)) {
537
                {
472
                        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
538
                    if ( ProjectUtils.hasSubprojectCycles( mProject, referencedProject ) )
473
                                NbBundle.getMessage(AntArtifactChooser.class, "MSG_AACH_Cycles"),
539
                    {
474
                                NotifyDescriptor.INFORMATION_MESSAGE));
540
                        DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message(
541
                                NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_Cycles" ),
542
                                NotifyDescriptor.INFORMATION_MESSAGE ) );
543
                        cell.setContinue(false);
475
                        cell.setContinue(false);
544
                    }
476
                    }
545
                }
477
                }
546
            }
478
            }
547
        }
479
        }
548
        
480
549
        // IElementLifeTimeEventsSink interface implementation ..................
481
        // IElementLifeTimeEventsSink interface implementation ..................
482
        public void onElementDeleted(IVersionableElement element, IResultCell cell) {
483
            if (element instanceof IElement) {
484
                modelElementDeleted((IElement) element);
485
            }
486
        }
550
487
551
        public void onElementDeleted(IVersionableElement element, IResultCell cell) {
552
            if (element instanceof IElement)
553
                modelElementDeleted((IElement)element);
554
        }
555
        
556
        public void onElementDuplicated(IVersionableElement element, IResultCell cell) {
488
        public void onElementDuplicated(IVersionableElement element, IResultCell cell) {
557
        }
489
        }
558
        
490
559
        public void onElementPreCreate(String ElementType, IResultCell cell) {
491
        public void onElementPreCreate(String ElementType, IResultCell cell) {
560
        }
492
        }
561
        
493
562
        public void onElementPreDuplicated(IVersionableElement element, IResultCell cell) {
494
        public void onElementPreDuplicated(IVersionableElement element, IResultCell cell) {
563
        }
495
        }
564
        
496
565
        public void onElementCreated(IVersionableElement element, IResultCell cell) {
497
        public void onElementCreated(IVersionableElement element, IResultCell cell) {
566
        }
498
        }
567
        
499
568
        public void onElementPreDelete(IVersionableElement element, IResultCell cell) {
500
        public void onElementPreDelete(IVersionableElement element, IResultCell cell) {
569
        }
501
        }
570
        
571
    }
502
    }
572
    
503
573
    // ..........................................................................
504
    // ..........................................................................
574
    private static class ElementWrapper {
505
    private static class ElementWrapper {
575
        
506
576
        IElement element;
507
        IElement element;
577
        
508
578
        ElementWrapper(IElement element) {
509
        ElementWrapper(IElement element) {
579
            this.element = element;
510
            this.element = element;
580
        }
511
        }
581
        
512
582
        public boolean equals(Object obj) {
513
        public boolean equals(Object obj) {
583
            if (obj instanceof ElementWrapper) {
514
            if (obj instanceof ElementWrapper) {
584
                return element.isSame(((ElementWrapper)obj).element);
515
                return element.isSame(((ElementWrapper) obj).element);
585
            }
516
            }
586
            return false;
517
            return false;
587
        }
518
        }
588
        
519
589
        public int hashCode() {
520
        public int hashCode() {
590
            return element.getXMIID().hashCode();
521
            return element.getXMIID().hashCode();
591
        }
522
        }
592
        
593
    }
523
    }
594
    
595
}
524
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/UMLProjectProperties.java (-237 / +187 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.customizer;
44
package org.netbeans.modules.uml.project.ui.customizer;
46
45
47
import java.io.File;
46
import java.io.File;
Lines 80-89 Link Here
80
/**
79
/**
81
 * @author Mike Frisino
80
 * @author Mike Frisino
82
 */
81
 */
83
public class UMLProjectProperties 
82
public class UMLProjectProperties {
84
{
85
    // Special properties of the project, stored in project.xml by project.save
83
    // Special properties of the project, stored in project.xml by project.save
86
    
84
87
    // Properties stored in the PROJECT.PROPERTIES
85
    // Properties stored in the PROJECT.PROPERTIES
88
    public static final String MODELING_MODE = "uml.modeling.mode"; // NOI18N
86
    public static final String MODELING_MODE = "uml.modeling.mode"; // NOI18N
89
    public static final String UML_PROJECT_ANT_ARTIFACT = "uml.umlproject"; // NOI18N
87
    public static final String UML_PROJECT_ANT_ARTIFACT = "uml.umlproject"; // NOI18N
Lines 99-110 Link Here
99
    public static final String CODE_GEN_USE_MARKERS = "code.gen.use.markers"; // NOI18N
97
    public static final String CODE_GEN_USE_MARKERS = "code.gen.use.markers"; // NOI18N
100
    public static final String CODE_GEN_ADD_MARKERS = "code.gen.add.markers"; // NOI18N
98
    public static final String CODE_GEN_ADD_MARKERS = "code.gen.add.markers"; // NOI18N
101
    public static final String CODE_GEN_SHOW_DIALOG = "code.gen.show.dialog"; // NOI18N
99
    public static final String CODE_GEN_SHOW_DIALOG = "code.gen.show.dialog"; // NOI18N
102
    
100
    public static final String DEFAULT_JAVA_TEMPLATES =
103
    public static final String DEFAULT_JAVA_TEMPLATES = 
101
            "Java:Basic Class|Java:Basic Interface|Java:Basic Enumeration"; // NOI18N
104
        "Java:Basic Class|Java:Basic Interface|Java:Basic Enumeration"; // NOI18N
105
        
106
    // MODELS FOR VISUAL CONTROLS
102
    // MODELS FOR VISUAL CONTROLS
107
    
108
    // CustomizerSources
103
    // CustomizerSources
109
    public ComboBoxModel modelingModeModel;
104
    public ComboBoxModel modelingModeModel;
110
    public String modelingModeValue;
105
    public String modelingModeValue;
Lines 117-197 Link Here
117
    public String codeGenUseMarkers;
112
    public String codeGenUseMarkers;
118
    public String codeGenAddMarkers;
113
    public String codeGenAddMarkers;
119
    public String codeGenShowDialog;
114
    public String codeGenShowDialog;
120
    
121
    UMLImportsSupport importsSupport;
115
    UMLImportsSupport importsSupport;
122
    
123
    // CustomizerRunTest
116
    // CustomizerRunTest
124
    
125
    // Private fields ---------------------------------------------------------
117
    // Private fields ---------------------------------------------------------
126
    private UMLProject project;
118
    private UMLProject project;
127
    private UMLProjectHelper updateHelper;
119
    private UMLProjectHelper updateHelper;
128
    private PropertyEvaluator evaluator;
120
    private PropertyEvaluator evaluator;
129
    private ReferenceHelper refHelper;
121
    private ReferenceHelper refHelper;
130
    private ReferencedJavaProjectSupport javaRefSupport;
122
    private ReferencedJavaProjectSupport javaRefSupport;
131
    
132
    private StoreGroup privateGroup;
123
    private StoreGroup privateGroup;
133
    private StoreGroup projectGroup;
124
    private StoreGroup projectGroup;
134
    
125
135
    public UMLProject getProject()
126
    public UMLProject getProject() {
136
    {
137
        return project;
127
        return project;
138
    }
128
    }
139
    
129
140
    /** Creates a new instance of UMLProjectProperties and initializes them */
130
    /** Creates a new instance of UMLProjectProperties and initializes them */
141
    public UMLProjectProperties(
131
    public UMLProjectProperties(
142
        UMLProject project,
132
            UMLProject project,
143
        UMLProjectHelper updateHelper,
133
            UMLProjectHelper updateHelper,
144
        PropertyEvaluator evaluator,
134
            PropertyEvaluator evaluator,
145
        ReferenceHelper refHelper
135
            ReferenceHelper refHelper) {
146
        )
147
    {
148
        this.project = project;
136
        this.project = project;
149
        this.updateHelper  = updateHelper;
137
        this.updateHelper = updateHelper;
150
        this.evaluator = evaluator;
138
        this.evaluator = evaluator;
151
        this.refHelper = refHelper;
139
        this.refHelper = refHelper;
152
        this.javaRefSupport = new ReferencedJavaProjectSupport(
140
        this.javaRefSupport = new ReferencedJavaProjectSupport(
153
            evaluator, refHelper, updateHelper.getAntProjectHelper(),
141
                evaluator, refHelper, updateHelper.getAntProjectHelper(),
154
            null, ANT_ARTIFACT_PREFIX );
142
                null, ANT_ARTIFACT_PREFIX);
155
        
143
156
        this.importsSupport =
144
        this.importsSupport =
157
            new UMLImportsSupport( evaluator, refHelper,
145
                new UMLImportsSupport(evaluator, refHelper,
158
            updateHelper.getAntProjectHelper(),
146
                updateHelper.getAntProjectHelper(),
159
            UML_ARTIFACT_PREFIX);
147
                UML_ARTIFACT_PREFIX);
160
        
148
161
        privateGroup = new StoreGroup();
149
        privateGroup = new StoreGroup();
162
        projectGroup = new StoreGroup();
150
        projectGroup = new StoreGroup();
163
        
151
164
        init(); // Load known properties
152
        init(); // Load known properties
165
    }
153
    }
166
    
154
167
    /** Initializes the visual models
155
    /** Initializes the visual models
168
     */
156
     */
169
    public void init()
157
    public void init() {
170
    {
171
        // Customizer Modeling
158
        // Customizer Modeling
172
        // fetch the stored value
159
        // fetch the stored value
173
        // SELECTED_MODELING_MODE_MODEL = projectGroup.createStringDocument(
160
        // SELECTED_MODELING_MODE_MODEL = projectGroup.createStringDocument(
174
        //  evaluator, MODELING_MODE );
161
        //  evaluator, MODELING_MODE );
175
        // construct model with stored value as selected item.
162
        // construct model with stored value as selected item.
176
        
163
177
        EditableProperties projectProperties = updateHelper.getProperties(
164
        EditableProperties projectProperties = updateHelper.getProperties(
178
            AntProjectHelper.PROJECT_PROPERTIES_PATH );
165
                AntProjectHelper.PROJECT_PROPERTIES_PATH);
179
        
166
180
        modelingModeModel = CommonUiSupport.createModelingModeComboBoxModel(
167
        modelingModeModel = CommonUiSupport.createModelingModeComboBoxModel(
181
            evaluator.getProperty(MODELING_MODE));
168
                evaluator.getProperty(MODELING_MODE));
182
        
169
183
        referencedJavaProjectModel = javaRefSupport.createReferencedJavaProjectModel(
170
        referencedJavaProjectModel = javaRefSupport.createReferencedJavaProjectModel(
184
            REFERENCED_JAVA_PROJECT, evaluator.getProperty(REFERENCED_JAVA_PROJECT));
171
                REFERENCED_JAVA_PROJECT, evaluator.getProperty(REFERENCED_JAVA_PROJECT));
185
        
172
186
        referencedJavaSourceRootsModel = javaRefSupport.
173
        referencedJavaSourceRootsModel = javaRefSupport.createReferencedJavaSourceRootsModel(
187
            createReferencedJavaSourceRootsModel(
174
                referencedJavaProjectModel,
188
            referencedJavaProjectModel,
175
                (String) projectProperties.get(REFERENCED_JAVA_PROJECT_SRC));
189
            (String) projectProperties.get(REFERENCED_JAVA_PROJECT_SRC));
176
190
        
191
        umlProjectImportsModel = UMLImportsUiSupport.createTableModel(
177
        umlProjectImportsModel = UMLImportsUiSupport.createTableModel(
192
            importsSupport.itemsIterator(
178
                importsSupport.itemsIterator(
193
            (String)projectProperties.get(UML_PROJECT_IMPORTS)));
179
                (String) projectProperties.get(UML_PROJECT_IMPORTS)));
194
        
180
195
        codeGenFolderLocation = projectProperties.get(CODE_GEN_FOLDER_LOCATION);
181
        codeGenFolderLocation = projectProperties.get(CODE_GEN_FOLDER_LOCATION);
196
        codeGenTemplates = projectProperties.get(CODE_GEN_TEMPLATES);
182
        codeGenTemplates = projectProperties.get(CODE_GEN_TEMPLATES);
197
        codeGenBackupSources = projectProperties.get(CODE_GEN_BACKUP_SOURCES);
183
        codeGenBackupSources = projectProperties.get(CODE_GEN_BACKUP_SOURCES);
Lines 199-383 Link Here
199
        codeGenAddMarkers = projectProperties.get(CODE_GEN_ADD_MARKERS);
185
        codeGenAddMarkers = projectProperties.get(CODE_GEN_ADD_MARKERS);
200
        codeGenShowDialog = projectProperties.get(CODE_GEN_SHOW_DIALOG);
186
        codeGenShowDialog = projectProperties.get(CODE_GEN_SHOW_DIALOG);
201
    }
187
    }
202
    
188
203
    public void save()
189
    public void save() {
204
    {
190
        try {
205
        try
206
        {
207
            // Store properties
191
            // Store properties
208
            ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction()
192
            ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() {
209
            {
193
210
                public Object run() throws IOException
194
                public Object run() throws IOException {
211
                {
212
                    storeProperties();
195
                    storeProperties();
213
                    return null;
196
                    return null;
214
                }
197
                }
215
            });
198
            });
216
            
199
217
            // and save the project
200
            // and save the project
218
            ProjectManager.getDefault().saveProject(project);
201
            ProjectManager.getDefault().saveProject(project);
219
            
202
220
            // MCF - I am not sure if this bad practice. But I want to
203
            // MCF - I am not sure if this bad practice. But I want to
221
            // avoid having to recreate props in my AssociatedSoruceProvider
204
            // avoid having to recreate props in my AssociatedSoruceProvider
222
            // which will be called a lot.
205
            // which will be called a lot.
223
            // So I am trying to cache these properties in the project.
206
            // So I am trying to cache these properties in the project.
224
            project.setUMLProjectProperties(this);
207
            project.setUMLProjectProperties(this);
225
        }
208
        } catch (MutexException e) {
226
        
209
            ErrorManager.getDefault().notify((IOException) e.getException());
227
        catch (MutexException e)
210
        } catch (IOException ex) {
228
        {
229
            ErrorManager.getDefault().notify((IOException)e.getException());
230
        }
231
        
232
        catch (IOException ex)
233
        {
234
            ErrorManager.getDefault().notify(ex);
211
            ErrorManager.getDefault().notify(ex);
235
        }
212
        }
236
    }
213
    }
237
    
214
238
    private void storeProperties() throws IOException
215
    private void storeProperties() throws IOException {
239
    {
240
        // Store special properties
216
        // Store special properties
241
        
217
242
        // Modify the project dependencies properly
218
        // Modify the project dependencies properly
243
        resolveProjectDependencies();
219
        resolveProjectDependencies();
244
        
220
245
        String[] umlImports = importsSupport.encodeToStrings(
221
        String[] umlImports = importsSupport.encodeToStrings(
246
            UMLImportsUiSupport.getIterator(umlProjectImportsModel));
222
                UMLImportsUiSupport.getIterator(umlProjectImportsModel));
247
        
223
248
        
224
249
        String[] refJavaSrcRoots = javaRefSupport
225
        String[] refJavaSrcRoots = javaRefSupport.encodeSrcGroupsToStrings(referencedJavaSourceRootsModel);
250
            .encodeSrcGroupsToStrings(referencedJavaSourceRootsModel);
226
251
        
252
        // Store standard properties
227
        // Store standard properties
253
        EditableProperties projectProperties = updateHelper.getProperties(
228
        EditableProperties projectProperties = updateHelper.getProperties(
254
            AntProjectHelper.PROJECT_PROPERTIES_PATH);
229
                AntProjectHelper.PROJECT_PROPERTIES_PATH);
255
        
230
256
        EditableProperties privateProperties = updateHelper.getProperties(
231
        EditableProperties privateProperties = updateHelper.getProperties(
257
            AntProjectHelper.PRIVATE_PROPERTIES_PATH);
232
                AntProjectHelper.PRIVATE_PROPERTIES_PATH);
258
        
233
259
        
234
260
        // Standard store of the properties
235
        // Standard store of the properties
261
        projectGroup.store(projectProperties);
236
        projectGroup.store(projectProperties);
262
        privateGroup.store(privateProperties);
237
        privateGroup.store(privateProperties);
263
        
238
264
        projectProperties.setProperty(MODELING_MODE, getProjectMode());
239
        projectProperties.setProperty(MODELING_MODE, getProjectMode());
265
        
240
266
        projectProperties.setProperty(
241
        projectProperties.setProperty(
267
            REFERENCED_JAVA_PROJECT_SRC, refJavaSrcRoots);
242
                REFERENCED_JAVA_PROJECT_SRC, refJavaSrcRoots);
268
        
243
269
        if (codeGenFolderLocation != null)
244
        if (codeGenFolderLocation != null) {
270
            projectProperties.setProperty(CODE_GEN_FOLDER_LOCATION, codeGenFolderLocation);
245
            projectProperties.setProperty(CODE_GEN_FOLDER_LOCATION, codeGenFolderLocation);
246
        }
271
247
272
        if (codeGenTemplates != null)
248
        if (codeGenTemplates != null) {
273
            projectProperties.setProperty(CODE_GEN_TEMPLATES, codeGenTemplates);
249
            projectProperties.setProperty(CODE_GEN_TEMPLATES, codeGenTemplates);
250
        }
274
251
275
        if (codeGenBackupSources != null)
252
        if (codeGenBackupSources != null) {
276
            projectProperties.setProperty(CODE_GEN_BACKUP_SOURCES, codeGenBackupSources);
253
            projectProperties.setProperty(CODE_GEN_BACKUP_SOURCES, codeGenBackupSources);
277
        
254
        }
278
        if (codeGenUseMarkers != null)
255
256
        if (codeGenUseMarkers != null) {
279
            projectProperties.setProperty(CODE_GEN_USE_MARKERS, codeGenUseMarkers);
257
            projectProperties.setProperty(CODE_GEN_USE_MARKERS, codeGenUseMarkers);
258
        }
280
259
281
        if (codeGenAddMarkers != null)
260
        if (codeGenAddMarkers != null) {
282
            projectProperties.setProperty(CODE_GEN_ADD_MARKERS, codeGenAddMarkers);
261
            projectProperties.setProperty(CODE_GEN_ADD_MARKERS, codeGenAddMarkers);
262
        }
283
263
284
        if (codeGenShowDialog != null)
264
        if (codeGenShowDialog != null) {
285
            projectProperties.setProperty(CODE_GEN_SHOW_DIALOG, codeGenShowDialog);
265
            projectProperties.setProperty(CODE_GEN_SHOW_DIALOG, codeGenShowDialog);
286
        
266
        }
267
287
        projectProperties.setProperty(UML_PROJECT_IMPORTS, umlImports);
268
        projectProperties.setProperty(UML_PROJECT_IMPORTS, umlImports);
288
       
269
289
        // Store the property changes into the project
270
        // Store the property changes into the project
290
        updateHelper.putProperties(
271
        updateHelper.putProperties(
291
            AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties );
272
                AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties);
292
        
273
293
        updateHelper.putProperties(
274
        updateHelper.putProperties(
294
            AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties );
275
                AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties);
295
		
276
296
        UMLProjectGenerator.fixJavaProjectReferences(
277
        UMLProjectGenerator.fixJavaProjectReferences(
297
            updateHelper.getAntProjectHelper(),referencedJavaProjectModel.getProject());
278
                updateHelper.getAntProjectHelper(), referencedJavaProjectModel.getProject());
298
    }
279
    }
299
280
300
    /** Finds out what are new and removed project dependencies and
281
    /** Finds out what are new and removed project dependencies and
301
     * applyes the info to the project
282
     * applyes the info to the project
302
     */
283
     */
303
    private void resolveProjectDependencies()
284
    private void resolveProjectDependencies() {
304
    {
285
305
        
306
        AntProjectHelper h = updateHelper.getAntProjectHelper();
286
        AntProjectHelper h = updateHelper.getAntProjectHelper();
307
        
287
308
        EditableProperties ep = updateHelper.getProperties(
288
        EditableProperties ep = updateHelper.getProperties(
309
            AntProjectHelper.PROJECT_PROPERTIES_PATH);
289
                AntProjectHelper.PROJECT_PROPERTIES_PATH);
310
        
290
311
        String oldJavaArtifactRefStr =
291
        String oldJavaArtifactRefStr =
312
            (String)ep.get(UMLProjectProperties.REFERENCED_JAVA_PROJECT_ARTIFACTS);
292
                (String) ep.get(UMLProjectProperties.REFERENCED_JAVA_PROJECT_ARTIFACTS);
313
        
293
314
        if (oldJavaArtifactRefStr != null && oldJavaArtifactRefStr.length() > 0)
294
        if (oldJavaArtifactRefStr != null && oldJavaArtifactRefStr.length() > 0) {
315
        {
295
316
            
317
            String[] oldJavaArtifactRefs = new String[]{oldJavaArtifactRefStr};
296
            String[] oldJavaArtifactRefs = new String[]{oldJavaArtifactRefStr};
318
            
297
319
            for (int i=0; i < oldJavaArtifactRefs.length; i++)
298
            for (int i = 0; i < oldJavaArtifactRefs.length; i++) {
320
            {
321
                // Debug.out.println("MCF destroy reference "  // NOI18N
299
                // Debug.out.println("MCF destroy reference "  // NOI18N
322
                //	+ oldJavaArtifactRefs[i]);
300
                //	+ oldJavaArtifactRefs[i]);
323
                refHelper.destroyReference(oldJavaArtifactRefs[i]);
301
                refHelper.destroyReference(oldJavaArtifactRefs[i]);
324
            }
302
            }
325
        }
303
        }
326
        
304
327
        
305
328
        // got to get fresh ep, after refHelper modified
306
        // got to get fresh ep, after refHelper modified
329
        ep = updateHelper.getProperties(
307
        ep = updateHelper.getProperties(
330
            AntProjectHelper.PROJECT_PROPERTIES_PATH);
308
                AntProjectHelper.PROJECT_PROPERTIES_PATH);
331
        
309
332
        // now add the new ref
310
        // now add the new ref
333
        // refHelper.addReference(artifact, uri);
311
        // refHelper.addReference(artifact, uri);
334
        Project javaSrcProj = referencedJavaProjectModel.getProject();
312
        Project javaSrcProj = referencedJavaProjectModel.getProject();
335
        
313
336
        if (javaSrcProj != null )
314
        if (javaSrcProj != null) {
337
        {
315
            String[] refStrs = UMLProjectGenerator.addJavaSrcProjRef(h, refHelper, javaSrcProj);
338
            String[] refStrs = UMLProjectGenerator
339
                .addJavaSrcProjRef(h, refHelper, javaSrcProj);
340
            ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
316
            ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
341
            ep.setProperty(UMLProjectProperties
317
            ep.setProperty(UMLProjectProperties.REFERENCED_JAVA_PROJECT_ARTIFACTS, refStrs);
342
                .REFERENCED_JAVA_PROJECT_ARTIFACTS, refStrs);
343
            h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
318
            h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
344
        }
319
        }
345
        
320
346
        // Create a set of old and new artifacts.
321
        // Create a set of old and new artifacts.
347
        Set oldArtifacts = new HashSet();
322
        Set oldArtifacts = new HashSet();
348
        Set newArtifacts = new HashSet();
323
        Set newArtifacts = new HashSet();
349
        
324
350
        // Create set of removed artifacts and remove them
325
        // Create set of removed artifacts and remove them
351
        Set removed = new HashSet( oldArtifacts );
326
        Set removed = new HashSet(oldArtifacts);
352
        removed.removeAll( newArtifacts );
327
        removed.removeAll(newArtifacts);
353
        Set added = new HashSet(newArtifacts);
328
        Set added = new HashSet(newArtifacts);
354
        added.removeAll(oldArtifacts);
329
        added.removeAll(oldArtifacts);
355
330
356
        // 2. now read project.properties and modify rest
331
        // 2. now read project.properties and modify rest
357
        ep = updateHelper.getProperties(
332
        ep = updateHelper.getProperties(
358
            AntProjectHelper.PROJECT_PROPERTIES_PATH);
333
                AntProjectHelper.PROJECT_PROPERTIES_PATH);
359
        
334
360
        boolean changed = false;
335
        boolean changed = false;
361
        String javaSrcProjRefVal = ""; // NOI18N
336
        String javaSrcProjRefVal = ""; // NOI18N
362
        
337
363
        if (javaSrcProj != null)
338
        if (javaSrcProj != null) {
364
        {
365
            javaSrcProjRefVal =
339
            javaSrcProjRefVal =
366
                UMLProjectGenerator.getJavaSrcProjRefVal(h, javaSrcProj);
340
                    UMLProjectGenerator.getJavaSrcProjRefVal(h, javaSrcProj);
367
            
341
368
            changed = true;
342
            changed = true;
369
        }
343
        }
370
        
344
371
        ep.setProperty(
345
        ep.setProperty(
372
            UMLProjectProperties.REFERENCED_JAVA_PROJECT, javaSrcProjRefVal);
346
                UMLProjectProperties.REFERENCED_JAVA_PROJECT, javaSrcProjRefVal);
373
        
347
374
        if (changed)
348
        if (changed) {
375
        {
376
            updateHelper.putProperties(
349
            updateHelper.putProperties(
377
                AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
350
                    AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
378
        }
351
        }
379
    }
352
    }
380
    
353
381
    // TODO - MCF - I kept this method from copied J2SE code, thinking we might
354
    // TODO - MCF - I kept this method from copied J2SE code, thinking we might
382
    // need it or something like it. I have not yet actually used it, and if we
355
    // need it or something like it. I have not yet actually used it, and if we
383
    // do not use it we can delete it.
356
    // do not use it we can delete it.
Lines 387-547 Link Here
387
     * @param projectDir project dir for relativization
360
     * @param projectDir project dir for relativization
388
     * @return relativized library classpath or null if some jar is not collocated
361
     * @return relativized library classpath or null if some jar is not collocated
389
     */
362
     */
390
    private String relativizeLibraryClasspath(String property, File projectDir)
363
    private String relativizeLibraryClasspath(String property, File projectDir) {
391
    {
392
        String value = PropertyUtils.getGlobalProperties().getProperty(property);
364
        String value = PropertyUtils.getGlobalProperties().getProperty(property);
393
        // bugfix #42852, check if the classpath
365
        // bugfix #42852, check if the classpath
394
        // property is set, otherwise return null
366
        // property is set, otherwise return null
395
        if (value == null)
367
        if (value == null) {
396
        {
397
            return null;
368
            return null;
398
        }
369
        }
399
        
370
400
        String[] paths = PropertyUtils.tokenizePath(value);
371
        String[] paths = PropertyUtils.tokenizePath(value);
401
        StringBuffer sb = new StringBuffer();
372
        StringBuffer sb = new StringBuffer();
402
        
373
403
        if (sb.length() == 0)
374
        if (sb.length() == 0) {
404
            return null;
375
            return null;
405
        
376
        } else {
406
        else
407
            return sb.toString();
377
            return sb.toString();
378
        }
408
    }
379
    }
409
    
380
410
    
381
    public static String getAntPropertyName(String property) {
411
    public static String getAntPropertyName( String property )
382
        if (property != null
412
    {
383
                && property.startsWith("${") && // NOI18N
413
        if (property != null &&
384
                property.endsWith("}")) // NOI18N
414
            property.startsWith( "${") && // NOI18N
415
            property.endsWith( "}")) // NOI18N
416
        {
385
        {
417
            return property.substring( 2, property.length() - 1 );
386
            return property.substring(2, property.length() - 1);
387
        } else {
388
            return property;
418
        }
389
        }
419
        
420
        else
421
            return property;
422
    }
390
    }
423
    
391
424
    
392
    public String getProjectMode() {
425
    public String getProjectMode()
426
    {
427
        return evaluator.getProperty(MODELING_MODE);
428
    }
429
    
430
    public String getCurrentProjectMode()
431
    {
432
        return evaluator.getProperty(MODELING_MODE);
393
        return evaluator.getProperty(MODELING_MODE);
433
    }
394
    }
434
395
435
    
396
    public String getCurrentProjectMode() {
436
    public String getCodeGenTemplates()
397
        return evaluator.getProperty(MODELING_MODE);
437
    {
398
    }
399
400
    public String getCodeGenTemplates() {
438
        String templates = evaluator.getProperty(CODE_GEN_TEMPLATES);
401
        String templates = evaluator.getProperty(CODE_GEN_TEMPLATES);
439
        
402
440
        if (templates == null)
403
        if (templates == null) {
441
            templates = "";
404
            templates = "";
442
        
405
        }
406
443
        return templates;
407
        return templates;
444
    }
408
    }
445
409
446
    public void setCodeGenFolderLocation(String val)
410
    public void setCodeGenFolderLocation(String val) {
447
    {
448
        codeGenFolderLocation = val;
411
        codeGenFolderLocation = val;
449
    }
412
    }
450
    
451
413
452
    public String getCodeGenFolderLocation()
414
    public String getCodeGenFolderLocation() {
453
    {
454
        String val = evaluator.getProperty(CODE_GEN_FOLDER_LOCATION);
415
        String val = evaluator.getProperty(CODE_GEN_FOLDER_LOCATION);
455
        
416
456
        if (val == null)
417
        if (val == null) {
457
            val = "";
418
            val = "";
458
        
419
        }
420
459
        return val;
421
        return val;
460
    }
422
    }
461
    
462
    public final static String TEMPLATE_DELIMITER = "|";
423
    public final static String TEMPLATE_DELIMITER = "|";
463
    
424
464
    public List<String> getCodeGenTemplatesArray()
425
    public List<String> getCodeGenTemplatesArray() {
465
    {
466
        return new ArrayList<String>(Arrays.asList(StringTokenizer2.toArray(
426
        return new ArrayList<String>(Arrays.asList(StringTokenizer2.toArray(
467
            getCodeGenTemplates(), TEMPLATE_DELIMITER))); // NOI18N
427
                getCodeGenTemplates(), TEMPLATE_DELIMITER))); // NOI18N
468
    }
428
    }
469
429
470
    public void setCodeGenTemplates(List<String> val)
430
    public void setCodeGenTemplates(List<String> val) {
471
    {
431
        codeGenTemplates =
472
        codeGenTemplates = 
432
                StringTokenizer2.delimitedString(val.toArray(), TEMPLATE_DELIMITER);
473
            StringTokenizer2.delimitedString(val.toArray(), TEMPLATE_DELIMITER);
474
    }
433
    }
475
434
476
    public boolean isCodeGenBackupSources()
435
    public boolean isCodeGenBackupSources() {
477
    {
478
        String val = evaluator.getProperty(CODE_GEN_BACKUP_SOURCES);
436
        String val = evaluator.getProperty(CODE_GEN_BACKUP_SOURCES);
479
        
437
480
        if (val == null)
438
        if (val == null) {
481
            val = "true"; // NOI18N
439
            val = "true"; // NOI18N
482
        
440
        }
483
        return Boolean.valueOf(val);
441
        return Boolean.valueOf(val);
484
    }
442
    }
485
443
486
    public void setCodeGenBackupSources(boolean val)
444
    public void setCodeGenBackupSources(boolean val) {
487
    {
488
        codeGenBackupSources = String.valueOf(val);
445
        codeGenBackupSources = String.valueOf(val);
489
    }
446
    }
490
447
491
    public boolean isCodeGenUseMarkers()
448
    public boolean isCodeGenUseMarkers() {
492
    {
493
        String val = evaluator.getProperty(CODE_GEN_USE_MARKERS);
449
        String val = evaluator.getProperty(CODE_GEN_USE_MARKERS);
494
        
450
495
        if (val == null)
451
        if (val == null) {
496
            val = "true";
452
            val = "true";
497
        
453
        }
454
498
        return Boolean.valueOf(val);
455
        return Boolean.valueOf(val);
499
    }
456
    }
500
457
501
    public void setCodeGenUseMarkers(boolean val)
458
    public void setCodeGenUseMarkers(boolean val) {
502
    {
503
        codeGenUseMarkers = String.valueOf(val);
459
        codeGenUseMarkers = String.valueOf(val);
504
    }
460
    }
505
461
506
    public boolean isCodeGenAddMarkers()
462
    public boolean isCodeGenAddMarkers() {
507
    {
508
        String val = evaluator.getProperty(CODE_GEN_ADD_MARKERS);
463
        String val = evaluator.getProperty(CODE_GEN_ADD_MARKERS);
509
        
464
510
        if (val == null)
465
        if (val == null) {
511
            val = "false";
466
            val = "false";
512
        
467
        }
468
513
        return Boolean.valueOf(val);
469
        return Boolean.valueOf(val);
514
    }
470
    }
515
471
516
    public void setCodeGenAddMarkers(boolean val)
472
    public void setCodeGenAddMarkers(boolean val) {
517
    {
518
        codeGenAddMarkers = String.valueOf(val);
473
        codeGenAddMarkers = String.valueOf(val);
519
    }
474
    }
520
475
521
    public boolean isCodeGenShowDialog()
476
    public boolean isCodeGenShowDialog() {
522
    {
523
        String val = evaluator.getProperty(CODE_GEN_SHOW_DIALOG);
477
        String val = evaluator.getProperty(CODE_GEN_SHOW_DIALOG);
524
        
478
525
        if (val == null)
479
        if (val == null) {
526
            val = "true";
480
            val = "true";
527
        
481
        }
482
528
        return Boolean.valueOf(val);
483
        return Boolean.valueOf(val);
529
    }
484
    }
530
485
531
    public void setCodeGenShowDialog(boolean val)
486
    public void setCodeGenShowDialog(boolean val) {
532
    {
533
        codeGenShowDialog = String.valueOf(val);
487
        codeGenShowDialog = String.valueOf(val);
534
    }
488
    }
535
489
536
    
490
    public File getJavaSourceRootFolder() {
537
    public File getJavaSourceRootFolder()
491
        return (referencedJavaSourceRootsModel == null
538
    {
492
                || referencedJavaSourceRootsModel.getSourceGroups().length == 0
539
        return 
493
                || referencedJavaSourceRootsModel.getSourceGroup(0) == null)
540
            (referencedJavaSourceRootsModel == null ||
494
                ? null
541
             referencedJavaSourceRootsModel.getSourceGroups().length == 0 ||
495
                : FileUtil.toFile(referencedJavaSourceRootsModel.getSourceGroup(0).getRootFolder());
542
             referencedJavaSourceRootsModel.getSourceGroup(0) == null)
543
             ? null
544
             : FileUtil.toFile(referencedJavaSourceRootsModel.
545
                getSourceGroup(0).getRootFolder());
546
    }
496
    }
547
}
497
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/uiapi/CategoryView.java (-3 lines)
Lines 53-60 Link Here
53
import java.util.Arrays;
53
import java.util.Arrays;
54
import java.util.Collection;
54
import java.util.Collection;
55
import java.util.Collections;
55
import java.util.Collections;
56
import javax.swing.Icon;
57
import javax.swing.ImageIcon;
58
import javax.swing.JPanel;
56
import javax.swing.JPanel;
59
import javax.swing.tree.TreeSelectionModel;
57
import javax.swing.tree.TreeSelectionModel;
60
import org.netbeans.modules.uml.resources.images.ImageUtil;
58
import org.netbeans.modules.uml.resources.images.ImageUtil;
Lines 66-72 Link Here
66
import org.openide.nodes.Node;
64
import org.openide.nodes.Node;
67
import org.openide.util.ImageUtilities;
65
import org.openide.util.ImageUtilities;
68
import org.openide.util.NbBundle;
66
import org.openide.util.NbBundle;
69
import org.openide.util.Utilities;
70
import org.openide.util.lookup.Lookups;
67
import org.openide.util.lookup.Lookups;
71
68
72
/**
69
/**
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/uiapi/ProjectChooserFactory.java (-1 lines)
Lines 48-54 Link Here
48
import org.netbeans.api.project.Project;
48
import org.netbeans.api.project.Project;
49
import org.netbeans.api.project.SourceGroup;
49
import org.netbeans.api.project.SourceGroup;
50
import org.openide.WizardDescriptor;
50
import org.openide.WizardDescriptor;
51
import org.openide.filesystems.FileObject;
52
51
53
import java.io.File;
52
import java.io.File;
54
53
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/customizer/uiapi/UMLCustomizerDialog.java (-1 lines)
Lines 55-61 Link Here
55
import org.openide.DialogDisplayer;
55
import org.openide.DialogDisplayer;
56
import org.openide.util.HelpCtx;
56
import org.openide.util.HelpCtx;
57
import org.openide.util.NbBundle;
57
import org.openide.util.NbBundle;
58
import org.netbeans.spi.project.ui.support.*;
59
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
58
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
60
import org.netbeans.spi.project.ui.support.ProjectCustomizer.CategoryComponentProvider;
59
import org.netbeans.spi.project.ui.support.ProjectCustomizer.CategoryComponentProvider;
61
60
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/java/UMLJavaAssociationUtil.java (-164 / +142 lines)
Lines 47-56 Link Here
47
 *
47
 *
48
 * Created on March 25, 2005, 11:16 AM
48
 * Created on March 25, 2005, 11:16 AM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.java;
50
package org.netbeans.modules.uml.project.ui.java;
52
51
53
54
import java.util.ArrayList;
52
import java.util.ArrayList;
55
import java.util.List;
53
import java.util.List;
56
54
Lines 67-246 Link Here
67
import org.netbeans.modules.uml.core.typemanagement.ITypeManager;
65
import org.netbeans.modules.uml.core.typemanagement.ITypeManager;
68
import org.netbeans.modules.uml.core.metamodel.core.constructs.IClass;
66
import org.netbeans.modules.uml.core.metamodel.core.constructs.IClass;
69
import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackage;
67
import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackage;
70
import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IInterface;
71
import org.netbeans.modules.uml.core.metamodel.core.constructs.IEnumeration;
72
import org.netbeans.modules.uml.project.UMLProjectHelper;
68
import org.netbeans.modules.uml.project.UMLProjectHelper;
73
//import org.netbeans.jmi.javamodel.JavaEnum;
69
//import org.netbeans.jmi.javamodel.JavaEnum;
74
//import  org.netbeans.modules.uml.project.*;
70
//import  org.netbeans.modules.uml.project.*;
75
//import org.netbeans.jmi.javamodel.*;
71
//import org.netbeans.jmi.javamodel.*;
76
//import org.netbeans.modules.javacore.api.JavaModel;
72
//import org.netbeans.modules.javacore.api.JavaModel;
77
import org.openide.ErrorManager;
78
import org.openide.loaders.DataObjectNotFoundException;
79
80
73
81
/**
74
/**
82
 *
75
 *
83
 * @author Mike
76
 * @author Mike
84
 */
77
 */
85
public class UMLJavaAssociationUtil {
78
public class UMLJavaAssociationUtil {
86
	
79
87
	/** Creates a new instance of UMLJavaAssociationUtil */
80
    /** Creates a new instance of UMLJavaAssociationUtil */
88
	public UMLJavaAssociationUtil() {
81
    public UMLJavaAssociationUtil() {
89
	}
82
    }
90
	
83
91
	
84
    // TODO - do we have to worry about or flag the edge case where a single
92
	// TODO - do we have to worry about or flag the edge case where a single
85
    // java project might be intentionally or unintentionally associated with
93
	// java project might be intentionally or unintentionally associated with
86
    // > 1 uml project? Perhaps we should detect that and throw an invalid state
94
	// > 1 uml project? Perhaps we should detect that and throw an invalid state
87
    // exception?
95
	// exception?
96
    /* NB60TBD
88
    /* NB60TBD
97
	public static Project getAssociatedUMLProject(JavaClass c) {
89
    public static Project getAssociatedUMLProject(JavaClass c) {
98
//		DataObject sourceDO = JavaMetamodel.getManager().getDataObject(c.getResource());
90
    //		DataObject sourceDO = JavaMetamodel.getManager().getDataObject(c.getResource());
99
            DataObject sourceDO = null;
91
    DataObject sourceDO = null;
100
            try {
92
    try {
101
                sourceDO = DataObject.find(JavaModel.getFileObject(c.getResource()));
93
    sourceDO = DataObject.find(JavaModel.getFileObject(c.getResource()));
102
            }catch (DataObjectNotFoundException e)
94
    }catch (DataObjectNotFoundException e)
103
            {
95
    {
104
                ErrorManager.getDefault().notify(e);
96
    ErrorManager.getDefault().notify(e);
97
    }
98
    return getAssociatedUMLProject(sourceDO);
99
    }
100
     */
101
    /**
102
     * Retrieve a UML project that is associatied with the given data object.
103
     */
104
    public static Project getAssociatedUMLProject(DataObject dObj) {
105
        Project currentJavaProj =
106
                FileOwnerQuery.getOwner(dObj.getPrimaryFile());
107
        return getAssociatedUMLProject(currentJavaProj);
108
    }
109
110
    /**
111
     * Retrieve a UML project that is associated with a specified
112
     * project.
113
     */
114
    public static Project getAssociatedUMLProject(Project project) {
115
        // Filter out the inappropriate projects
116
117
        // TODO - complete the "association detecthion" It should probably
118
        // be even more fine tuned to check that the UMLProject is ALSO listing
119
        // the Java classes SourceGroup. There is possibility that > 1 UMLProject
120
        // might target same java project but different source groups. That would
121
        // be ok, but we would need to factor that into the check below.
122
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
123
        for (int i = 0; i < allProjects.length; i++) {
124
            AssociatedSourceProvider asp = (AssociatedSourceProvider) allProjects[i].getLookup().lookup(AssociatedSourceProvider.class);
125
            if (asp != null) {
126
                Project codeGenProj = asp.getCodeGenTargetProject();
127
                if (project == codeGenProj) {
128
                    return allProjects[i];
129
                }
130
131
                Project umlJavaProj = asp.getAssociatedSourceProject();
132
                if (project == umlJavaProj) {
133
                    return allProjects[i];
134
                }
135
105
            }
136
            }
106
      return getAssociatedUMLProject(sourceDO);
137
        }
107
	}
138
        return null;
108
    */
139
    }
109
140
110
   /**
141
    public static List<Project> getAllAssociatedUMLProjects(DataObject dObj) {
111
    * Retrieve a UML project that is associatied with the given data object.
142
        Project currentJavaProj =
112
    */
143
                FileOwnerQuery.getOwner(dObj.getPrimaryFile());
113
   public static Project getAssociatedUMLProject(DataObject dObj)
144
        return getAllAssociatedUMLProjects(currentJavaProj);
114
   {  
145
    }
115
      Project currentJavaProj =
146
116
               FileOwnerQuery.getOwner(dObj.getPrimaryFile());
147
    /**
117
      return getAssociatedUMLProject(currentJavaProj);   
148
     * Retrieve all UML projects that are associated with a specified
118
   }
149
     * project.
119
	
150
     */
120
   /**
151
    public static List<Project> getAllAssociatedUMLProjects(Project project) {
121
    * Retrieve a UML project that is associated with a specified 
152
        ArrayList<Project> retVal = new ArrayList<Project>();
122
    * project.
153
        Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
123
    */
154
        for (int i = 0; i < allProjects.length; i++) {
124
   public static Project getAssociatedUMLProject(Project project)
155
            AssociatedSourceProvider asp = (AssociatedSourceProvider) allProjects[i].getLookup().lookup(AssociatedSourceProvider.class);
125
   {
156
            if (asp != null) {
126
      // Filter out the inappropriate projects
157
                Project codeGenProj = asp.getCodeGenTargetProject();
127
      
158
                if (project == codeGenProj) {
128
      // TODO - complete the "association detecthion" It should probably
159
                    retVal.add(allProjects[i]);
129
      // be even more fine tuned to check that the UMLProject is ALSO listing
160
                } else {
130
      // the Java classes SourceGroup. There is possibility that > 1 UMLProject
161
                    Project umlJavaProj = asp.getAssociatedSourceProject();
131
      // might target same java project but different source groups. That would
162
                    if (project == umlJavaProj) {
132
      // be ok, but we would need to factor that into the check below.
163
                        retVal.add(allProjects[i]);
133
      Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
164
                    }
134
      for (int i = 0; i < allProjects.length; i++)
165
                }
135
      {
136
         AssociatedSourceProvider asp = (AssociatedSourceProvider)
137
         allProjects[i].getLookup().lookup(AssociatedSourceProvider.class);
138
         if ( asp != null )
139
         {
140
            Project codeGenProj = asp.getCodeGenTargetProject();            
141
            if(project == codeGenProj)
142
            {
143
               return allProjects[i];
144
            }
166
            }
145
167
        }
146
            Project umlJavaProj = asp.getAssociatedSourceProject();           
168
        return retVal;
147
            if(project == umlJavaProj)
169
    }
148
            {
149
               return allProjects[i];
150
            }
151
            
152
         }
153
      }
154
      return null;
155
   }
156
157
	
158
   public static List<Project> getAllAssociatedUMLProjects(DataObject dObj)
159
   {  
160
      Project currentJavaProj =
161
               FileOwnerQuery.getOwner(dObj.getPrimaryFile());
162
      return getAllAssociatedUMLProjects(currentJavaProj);   
163
   }
164
	
165
166
   /**
167
    * Retrieve all UML projects that are associated with a specified 
168
    * project.
169
    */
170
   public static List<Project> getAllAssociatedUMLProjects(Project project)
171
   {
172
      ArrayList<Project> retVal = new ArrayList<Project>();
173
      Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
174
      for (int i = 0; i < allProjects.length; i++)
175
      {
176
         AssociatedSourceProvider asp = (AssociatedSourceProvider)
177
         allProjects[i].getLookup().lookup(AssociatedSourceProvider.class);
178
         if ( asp != null )
179
         {
180
            Project codeGenProj = asp.getCodeGenTargetProject();            
181
            if(project == codeGenProj)
182
            {
183
               retVal.add(allProjects[i]);
184
            } 
185
            else 
186
            {
187
               Project umlJavaProj = asp.getAssociatedSourceProject();           
188
               if(project == umlJavaProj)
189
               {
190
                  retVal.add(allProjects[i]);
191
               }
192
            }            
193
         }
194
      }
195
      return retVal;
196
   }
197
170
198
//proj=The UML project to search
171
//proj=The UML project to search
199
//qualifiedName=The fully qualified name of the class.
172
//qualifiedName=The fully qualified name of the class.
200
//type=The type of model element that you want to be returned IClass.class, IEnumeration.class, etc
173
//type=The type of model element that you want to be returned IClass.class, IEnumeration.class, etc
201
public static INamedElement findElement(Project umlProject,
174
    public static INamedElement findElement(Project umlProject,
202
                                       String qualifiedName,
175
            String qualifiedName,
203
                                       Class type) {
176
            Class type) {
204
	
205
	UMLProjectHelper mHelper = null;
206
	mHelper = (UMLProjectHelper) umlProject.getLookup().lookup(UMLProjectHelper.class);
207
	
208
	if(mHelper == null)
209
		return null; // should not happen
210
	
211
	
212
	IProject iProj = mHelper.getProject();
213
		
214
177
215
       if (iProj == null) {
178
        UMLProjectHelper mHelper = null;
216
           return null;
179
        mHelper = (UMLProjectHelper) umlProject.getLookup().lookup(UMLProjectHelper.class);
217
       }
218
180
181
        if (mHelper == null) {
182
            return null; // should not happen
183
        }
219
184
220
       ITypeManager typeManager = iProj.getTypeManager();
185
        IProject iProj = mHelper.getProject();
221
       if (typeManager == null) {
222
           return null;
223
       }
224
186
225
       // Converts a Java qualified name to a UML qualified name
226
       // Example: java.swing.JFrame -> java::swing::JFrame
227
       //          java.swing.JFrame$InnerClass -> java::swing::JFrame::InnerClass
228
       String umlName = convertJavaToUML(qualifiedName);
229
	   	   
230
       ETList<INamedElement> elems = typeManager.getLocalCachedTypesByName(umlName);
231
187
232
       int count = elems != null? elems.getCount() : 0;
188
        if (iProj == null) {
233
       for(int i = 0; i < count; i++) {
189
            return null;
234
           INamedElement elem = elems.item(i);
190
        }
235
           if (elem == null) continue;
191
236
           if (type != null && !type.isAssignableFrom(elem.getClass())) continue;
192
237
           String nameToCompare = getFullyQualifiedName(elem);
193
        ITypeManager typeManager = iProj.getTypeManager();
238
           if(nameToCompare.equals(qualifiedName)
194
        if (typeManager == null) {
239
                  || nameToCompare.replace('$', '.').equals(qualifiedName))
195
            return null;
240
               return elem;
196
        }
241
       }
197
242
       return null;
198
        // Converts a Java qualified name to a UML qualified name
243
   }
199
        // Example: java.swing.JFrame -> java::swing::JFrame
200
        //          java.swing.JFrame$InnerClass -> java::swing::JFrame::InnerClass
201
        String umlName = convertJavaToUML(qualifiedName);
202
203
        ETList<INamedElement> elems = typeManager.getLocalCachedTypesByName(umlName);
204
205
        int count = elems != null ? elems.getCount() : 0;
206
        for (int i = 0; i < count; i++) {
207
            INamedElement elem = elems.item(i);
208
            if (elem == null) {
209
                continue;
210
            }
211
            if (type != null && !type.isAssignableFrom(elem.getClass())) {
212
                continue;
213
            }
214
            String nameToCompare = getFullyQualifiedName(elem);
215
            if (nameToCompare.equals(qualifiedName)
216
                    || nameToCompare.replace('$', '.').equals(qualifiedName)) {
217
                return elem;
218
            }
219
        }
220
        return null;
221
    }
244
222
245
    /**
223
    /**
246
     * Converts a fully qualified Java classname to Describe's internal
224
     * Converts a fully qualified Java classname to Describe's internal
Lines 251-262 Link Here
251
     *
229
     *
252
     * @param javaName A fully qualifid java class name.
230
     * @param javaName A fully qualifid java class name.
253
     */
231
     */
254
    public static String convertJavaToUML( String javaName ) {
232
    public static String convertJavaToUML(String javaName) {
255
        String retVal = javaName.replace('$', '.');
233
        String retVal = javaName.replace('$', '.');
256
234
257
        // replace "." with "::"
235
        // replace "." with "::"
258
        int pos = retVal.indexOf(".");
236
        int pos = retVal.indexOf(".");
259
        while(pos > 0) {
237
        while (pos > 0) {
260
            StringBuffer buf = new StringBuffer(retVal);
238
            StringBuffer buf = new StringBuffer(retVal);
261
            retVal = buf.replace(pos, pos + 1, "::").toString();
239
            retVal = buf.replace(pos, pos + 1, "::").toString();
262
            pos = retVal.indexOf(".");
240
            pos = retVal.indexOf(".");
Lines 274-280 Link Here
274
     */
252
     */
275
    public static String convertJavaToUML(String pName, String name) {
253
    public static String convertJavaToUML(String pName, String name) {
276
        String curPName = (pName.length() > 0 ? pName + "." : "");
254
        String curPName = (pName.length() > 0 ? pName + "." : "");
277
        String fullScopeName  = curPName + name;
255
        String fullScopeName = curPName + name;
278
        return convertJavaToUML(fullScopeName);
256
        return convertJavaToUML(fullScopeName);
279
    }
257
    }
280
258
Lines 282-293 Link Here
282
     * Converts a UML fully qualified name into a Java fully qualified name.
260
     * Converts a UML fully qualified name into a Java fully qualified name.
283
     * @param umlNam A UML formated string.
261
     * @param umlNam A UML formated string.
284
     */
262
     */
285
    public static String convertUMLtoJava( String umlName ) {
263
    public static String convertUMLtoJava(String umlName) {
286
        String retVal = umlName;
264
        String retVal = umlName;
287
265
288
        // replace "::" with "."
266
        // replace "::" with "."
289
        int pos = retVal.indexOf("::");
267
        int pos = retVal.indexOf("::");
290
        while(pos > 0) {
268
        while (pos > 0) {
291
            StringBuffer buf = new StringBuffer(retVal);
269
            StringBuffer buf = new StringBuffer(retVal);
292
            retVal = buf.replace(pos, pos + 2, ".").toString();
270
            retVal = buf.replace(pos, pos + 2, ".").toString();
293
            pos = retVal.indexOf("::");
271
            pos = retVal.indexOf("::");
Lines 296-302 Link Here
296
        return retVal;
274
        return retVal;
297
    }
275
    }
298
276
299
   /**
277
    /**
300
     *  Returns the fully-qualified name for the given named element.
278
     *  Returns the fully-qualified name for the given named element.
301
     * @param element The element for which the qualified name needs to be
279
     * @param element The element for which the qualified name needs to be
302
     *                determined.
280
     *                determined.
Lines 307-326 Link Here
307
        StringBuffer name = new StringBuffer(element.getName());
285
        StringBuffer name = new StringBuffer(element.getName());
308
286
309
        for (IElement parent = element.getOwner(); parent != null;
287
        for (IElement parent = element.getOwner(); parent != null;
310
                        parent = parent.getOwner()) {
288
                parent = parent.getOwner()) {
311
            if (parent instanceof IClass) {
289
            if (parent instanceof IClass) {
312
                IClass p = (IClass)  parent;
290
                IClass p = (IClass) parent;
313
                name.insert(0, '$');
291
                name.insert(0, '$');
314
                name.insert(0, p.getName());
292
                name.insert(0, p.getName());
315
            } else if (parent instanceof IPackage
293
            } else if (parent instanceof IPackage
316
                            && !(parent instanceof IProject)) {
294
                    && !(parent instanceof IProject)) {
317
                IPackage p = (IPackage)  parent;
295
                IPackage p = (IPackage) parent;
318
                name.insert(0, '.');
296
                name.insert(0, '.');
319
                name.insert(0, p.getName());
297
                name.insert(0, p.getName());
320
            } else
298
            } else {
321
                break;
299
                break;
300
            }
322
        }
301
        }
323
        return name.toString();
302
        return name.toString();
324
    }
303
    }
325
	
326
}
304
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/AbstractModelElementNode.java (-348 / +238 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
46
45
47
import org.netbeans.modules.uml.core.eventframework.IEventPayload;
46
import org.netbeans.modules.uml.core.eventframework.IEventPayload;
Lines 88-94 Link Here
88
import org.openide.util.datatransfer.NewType;
87
import org.openide.util.datatransfer.NewType;
89
import org.openide.util.datatransfer.PasteType;
88
import org.openide.util.datatransfer.PasteType;
90
89
91
92
/**
90
/**
93
 * AbstractModelElementNode model element node is a base node for all nodes that
91
 * AbstractModelElementNode model element node is a base node for all nodes that
94
 * model represent model elements.  AbstractModelElementNode provides the basic
92
 * model represent model elements.  AbstractModelElementNode provides the basic
Lines 102-109 Link Here
102
 * @author Trey Spiva
100
 * @author Trey Spiva
103
 * @author Craig Conover, craig.conover@sun.com
101
 * @author Craig Conover, craig.conover@sun.com
104
 */
102
 */
105
public abstract class AbstractModelElementNode extends AbstractNode
103
public abstract class AbstractModelElementNode extends AbstractNode {
106
{   
104
107
    public final static String ELEMENT_TYPE_PROJECT = "Project"; // NOI18N
105
    public final static String ELEMENT_TYPE_PROJECT = "Project"; // NOI18N
108
    public final static String ELEMENT_TYPE_PACKAGE = "Package"; // NOI18N
106
    public final static String ELEMENT_TYPE_PACKAGE = "Package"; // NOI18N
109
    public final static String ELEMENT_TYPE_CLASS = "Class"; // NOI18N
107
    public final static String ELEMENT_TYPE_CLASS = "Class"; // NOI18N
Lines 137-144 Link Here
137
    public final static String ELEMENT_TYPE_COMMENT = "Comment"; // NOI18N
135
    public final static String ELEMENT_TYPE_COMMENT = "Comment"; // NOI18N
138
    public final static String ELEMENT_TYPE_DEPLOYMENTSPECIFICATION = "DeploymentSpecification"; // NOI18N
136
    public final static String ELEMENT_TYPE_DEPLOYMENTSPECIFICATION = "DeploymentSpecification"; // NOI18N
139
    public final static String ELEMENT_TYPE_COMPONENT = "Component"; // NOI18N
137
    public final static String ELEMENT_TYPE_COMPONENT = "Component"; // NOI18N
140
    
141
    
142
    public final static String ELEMENT_TYPE_SOURCE_FILE_ARTIFACT = "SourcFileArtifact"; // NOI18N
138
    public final static String ELEMENT_TYPE_SOURCE_FILE_ARTIFACT = "SourcFileArtifact"; // NOI18N
143
    public static final String ELEMENT_TYPE_DEPENDENCY = "Dependency"; // NOI18N
139
    public static final String ELEMENT_TYPE_DEPENDENCY = "Dependency"; // NOI18N
144
    public static final String ELEMENT_TYPE_REALIZATION = "Realization"; // NOI18N
140
    public static final String ELEMENT_TYPE_REALIZATION = "Realization"; // NOI18N
Lines 148-168 Link Here
148
    public static final String ELEMENT_TYPE_GENERALIZATION = "Generalization"; // NOI18N
144
    public static final String ELEMENT_TYPE_GENERALIZATION = "Generalization"; // NOI18N
149
    public static final String ELEMENT_TYPE_ASSOCIATION = "Association"; // NOI18N
145
    public static final String ELEMENT_TYPE_ASSOCIATION = "Association"; // NOI18N
150
    public static final String ELEMENT_TYPE_AGGREGATION = "Aggregation"; // NOI18N
146
    public static final String ELEMENT_TYPE_AGGREGATION = "Aggregation"; // NOI18N
151
    
152
    public final static int NEW_TYPE_DIAGRAM = 0;
147
    public final static int NEW_TYPE_DIAGRAM = 0;
153
    public final static int NEW_TYPE_PACKAGE = 1;
148
    public final static int NEW_TYPE_PACKAGE = 1;
154
    public final static int NEW_TYPE_ELEMENT = 2;
149
    public final static int NEW_TYPE_ELEMENT = 2;
155
    public final static int NEW_TYPE_ATTRIBUTE = 3;
150
    public final static int NEW_TYPE_ATTRIBUTE = 3;
156
    public final static int NEW_TYPE_OPERATION = 4;
151
    public final static int NEW_TYPE_OPERATION = 4;
157
    
152
    public final static Integer[] AVAILABLE_NEW_TYPES = new Integer[]{
158
    public final static Integer[] AVAILABLE_NEW_TYPES = new Integer[]
159
    {
160
        NEW_TYPE_DIAGRAM, NEW_TYPE_PACKAGE, NEW_TYPE_ELEMENT,
153
        NEW_TYPE_DIAGRAM, NEW_TYPE_PACKAGE, NEW_TYPE_ELEMENT,
161
        NEW_TYPE_ATTRIBUTE, NEW_TYPE_OPERATION
154
        NEW_TYPE_ATTRIBUTE, NEW_TYPE_OPERATION
162
    };
155
    };
163
    
164
    public final static int TOTAL_NEW_TYPES = AVAILABLE_NEW_TYPES.length;
156
    public final static int TOTAL_NEW_TYPES = AVAILABLE_NEW_TYPES.length;
165
    
166
    public final static String ADDIN_ID_ASSOCIATE_WITH = "AssociateWith"; // NOI18N
157
    public final static String ADDIN_ID_ASSOCIATE_WITH = "AssociateWith"; // NOI18N
167
    public final static String ADDIN_ID_DEPENDENCY_DIAGRAM = "DependencyDiagram"; // NOI18N
158
    public final static String ADDIN_ID_DEPENDENCY_DIAGRAM = "DependencyDiagram"; // NOI18N
168
    public final static String ADDIN_ID_DIAGRAM_CREATOR = "DiagramCreator"; // NOI18N
159
    public final static String ADDIN_ID_DIAGRAM_CREATOR = "DiagramCreator"; // NOI18N
Lines 170-192 Link Here
170
    public final static String ADDIN_ID_REDEFINE_OPERATIONS = "RedefineOperations"; // NOI18N
161
    public final static String ADDIN_ID_REDEFINE_OPERATIONS = "RedefineOperations"; // NOI18N
171
    public final static String ADDIN_ID_RE_OPERATION = "REOperation"; // NOI18N
162
    public final static String ADDIN_ID_RE_OPERATION = "REOperation"; // NOI18N
172
    public final static String ADDIN_ID_SHOW_AS_XML = "ShowAsXML"; // NOI18N
163
    public final static String ADDIN_ID_SHOW_AS_XML = "ShowAsXML"; // NOI18N
173
    
174
    //Cache to improve performance
164
    //Cache to improve performance
175
    Action newAction=null;
165
    Action newAction = null;
176
    
166
177
    /**
167
    /**
178
     * Create a new abstract model element node.
168
     * Create a new abstract model element node.
179
     */
169
     */
180
    public AbstractModelElementNode()
170
    public AbstractModelElementNode() {
181
    {
182
        this(new UMLChildren());
171
        this(new UMLChildren());
183
    }
172
    }
184
    
173
185
    public AbstractModelElementNode(Children ch)
174
    public AbstractModelElementNode(Children ch) {
186
    {
187
        this(ch, null);
175
        this(ch, null);
188
    }
176
    }
189
    
177
190
    /**
178
    /**
191
     * Create a new abstract model element node and associated lookup.
179
     * Create a new abstract model element node and associated lookup.
192
     *
180
     *
Lines 194-209 Link Here
194
     *               getCookie(java.lang.Class).
182
     *               getCookie(java.lang.Class).
195
     */
183
     */
196
    //public AbstractModelElementNode(Node node, Lookup lookup)
184
    //public AbstractModelElementNode(Node node, Lookup lookup)
197
    public AbstractModelElementNode(Lookup lookup)
185
    public AbstractModelElementNode(Lookup lookup) {
198
    {
199
        this(new UMLChildren(), lookup);
186
        this(new UMLChildren(), lookup);
200
    }
187
    }
201
    
188
202
    public AbstractModelElementNode(Children ch, Lookup lookup)
189
    public AbstractModelElementNode(Children ch, Lookup lookup) {
203
    {
204
        super(ch, lookup);
190
        super(ch, lookup);
205
    }
191
    }
206
    
192
207
    /**
193
    /**
208
     * Retrieve the model element associated with the node.
194
     * Retrieve the model element associated with the node.
209
     *
195
     *
Lines 211-255 Link Here
211
     * @see IElement
197
     * @see IElement
212
     */
198
     */
213
    public abstract IElement getModelElement();
199
    public abstract IElement getModelElement();
214
    
200
215
    /**
201
    /**
216
     * Retrieve the meta-data name for the model element.
202
     * Retrieve the meta-data name for the model element.
217
     *
203
     *
218
     * @param The meta data name.
204
     * @param The meta data name.
219
     */
205
     */
220
    public String getElementType()
206
    public String getElementType() {
221
    {
222
        String retVal = ""; // NOI18N
207
        String retVal = ""; // NOI18N
223
        
208
224
        IElement element = getModelElement();
209
        IElement element = getModelElement();
225
        if(element != null)
210
        if (element != null) {
226
        {
227
            retVal = element.getElementType();
211
            retVal = element.getElementType();
228
        }
212
        }
229
        
213
230
        return retVal;
214
        return retVal;
231
    }
215
    }
232
    
216
233
    
217
    public void setDisplayName(String s) {
234
    public void setDisplayName(String s)
235
    {
236
        setDisplayName(s, true);
218
        setDisplayName(s, true);
237
    }
219
    }
238
    
220
239
    // conover
221
    // conover
240
    public void setDisplayName(String s, boolean notify)
222
    public void setDisplayName(String s, boolean notify) {
241
    {
242
        super.setDisplayName(s);
223
        super.setDisplayName(s);
243
        
224
244
        if (notify)
225
        if (notify) {
245
            notifyPropertySetsChange();
226
            notifyPropertySetsChange();
227
        }
246
    }
228
    }
247
    
229
248
    
249
    //**************************************************
230
    //**************************************************
250
    // Node Overrides
231
    // Node Overrides
251
    //**************************************************
232
    //**************************************************
252
    
253
    /**
233
    /**
254
     * Get the new types that can be created in this node. For example, a node
234
     * Get the new types that can be created in this node. For example, a node
255
     * representing a class will permit attributes, operations, classes,
235
     * representing a class will permit attributes, operations, classes,
Lines 257-320 Link Here
257
     *
237
     *
258
     * @return An array of new type operations that are allowed.
238
     * @return An array of new type operations that are allowed.
259
     */
239
     */
260
    public NewType[] getNewTypes()
240
    public NewType[] getNewTypes() {
261
    {
262
        String elType = getElementType();
241
        String elType = getElementType();
263
        NewType[] retVal = null;
242
        NewType[] retVal = null;
264
        
243
265
        if (getModelElement() instanceof INamespace)
244
        if (getModelElement() instanceof INamespace) {
266
        {
267
            // Diagram types: Use Case Diagram, Deployment Diagram
245
            // Diagram types: Use Case Diagram, Deployment Diagram
268
            if (
246
            if (elType.equals(ELEMENT_TYPE_PROXY_DIAGRAM)
269
                    elType.equals(ELEMENT_TYPE_PROXY_DIAGRAM) ||
247
                    || elType.equals(ELEMENT_TYPE_DIAGRAM)) {
270
                    elType.equals(ELEMENT_TYPE_DIAGRAM))
248
                return new NewType[]{
271
            {
249
                            new NewPackageType(this),
272
                return new NewType[]
250
                            new NewElementType(this)
273
                {
251
                        };
274
                    new NewPackageType(this),
252
            } else if (elType.equals(ELEMENT_TYPE_PROJECT)) {
275
                    new NewElementType(this)
253
                return new NewType[]{
276
                };
254
                            new NewDiagramType(this),
277
            }
255
                            new NewPackageType(this),
278
            
256
                            new NewElementType(this)
279
            else if (elType.equals(ELEMENT_TYPE_PROJECT))
257
                        };
280
            {
258
            } // Interaction types: Sequence Diagram, Collaboration Diagram
281
                return new NewType[]
282
                {
283
                    new NewDiagramType(this),
284
                    new NewPackageType(this),
285
                    new NewElementType(this)
286
                };
287
            }
288
            
289
            // Interaction types: Sequence Diagram, Collaboration Diagram
290
            // StateMachine types: State Diagram
259
            // StateMachine types: State Diagram
291
            // Activity types: Activity Diagram
260
            // Activity types: Activity Diagram
292
            else if (elType.equals(ELEMENT_TYPE_INTERACTION) ||
261
            else if (elType.equals(ELEMENT_TYPE_INTERACTION)
293
                    elType.equals(ELEMENT_TYPE_STATE_MACHINE) ||
262
                    || elType.equals(ELEMENT_TYPE_STATE_MACHINE)
294
                    elType.equals(ELEMENT_TYPE_ACTIVITY))
263
                    || elType.equals(ELEMENT_TYPE_ACTIVITY)) {
295
            {
264
                return new NewType[]{
296
                return new NewType[]
265
                            new NewDiagramType(this),
297
                {
266
                            new NewPackageType(this),
298
                    new NewDiagramType(this),
267
                            new NewElementType(this),
299
                    new NewPackageType(this),
268
                            new NewAttributeType(this),
300
                    new NewElementType(this),
269
                            new NewOperationType(this)
301
                    new NewAttributeType(this),
270
                        };
302
                    new NewOperationType(this)
303
                };
304
            }
271
            }
305
        } // if getModelElement() instanceof INamespace
272
        } // if getModelElement() instanceof INamespace
306
        
273
307
        // The NewAction code does not check for null.  Therefore, we have
274
        // The NewAction code does not check for null.  Therefore, we have
308
        // to create a new object just to keep them from throwing.
275
        // to create a new object just to keep them from throwing.
309
        if (retVal == null)
276
        if (retVal == null) {
310
        {
311
            retVal = new NewType[0];
277
            retVal = new NewType[0];
312
        }
278
        }
313
        
279
314
        return retVal;
280
        return retVal;
315
    }
281
    }
316
    
282
317
    
318
    /**
283
    /**
319
     * Retrieves the actions for the node.  This method only returns
284
     * Retrieves the actions for the node.  This method only returns
320
     * the context sensitive actions.
285
     * the context sensitive actions.
Lines 323-413 Link Here
323
     *                node itself
288
     *                node itself
324
     * @return A list of actions (you may include nulls for separators)
289
     * @return A list of actions (you may include nulls for separators)
325
     */
290
     */
326
    public Action[] getActions(boolean context)
291
    public Action[] getActions(boolean context) {
327
    {
292
        ArrayList<Action> actions = new ArrayList<Action>();
328
        ArrayList<Action> actions = new ArrayList <Action>();
293
329
        
330
        actions.add(SystemAction.get(OpenAction.class));
294
        actions.add(SystemAction.get(OpenAction.class));
331
        
295
332
        // cvc - CR 6287660 & 6276911
296
        // cvc - CR 6287660 & 6276911
333
        //commented out - moved to getNewAction() to improve performance
297
        //commented out - moved to getNewAction() to improve performance
334
                /*if (!(getParentNode() instanceof UMLDiagramsRootNode) &&
298
                /*if (!(getParentNode() instanceof UMLDiagramsRootNode) &&
335
                        !elemType.equals(ELEMENT_TYPE_ABSTRACTION) &&
299
        !elemType.equals(ELEMENT_TYPE_ABSTRACTION) &&
336
                        !elemType.equals(ELEMENT_TYPE_AGGREGATION) &&
300
        !elemType.equals(ELEMENT_TYPE_AGGREGATION) &&
337
                        !elemType.equals(ELEMENT_TYPE_ASSOCIATION) &&
301
        !elemType.equals(ELEMENT_TYPE_ASSOCIATION) &&
338
                        !elemType.equals(ELEMENT_TYPE_DEPENDENCY) &&
302
        !elemType.equals(ELEMENT_TYPE_DEPENDENCY) &&
339
                        !elemType.equals(ELEMENT_TYPE_GENERALIZATION) &&
303
        !elemType.equals(ELEMENT_TYPE_GENERALIZATION) &&
340
                        !elemType.equals(ELEMENT_TYPE_PERMISSION) &&
304
        !elemType.equals(ELEMENT_TYPE_PERMISSION) &&
341
                        !elemType.equals(ELEMENT_TYPE_REALIZATION) &&
305
        !elemType.equals(ELEMENT_TYPE_REALIZATION) &&
342
                        !elemType.equals(ELEMENT_TYPE_USAGE))*/
306
        !elemType.equals(ELEMENT_TYPE_USAGE))*/
343
        Action action=getNewAction();
307
        Action action = getNewAction();
344
        if(action!=null)
308
        if (action != null) {
345
        {
346
            actions.add(action);
309
            actions.add(action);
347
        }
310
        }
348
        
311
349
        actions.add(null);
312
        actions.add(null);
350
        
313
351
        actions.add(SystemAction.get(DeleteAction.class));
314
        actions.add(SystemAction.get(DeleteAction.class));
352
        actions.add(SystemAction.get(RenameAction.class));
315
        actions.add(SystemAction.get(RenameAction.class));
353
        
316
354
        actions.add(null);
317
        actions.add(null);
355
        
318
356
        addContextMenus(actions);
319
        addContextMenus(actions);
357
        
320
358
        actions.add(null);
321
        actions.add(null);
359
        
322
360
        //      actions.add(SystemAction.get(SourceControlSubMenuAction.class));
323
        //      actions.add(SystemAction.get(SourceControlSubMenuAction.class));
361
        //To improve performance, cache this action
324
        //To improve performance, cache this action
362
        
325
363
        // Source control Sub menu Actions are created based on the SCM status of the nodes so every time we need
326
        // Source control Sub menu Actions are created based on the SCM status of the nodes so every time we need
364
        //to get the actions freshly so they can't be checked for null
327
        //to get the actions freshly so they can't be checked for null
365
/*		if(scSubMenuAction==null)
328
/*		if(scSubMenuAction==null)
366
                        scSubMenuAction=new SourceControlSubMenuAction();
329
        scSubMenuAction=new SourceControlSubMenuAction();
367
                actions.add(scSubMenuAction);
330
        actions.add(scSubMenuAction);
368
 */
331
         */
369
        actions.add(null);
332
        actions.add(null);
370
        
333
371
        actions.add(SystemAction.get(PropertiesAction.class));
334
        actions.add(SystemAction.get(PropertiesAction.class));
372
        
335
373
        Action[] retVal = new Action[actions.size()];
336
        Action[] retVal = new Action[actions.size()];
374
        actions.toArray(retVal);
337
        actions.toArray(retVal);
375
        return retVal;
338
        return retVal;
376
    }
339
    }
377
    
340
378
    private Action getNewAction()
341
    private Action getNewAction() {
379
    {
380
        // TODO: this needs to be reviewed as to what node should have new type action
342
        // TODO: this needs to be reviewed as to what node should have new type action
381
        
343
382
        if(newAction==null)
344
        if (newAction == null) {
383
        {   String elemType = getElementType();
345
            String elemType = getElementType();
384
            if (!(getParentNode() instanceof UMLDiagramsRootNode) &&
346
            if (!(getParentNode() instanceof UMLDiagramsRootNode)
385
                    getModelElement()!=null &&
347
                    && getModelElement() != null
386
                    !elemType.equals(ELEMENT_TYPE_ABSTRACTION) &&
348
                    && !elemType.equals(ELEMENT_TYPE_ABSTRACTION)
387
                    !elemType.equals(ELEMENT_TYPE_AGGREGATION) &&
349
                    && !elemType.equals(ELEMENT_TYPE_AGGREGATION)
388
                    !elemType.equals(ELEMENT_TYPE_ASSOCIATION) &&
350
                    && !elemType.equals(ELEMENT_TYPE_ASSOCIATION)
389
                    !elemType.equals(ELEMENT_TYPE_DEPENDENCY) &&
351
                    && !elemType.equals(ELEMENT_TYPE_DEPENDENCY)
390
                    !elemType.equals(ELEMENT_TYPE_GENERALIZATION) &&
352
                    && !elemType.equals(ELEMENT_TYPE_GENERALIZATION)
391
                    !elemType.equals(ELEMENT_TYPE_PERMISSION) &&
353
                    && !elemType.equals(ELEMENT_TYPE_PERMISSION)
392
                    !elemType.equals(ELEMENT_TYPE_REALIZATION) &&
354
                    && !elemType.equals(ELEMENT_TYPE_REALIZATION)
393
                    !elemType.equals(ELEMENT_TYPE_USAGE) &&
355
                    && !elemType.equals(ELEMENT_TYPE_USAGE)
394
                    !elemType.equals(ELEMENT_TYPE_ACTOR) &&
356
                    && !elemType.equals(ELEMENT_TYPE_ACTOR)
395
                    !elemType.equals(ELEMENT_TYPE_DIAGRAM) &&
357
                    && !elemType.equals(ELEMENT_TYPE_DIAGRAM)
396
                    !elemType.equals(ELEMENT_TYPE_PROXY_DIAGRAM) &&
358
                    && !elemType.equals(ELEMENT_TYPE_PROXY_DIAGRAM)
397
                    !elemType.equals(""))
359
                    && !elemType.equals("")) {
398
            {
399
                //newAction=SystemAction.get(NewAction.class);
360
                //newAction=SystemAction.get(NewAction.class);
400
                  Action[] newActions = getNewMenuAction();
361
                Action[] newActions = getNewMenuAction();
401
                  if (newActions != null && newActions.length > 0)
362
                if (newActions != null && newActions.length > 0) {
402
                  {
363
                    newAction = newActions[0];
403
                     newAction= newActions[0];
364
                }
404
                  }
405
            }
365
            }
406
        }
366
        }
407
        return newAction;
367
        return newAction;
408
    }
368
    }
409
    
369
410
    
411
    /**
370
    /**
412
     * Retrievse the for the model element using property elements and property
371
     * Retrievse the for the model element using property elements and property
413
     * definitions.  The property elements allow us to use a configuration file
372
     * definitions.  The property elements allow us to use a configuration file
Lines 418-545 Link Here
418
     * @see org.netbeans.modules.uml.core.support.umlutils.IPropertyDefinitionFactory
377
     * @see org.netbeans.modules.uml.core.support.umlutils.IPropertyDefinitionFactory
419
     * @see org.openide.nodes.Node#getPropertySets()
378
     * @see org.openide.nodes.Node#getPropertySets()
420
     */
379
     */
421
    public Node.PropertySet[] getPropertySets()
380
    public Node.PropertySet[] getPropertySets() {
422
    {
423
        Node.PropertySet[] retVal = null;
381
        Node.PropertySet[] retVal = null;
424
        
382
425
        Node.PropertySet[] parentSet = super.getPropertySets();
383
        Node.PropertySet[] parentSet = super.getPropertySets();
426
        
384
427
        // The model element my not be set yet.  If the model element is not set
385
        // The model element my not be set yet.  If the model element is not set
428
        // then we do not want only want to return the parents property set.
386
        // then we do not want only want to return the parents property set.
429
        String elementType = getElementType();
387
        String elementType = getElementType();
430
        
388
431
        if (elementType.length() > 0)
389
        if (elementType.length() > 0) {
432
        {  
433
            PropertySet[] elementProperties = retreiveProperties();
390
            PropertySet[] elementProperties = retreiveProperties();
434
            if (elementProperties != null)
391
            if (elementProperties != null) {
435
            {
392
                retVal = new PropertySet[parentSet.length + elementProperties.length];
436
                retVal = new PropertySet[
437
                        parentSet.length + elementProperties.length];
438
                System.arraycopy(
393
                System.arraycopy(
439
                        elementProperties, 0, retVal, 0, elementProperties.length);
394
                        elementProperties, 0, retVal, 0, elementProperties.length);
440
                System.arraycopy(
395
                System.arraycopy(
441
                        parentSet, 0, retVal, elementProperties.length, parentSet.length);
396
                        parentSet, 0, retVal, elementProperties.length, parentSet.length);
442
            }
397
            } else {
443
            
444
            else
445
            {
446
                retVal = parentSet;
398
                retVal = parentSet;
447
            }
399
            }
448
        }
400
        } else {
449
        
450
        else
451
        {
452
            retVal = parentSet;
401
            retVal = parentSet;
453
        }
402
        }
454
        
403
455
        return retVal;
404
        return retVal;
456
    }
405
    }
457
    
406
458
    @Override
407
    @Override
459
    public Transferable clipboardCopy()
408
    public Transferable clipboardCopy()
460
            throws IOException
409
            throws IOException {
461
    {
462
        ADTransferable retVal = new ADTransferable("DRAGGEDITEMS"); // NOI18N
410
        ADTransferable retVal = new ADTransferable("DRAGGEDITEMS"); // NOI18N
463
        retVal.addModelElement(getModelElement());
411
        retVal.addModelElement(getModelElement());
464
        
412
465
        DispatchHelper heleper = new DispatchHelper();
413
        DispatchHelper heleper = new DispatchHelper();
466
        IProjectTreeEventDispatcher disp = heleper.getProjectTreeDispatcher();
414
        IProjectTreeEventDispatcher disp = heleper.getProjectTreeDispatcher();
467
        
415
468
        if (disp != null)
416
        if (disp != null) {
469
        {
470
            IEventPayload payload = disp.createPayload("ProjectTreeBeginDrag"); // NOI18N
417
            IEventPayload payload = disp.createPayload("ProjectTreeBeginDrag"); // NOI18N
471
            IProjectTreeDragVerify context = new ProjectTreeDragVerifyImpl();
418
            IProjectTreeDragVerify context = new ProjectTreeDragVerifyImpl();
472
            
419
473
            if (this instanceof ITreeItem)
420
            if (this instanceof ITreeItem) {
474
            {
421
                IProjectTreeItem[] items = {((ITreeItem) this).getData()};
475
                IProjectTreeItem[] items = {((ITreeItem)this).getData()};
476
                disp.fireBeginDrag(null, items, context, payload);
422
                disp.fireBeginDrag(null, items, context, payload);
477
            }
423
            }
478
            
424
479
        }
425
        }
480
        return retVal;
426
        return retVal;
481
    }
427
    }
482
    
428
483
    public Transferable clipboardCut()
429
    public Transferable clipboardCut()
484
            throws IOException
430
            throws IOException {
485
    {
486
        return clipboardCopy();
431
        return clipboardCopy();
487
    }
432
    }
488
    
433
489
    public boolean canDestroy()
434
    public boolean canDestroy() {
490
    {
491
        Lookup lkp = getLookup();
435
        Lookup lkp = getLookup();
492
        boolean canDestroy = lkp.lookup(IProjectTreeItem.class) != null;
436
        boolean canDestroy = lkp.lookup(IProjectTreeItem.class) != null;
493
        return canDestroy;
437
        return canDestroy;
494
    }
438
    }
495
    
439
496
    public void destroy() throws IOException
440
    public void destroy() throws IOException {
497
    {
498
        // Gather up all the diagrams and model elements
441
        // Gather up all the diagrams and model elements
499
        //  in preparation for deleting.
442
        //  in preparation for deleting.
500
        final ETList<IElement> modelElements = new ETArrayList<IElement>();
443
        final ETList<IElement> modelElements = new ETArrayList<IElement>();
501
        final List<String> diagrams = new LinkedList<String>();
444
        final List<String> diagrams = new LinkedList<String>();
502
        
445
503
        IProjectTreeItem treeItem = this.getLookup().lookup(IProjectTreeItem.class);
446
        IProjectTreeItem treeItem = this.getLookup().lookup(IProjectTreeItem.class);
504
        
447
505
        if (treeItem == null)
448
        if (treeItem == null) {
506
            return;
449
            return;
507
        
450
        }
508
        
451
452
509
        // If this item is a model element then add to the list of model
453
        // If this item is a model element then add to the list of model
510
        // elements, if it's a diagram then add it to the list of names
454
        // elements, if it's a diagram then add it to the list of names
511
        // associated with the diagrams.
455
        // associated with the diagrams.
512
        if (treeItem.isImportedPackage())
456
        if (treeItem.isImportedPackage()) {
513
        {
457
            if (treeItem.getImportedPackage() != null) {
514
            if (treeItem.getImportedPackage() != null)
515
                modelElements.add(treeItem.getImportedPackage());
458
                modelElements.add(treeItem.getImportedPackage());
516
        }
459
            }
517
        
460
        } else if (treeItem.isImportedModelElement()) {
518
        else if (treeItem.isImportedModelElement())
461
            if (treeItem.getImportedModelElement() != null) {
519
        {
520
            if (treeItem.getImportedModelElement() != null)
521
                modelElements.add(treeItem.getImportedModelElement());
462
                modelElements.add(treeItem.getImportedModelElement());
522
        }
463
            }
523
        else if (treeItem.isDiagram())
464
        } else if (treeItem.isDiagram()) {
524
        {
465
            if (treeItem.getDescription() != null
525
            if (treeItem.getDescription() != null &&
466
                    && treeItem.getDescription().length() > 0) {
526
                    treeItem.getDescription().length() > 0)
527
            {
528
                diagrams.add(treeItem.getDescription());
467
                diagrams.add(treeItem.getDescription());
529
            }
468
            }
530
        }
469
        } else if (treeItem.getModelElement() != null) {
531
        else if (treeItem.getModelElement() != null)
532
        {
533
            IElement elem = treeItem.getModelElement();
470
            IElement elem = treeItem.getModelElement();
534
            modelElements.add(elem);
471
            modelElements.add(elem);
535
        }
472
        }
536
    
473
537
        
474
538
        Runnable runnable = new Runnable()
475
        Runnable runnable = new Runnable() {
539
        {
476
540
            public void run()
477
            public void run() {
541
            {
478
                synchronized (deleteLock) {
542
                synchronized(deleteLock) { 
543
                    if (inDelete) {
479
                    if (inDelete) {
544
                        EventQueue.invokeLater(this);
480
                        EventQueue.invokeLater(this);
545
                        return;
481
                        return;
Lines 550-566 Link Here
550
486
551
                try {
487
                try {
552
                    // Now actually do the delete of the model elements
488
                    // Now actually do the delete of the model elements
553
                    for (final IElement curModelElement: modelElements)
489
                    for (final IElement curModelElement : modelElements) {
554
                    {
555
                        curModelElement.delete();
490
                        curModelElement.delete();
556
                    }
491
                    }
557
                    
492
558
                    // Now whack the diagrams
493
                    // Now whack the diagrams
559
                    final IProxyDiagramManager proxyDiagramManager =
494
                    final IProxyDiagramManager proxyDiagramManager =
560
                        ProxyDiagramManager.instance();
495
                            ProxyDiagramManager.instance();
561
                    
496
562
                    for (final String curDiagramName: diagrams)
497
                    for (final String curDiagramName : diagrams) {
563
                    {
564
                        proxyDiagramManager.removeDiagram(curDiagramName);
498
                        proxyDiagramManager.removeDiagram(curDiagramName);
565
                    }
499
                    }
566
                } finally {
500
                } finally {
Lines 568-703 Link Here
568
                }
502
                }
569
            }
503
            }
570
        };
504
        };
571
        
505
572
        EventQueue.invokeLater(runnable);
506
        EventQueue.invokeLater(runnable);
573
    }
507
    }
574
    
575
    private static boolean inDelete = false;
508
    private static boolean inDelete = false;
576
    private static Object deleteLock = new Object();
509
    private static Object deleteLock = new Object();
577
510
578
    
511
    public boolean canCut() {
579
    public boolean canCut()
580
    {
581
        return true;
512
        return true;
582
    }
513
    }
583
    
514
584
 
515
    protected void createPasteTypes(Transferable t, List s) {
585
    
586
    protected void createPasteTypes(Transferable t, List s)
587
    {
588
        super.createPasteTypes(t, s);
516
        super.createPasteTypes(t, s);
589
        PasteType type = getDropType(t, DnDConstants.ACTION_COPY, -1);
517
        PasteType type = getDropType(t, DnDConstants.ACTION_COPY, -1);
590
        if (type != null)
518
        if (type != null) {
591
        {
592
            s.add(type);
519
            s.add(type);
593
        }
520
        }
594
    }
521
    }
595
    
522
596
    
523
    public PasteType getDropType(Transferable trans, int action, int index) {
597
    public PasteType getDropType(Transferable trans, int action, int index)
598
    {
599
        PasteType retVal = null;
524
        PasteType retVal = null;
600
        
525
601
        // cvc - CR 6363187 - can't DnD more than one model element in tree
526
        // cvc - CR 6363187 - can't DnD more than one model element in tree
602
        // This method has been overhauled to fix the bug.
527
        // This method has been overhauled to fix the bug.
603
        
528
604
        try
529
        try {
605
        {
530
            if (trans instanceof ADTransferable) {
606
            if (trans instanceof ADTransferable)
531
                if (trans.isDataFlavorSupported(ADTransferable.ADDataFlavor)) {
607
            {
608
                if (trans.isDataFlavorSupported(ADTransferable.ADDataFlavor))
609
                {
610
                    Object obj = trans.getTransferData(ADTransferable.ADDataFlavor);
532
                    Object obj = trans.getTransferData(ADTransferable.ADDataFlavor);
611
                    ADTransferable adTrans = (ADTransferable)trans;
533
                    ADTransferable adTrans = (ADTransferable) trans;
612
                    
534
613
                    if (obj != null)
535
                    if (obj != null) {
614
                    {
536
                        if (this instanceof ITreeItem) {
615
                        if (this instanceof ITreeItem)
537
                            ITreeItem item = (ITreeItem) this;
616
                        {
617
                            ITreeItem item = (ITreeItem)this;
618
                            IProjectTreeItem data = item.getData();
538
                            IProjectTreeItem data = item.getData();
619
                            retVal = new ModelPasteType(trans, data, action);
539
                            retVal = new ModelPasteType(trans, data, action);
620
                        }
540
                        }
621
                    }
541
                    }
622
                } // if - isDataFlavorSupported
542
                } // if - isDataFlavorSupported
623
            } // if - ADTransferable
543
            } // if - ADTransferable
624
            
544
            else if (trans instanceof ExTransferable) {
625
            else if (trans instanceof ExTransferable)
545
                ExTransferable exTrans = (ExTransferable) trans;
626
            {
546
627
                ExTransferable exTrans = (ExTransferable)trans;
547
                if (this instanceof ITreeItem) {
628
                
548
                    ITreeItem item = (ITreeItem) this;
629
                if (this instanceof ITreeItem)
630
                {
631
                    ITreeItem item = (ITreeItem)this;
632
                    IProjectTreeItem data = item.getData();
549
                    IProjectTreeItem data = item.getData();
633
                    retVal = new ModelPasteType(exTrans, data, action);
550
                    retVal = new ModelPasteType(exTrans, data, action);
634
                }
551
                }
635
            }
552
            } else {
636
            
637
            else
638
            {
639
                Log.write(
553
                Log.write(
640
                        "Unexpected Transferrable subtype parameter, "  // NOI18N
554
                        "Unexpected Transferrable subtype parameter, " // NOI18N
641
                        + trans.getClass().getName() + ". Should not be " // NOI18N
555
                        + trans.getClass().getName() + ". Should not be " // NOI18N
642
                        + "an issue but proactively logging ocurrence."); // NOI18N
556
                        + "an issue but proactively logging ocurrence."); // NOI18N
643
            }
557
            }
644
        } // try
558
        } // try
645
        
559
        catch (Exception e) {
646
        catch (Exception e)
647
        {
648
            Log.stackTrace(e);
560
            Log.stackTrace(e);
649
        }
561
        }
650
        
562
651
        return retVal;
563
        return retVal;
652
    }
564
    }
653
   
565
654
    protected Action[] getNewMenuAction()
566
    protected Action[] getNewMenuAction() {
655
    {
567
        return getActionsFromRegistry("contextmenu/uml/newtypes"); // NOI18N
656
       return getActionsFromRegistry("contextmenu/uml/newtypes"); // NOI18N
657
    }
568
    }
658
    
569
659
    protected void getNewMenuAction(List actions)
570
    protected void getNewMenuAction(List actions) {
660
    {
571
        Action[] nodeActions = getActionsFromRegistry("contextmenu/uml/newtypes"); // NOI18N
661
       Action [] nodeActions = getActionsFromRegistry("contextmenu/uml/newtypes"); // NOI18N
572
        if (nodeActions != null) {
662
       if (nodeActions != null )
573
            for (Action curAction : nodeActions) {
663
       {
574
                if (curAction == null) {
664
          for(Action curAction : nodeActions)
575
                    // Make Sure the Seperators are kept.
665
          {
576
                    actions.add(null);
666
             if (curAction == null)
577
                } else if (curAction != null && curAction.isEnabled()) {
667
             {
578
                    actions.add(curAction);
668
                // Make Sure the Seperators are kept.
579
                }
669
                actions.add(null);
580
            }
670
             }
581
            actions.add(null);  // add a Separator
671
             else if (curAction != null && curAction.isEnabled())
582
        }
672
             {
673
                actions.add(curAction);
674
             }
675
          }
676
          actions.add(null);  // add a Separator
677
       }
678
    }
583
    }
679
    
584
680
    /**
585
    /**
681
     * Retrieve the context actions added by other modules.
586
     * Retrieve the context actions added by other modules.
682
     *
587
     *
683
     * @param actions The action collection to add the actions to.
588
     * @param actions The action collection to add the actions to.
684
     */
589
     */
685
    protected void addContextMenus(ArrayList<Action> actions)
590
    protected void addContextMenus(ArrayList<Action> actions) {
686
    {
687
        Action[] nodeActions = getActionsFromRegistry("contextmenu/uml/element"); // NOI18N
591
        Action[] nodeActions = getActionsFromRegistry("contextmenu/uml/element"); // NOI18N
688
        
592
689
        for(Action curAction : nodeActions)
593
        for (Action curAction : nodeActions) {
690
        {
594
            if (curAction == null) // Make Sure the Seperators are kept.
691
            if (curAction == null)
595
            {
692
                // Make Sure the Seperators are kept.
693
                actions.add(null);
596
                actions.add(null);
694
            
597
            } else if (curAction.isEnabled()) {
695
            else if (curAction.isEnabled())
696
                actions.add(curAction);
598
                actions.add(curAction);
599
            }
697
        }
600
        }
698
    }
601
    }
699
    
602
700
    
701
    /**
603
    /**
702
     * The registry information that is retrieved from layer files to build
604
     * The registry information that is retrieved from layer files to build
703
     * the list of actions supported by this node.
605
     * the list of actions supported by this node.
Lines 706-801 Link Here
706
     * @return The list of actions in the path.  null will be used if when
608
     * @return The list of actions in the path.  null will be used if when
707
     *         seperators can be placed.
609
     *         seperators can be placed.
708
     */
610
     */
709
    protected Action[] getActionsFromRegistry(String path)
611
    protected Action[] getActionsFromRegistry(String path) {
710
    {
711
        List<? extends Action> actions = Utilities.actionsForPath(path);
612
        List<? extends Action> actions = Utilities.actionsForPath(path);
712
        Action[] retVal = new Action[actions.size()];
613
        Action[] retVal = new Action[actions.size()];
713
        actions.toArray(retVal);
614
        actions.toArray(retVal);
714
        return retVal;
615
        return retVal;
715
    }
616
    }
716
    
617
717
    
618
    protected Node.PropertySet[] retreiveProperties() {
718
    protected Node.PropertySet[] retreiveProperties()
719
    {
720
        Node.PropertySet[] retVal = null;
619
        Node.PropertySet[] retVal = null;
721
        
620
722
        retVal = buildProperties();
621
        retVal = buildProperties();
723
        
622
724
        return retVal;
623
        return retVal;
725
    }
624
    }
726
    
625
727
    // Jyothi: Fix for Bug#6258627-Naming a component doesn't update the property sheet Name to the new value.
626
    // Jyothi: Fix for Bug#6258627-Naming a component doesn't update the property sheet Name to the new value.
728
    // This method is a hack.. and is NOT supposed to be used in any other scenario
627
    // This method is a hack.. and is NOT supposed to be used in any other scenario
729
    public void notifyPropertySetsChange()
628
    public void notifyPropertySetsChange() {
730
    {
731
        firePropertySetsChange(null, retreiveProperties());
629
        firePropertySetsChange(null, retreiveProperties());
732
    }
630
    }
733
    
631
734
    /**
632
    /**
735
     * Builds the proerty set structure for all model elements.
633
     * Builds the proerty set structure for all model elements.
736
     */
634
     */
737
    protected Node.PropertySet[] buildProperties()
635
    protected Node.PropertySet[] buildProperties() {
738
    {
739
        Node.PropertySet[] retVal = null;
636
        Node.PropertySet[] retVal = null;
740
        
637
741
        IElement element = getModelElement();
638
        IElement element = getModelElement();
742
        
639
743
        if (element != null)
640
        if (element != null) {
744
        {
745
            DefinitionPropertyBuilder builder = DefinitionPropertyBuilder.instance();
641
            DefinitionPropertyBuilder builder = DefinitionPropertyBuilder.instance();
746
            retVal = builder.retreiveProperties(element.getElementType(), element);
642
            retVal = builder.retreiveProperties(element.getElementType(), element);
747
        }
643
        }
748
        
644
749
        return retVal;
645
        return retVal;
750
    }
646
    }
751
    
647
752
    public class ModelPasteType extends PasteType
648
    public class ModelPasteType extends PasteType {
753
    {
754
        // cvc - CR 6363187 - can't DnD more than one model element in tree
649
        // cvc - CR 6363187 - can't DnD more than one model element in tree
755
        // This inner class has been overhauled to fix the bug.
650
        // This inner class has been overhauled to fix the bug.
756
        
651
757
        private IProjectTreeItem mTreeItem = null;
652
        private IProjectTreeItem mTreeItem = null;
758
        private Transferable mTransferable = null;
653
        private Transferable mTransferable = null;
759
        private int mAction = DnDConstants.ACTION_NONE;
654
        private int mAction = DnDConstants.ACTION_NONE;
760
        
655
761
        public ModelPasteType(
656
        public ModelPasteType(
762
                Transferable transferable,
657
                Transferable transferable,
763
                IProjectTreeItem data,
658
                IProjectTreeItem data,
764
                int action)
659
                int action) {
765
        {
766
            mTreeItem = data;
660
            mTreeItem = data;
767
            mTransferable = transferable;
661
            mTransferable = transferable;
768
            mAction = action;
662
            mAction = action;
769
        }
663
        }
770
        
664
771
        public Transferable paste()
665
        public Transferable paste()
772
                throws IOException
666
                throws IOException {
773
        {
774
            fireEndDrag();
667
            fireEndDrag();
775
            return null;
668
            return null;
776
        }
669
        }
777
        
670
778
        /**
671
        /**
779
         * Notifies listeners that the drag process has been completed.  This event
672
         * Notifies listeners that the drag process has been completed.  This event
780
         * is only fired if project tree is the drop target.
673
         * is only fired if project tree is the drop target.
781
         */
674
         */
782
        public boolean fireEndDrag()
675
        public boolean fireEndDrag() {
783
        {
784
            boolean retVal = true;
676
            boolean retVal = true;
785
            
677
786
            if (mAction != DnDConstants.ACTION_NONE)
678
            if (mAction != DnDConstants.ACTION_NONE) {
787
            {
788
                DispatchHelper dispatcherHelper = new DispatchHelper();
679
                DispatchHelper dispatcherHelper = new DispatchHelper();
789
                IProjectTreeEventDispatcher disp = dispatcherHelper.getProjectTreeDispatcher();
680
                IProjectTreeEventDispatcher disp = dispatcherHelper.getProjectTreeDispatcher();
790
                
681
791
                if (disp != null)
682
                if (disp != null) {
792
                {
793
                    IEventPayload payload = disp.createPayload("ProjectTreeEndDrag"); // NOI18N
683
                    IEventPayload payload = disp.createPayload("ProjectTreeEndDrag"); // NOI18N
794
                    IProjectTreeDragVerify context = new ProjectTreeDragVerifyImpl();
684
                    IProjectTreeDragVerify context = new ProjectTreeDragVerifyImpl();
795
                    context.setTargetNode(mTreeItem);
685
                    context.setTargetNode(mTreeItem);
796
                    
686
797
                    disp.fireEndDrag(null, mTransferable, mAction, context, payload);
687
                    disp.fireEndDrag(null, mTransferable, mAction, context, payload);
798
                    
688
799
                    retVal = !context.isCancel();
689
                    retVal = !context.isCancel();
800
                }
690
                }
801
            }
691
            }
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/ImportProjectRootNode.java (-35 / +18 lines)
Lines 51-57 Link Here
51
 * the Source Creation and Management node. Right-click the template and choose
51
 * the Source Creation and Management node. Right-click the template and choose
52
 * Open. You can then make changes to the template in the Source Editor.
52
 * Open. You can then make changes to the template in the Source Editor.
53
 */
53
 */
54
55
package org.netbeans.modules.uml.project.ui.nodes;
54
package org.netbeans.modules.uml.project.ui.nodes;
56
55
57
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
56
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
Lines 66-96 Link Here
66
import org.openide.nodes.AbstractNode;
65
import org.openide.nodes.AbstractNode;
67
import org.openide.util.NbBundle;
66
import org.openide.util.NbBundle;
68
67
69
70
/**
68
/**
71
 *
69
 *
72
 * @author Administrator
70
 * @author Administrator
73
 */
71
 */
74
public class ImportProjectRootNode extends AbstractNode implements ImportElementListener
72
public class ImportProjectRootNode extends AbstractNode implements ImportElementListener {
75
{
76
73
77
    IProject project = null;
74
    IProject project = null;
78
75
79
    /** Creates a new instance of ImportProjectRootNode */
76
    /** Creates a new instance of ImportProjectRootNode */
80
    public ImportProjectRootNode(UMLProjectHelper helper)
77
    public ImportProjectRootNode(UMLProjectHelper helper) {
81
    {
82
        super(new ImportedProjectChildren(helper));
78
        super(new ImportedProjectChildren(helper));
83
        this.project = helper.getProject();
79
        this.project = helper.getProject();
84
        setIconBaseWithExtension(ImageUtil.IMAGE_FOLDER + "import-elements.png"); // NOI18N
80
        setIconBaseWithExtension(ImageUtil.IMAGE_FOLDER + "import-elements.png"); // NOI18N
85
    }
81
    }
86
82
87
    public String getDisplayName()
83
    public String getDisplayName() {
88
    {
89
        return (String) NbBundle.getMessage(ImportProjectRootNode.class, "ImportedNode_Name"); // NOI18N
84
        return (String) NbBundle.getMessage(ImportProjectRootNode.class, "ImportedNode_Name"); // NOI18N
90
    }
85
    }
91
86
92
    public String getName()
87
    public String getName() {
93
    {
94
        return this.getDisplayName();
88
        return this.getDisplayName();
95
    }
89
    }
96
    ////////////////////////////////////////////////////////////////////////////
90
    ////////////////////////////////////////////////////////////////////////////
Lines 98-125 Link Here
98
92
99
    public void elementImported(IProject project,
93
    public void elementImported(IProject project,
100
            IElement element,
94
            IElement element,
101
            IElementImport importElement)
95
            IElementImport importElement) {
102
    {
103
        ImportedProjectChildren children = (ImportedProjectChildren) getChildren();
96
        ImportedProjectChildren children = (ImportedProjectChildren) getChildren();
104
        children.addNewImportedElement(project, element, importElement, true);
97
        children.addNewImportedElement(project, element, importElement, true);
105
    }
98
    }
106
99
107
    public void packageImported(IProject project,
100
    public void packageImported(IProject project,
108
            IElement element,
101
            IElement element,
109
            IPackageImport importElement)
102
            IPackageImport importElement) {
110
    {
111
        ImportedProjectChildren children = (ImportedProjectChildren) getChildren();
103
        ImportedProjectChildren children = (ImportedProjectChildren) getChildren();
112
        children.addNewImportedElement(project, element, importElement, true);
104
        children.addNewImportedElement(project, element, importElement, true);
113
    }
105
    }
114
106
115
    public void elementDeleted(IProject proj, IElement element)
107
    public void elementDeleted(IProject proj, IElement element) {
116
    {
117
        // this is the case when original model element is deleted,
108
        // this is the case when original model element is deleted,
118
        // just remove it from imported element list if it exists, no need to operate on
109
        // just remove it from imported element list if it exists, no need to operate on
119
        // the node, as filter node listens to original node events, it will be destroyed
110
        // the node, as filter node listens to original node events, it will be destroyed
120
        // once the original node is deleted.
111
        // once the original node is deleted.
121
        if (!(element instanceof IElementImport) && !(element instanceof IPackageImport))
112
        if (!(element instanceof IElementImport) && !(element instanceof IPackageImport)) {
122
        {
123
            project.removeElementImport(element);
113
            project.removeElementImport(element);
124
            return;
114
            return;
125
        }
115
        }
Lines 128-143 Link Here
128
        // 'remove from import' option is selected, or an imported element is deleted in 
118
        // 'remove from import' option is selected, or an imported element is deleted in 
129
        // other projects.
119
        // other projects.
130
        // filter out the event for deleting imported element in a different project 85134
120
        // filter out the event for deleting imported element in a different project 85134
131
        if (proj != project)
121
        if (proj != project) {
132
            return;
122
            return;
133
        
123
        }
124
134
        IElement e = element;
125
        IElement e = element;
135
        IProject ownerProject = proj;
126
        IProject ownerProject = proj;
136
        if (element instanceof IElementImport)
127
        if (element instanceof IElementImport) {
137
        {
138
            e = ((IElementImport) element).getImportedElement();
128
            e = ((IElementImport) element).getImportedElement();
139
        } else if (element instanceof IPackageImport)
129
        } else if (element instanceof IPackageImport) {
140
        {
141
            e = ((IPackageImport) element).getImportedPackage();
130
            e = ((IPackageImport) element).getImportedPackage();
142
        }
131
        }
143
//        ownerProject = e.getOwner() == null ? proj : e.getOwner().getProject();
132
//        ownerProject = e.getOwner() == null ? proj : e.getOwner().getProject();
Lines 146-174 Link Here
146
        children.removeImportElement(ownerProject, element);
135
        children.removeImportElement(ownerProject, element);
147
    }
136
    }
148
137
149
    
138
    public boolean canCopy() {
150
    public boolean canCopy()
151
    {
152
        return false;
139
        return false;
153
    }
140
    }
154
141
155
    public boolean canCut()
142
    public boolean canCut() {
156
    {
157
        return false;
143
        return false;
158
    }
144
    }
159
145
160
    public boolean canDestroy()
146
    public boolean canDestroy() {
161
    {
162
        return false;
147
        return false;
163
    }
148
    }
164
149
165
    public boolean canRename()
150
    public boolean canRename() {
166
    {
167
        return false;
151
        return false;
168
    }
152
    }
169
153
170
    public Action[] getActions(boolean context)
154
    public Action[] getActions(boolean context) {
171
    {
172
        return new Action[]{null};
155
        return new Action[]{null};
173
    }
156
    }
174
}
157
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/ImportedElementNode.java (-48 / +23 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
46
45
47
import java.io.IOException;
46
import java.io.IOException;
Lines 55-70 Link Here
55
import org.openide.nodes.FilterNode;
54
import org.openide.nodes.FilterNode;
56
import org.openide.nodes.Node;
55
import org.openide.nodes.Node;
57
56
58
57
public class ImportedElementNode extends FilterNode implements ImportedElementCookie, Comparable {
59
public class ImportedElementNode extends FilterNode implements ImportedElementCookie, Comparable
60
{
61
58
62
    private IProject referencingProject;
59
    private IProject referencingProject;
63
    private IElement elementImport;
60
    private IElement elementImport;
64
61
65
    public ImportedElementNode(IProject project, Node orig,
62
    public ImportedElementNode(IProject project, Node orig,
66
            IElementImport elementImport)
63
            IElementImport elementImport) {
67
    {
68
        super(orig, new NestedImportElementChildren(orig));
64
        super(orig, new NestedImportElementChildren(orig));
69
        this.referencingProject = project;
65
        this.referencingProject = project;
70
        this.elementImport = elementImport;
66
        this.elementImport = elementImport;
Lines 72-79 Link Here
72
    }
68
    }
73
69
74
    public ImportedElementNode(IProject project, Node orig,
70
    public ImportedElementNode(IProject project, Node orig,
75
            IPackageImport elementImport)
71
            IPackageImport elementImport) {
76
    {
77
//        super(orig, Children.LEAF);
72
//        super(orig, Children.LEAF);
78
        super(orig,
73
        super(orig,
79
                new NestedImportElementChildren(orig));
74
                new NestedImportElementChildren(orig));
Lines 81-87 Link Here
81
        this.elementImport = elementImport;
76
        this.elementImport = elementImport;
82
        this.disableDelegation(DELEGATE_DESTROY);
77
        this.disableDelegation(DELEGATE_DESTROY);
83
    }
78
    }
84
    
79
85
//   public Action[] getActions(boolean context)
80
//   public Action[] getActions(boolean context)
86
//    {
81
//    {
87
//       if (elementImport instanceof IElementImport)
82
//       if (elementImport instanceof IElementImport)
Lines 99-150 Link Here
99
//       Action[] a = new Action[list.size()];
94
//       Action[] a = new Action[list.size()];
100
//       return list.toArray(a);
95
//       return list.toArray(a);
101
//    }
96
//    }
102
97
    public <T extends Node.Cookie> T getCookie(Class<T> type) {
103
    public <T extends Node.Cookie> T getCookie(Class<T> type)
98
        if (type.isInstance(this)) {
104
    {
105
        if (type.isInstance(this))
106
        {
107
            return type.cast(this);
99
            return type.cast(this);
108
        }
100
        }
109
        return super.getCookie(type);
101
        return super.getCookie(type);
110
    }
102
    }
111
103
112
    public boolean canDestroy()
104
    public boolean canDestroy() {
113
    {
114
        return true;
105
        return true;
115
    }
106
    }
116
107
117
    public void destroy() throws IOException
108
    public void destroy() throws IOException {
118
    {
119
        destroy(true);
109
        destroy(true);
120
    }
110
    }
121
111
122
    public void destroy(boolean fromOriginal) throws IOException
112
    public void destroy(boolean fromOriginal) throws IOException {
123
    {
113
        if (fromOriginal == true) {
124
        if (fromOriginal == true)
125
        {
126
            this.getOriginal().destroy();
114
            this.getOriginal().destroy();
127
        }
115
        }
128
        super.destroy(); // calls Node.destroy(), not orig.destroy()
116
        super.destroy(); // calls Node.destroy(), not orig.destroy()
129
    }
117
    }
130
118
131
    public void removeImportedElement()
119
    public void removeImportedElement() {
132
    {
133
        IProjectTreeItem item = getOriginal().getCookie(IProjectTreeItem.class);
120
        IProjectTreeItem item = getOriginal().getCookie(IProjectTreeItem.class);
134
        if (item != null)
121
        if (item != null) {
135
        {
136
            referencingProject.removeElementImport(elementImport);
122
            referencingProject.removeElementImport(elementImport);
137
        }
123
        }
138
        try
124
        try {
139
        {
140
            destroy(false);
125
            destroy(false);
141
        } catch (IOException e)
126
        } catch (IOException e) {
142
        {
143
        }
127
        }
144
    }
128
    }
145
129
146
    public int compareTo(Object o)
130
    public int compareTo(Object o) {
147
    {
148
        return Collator.getInstance().compare(this.getName(), o.toString());
131
        return Collator.getInstance().compare(this.getName(), o.toString());
149
//        if (!(o instanceof ImportedElementNode))
132
//        if (!(o instanceof ImportedElementNode))
150
//        {
133
//        {
Lines 159-171 Link Here
159
//        return -1;
142
//        return -1;
160
    }
143
    }
161
144
162
    public IProject getReferencingProject()
145
    public IProject getReferencingProject() {
163
    {
164
        return referencingProject;
146
        return referencingProject;
165
    }
147
    }
166
148
167
    public String getElementXMIID()
149
    public String getElementXMIID() {
168
    {
169
        IProjectTreeItem item = getOriginal().getCookie(IProjectTreeItem.class);
150
        IProjectTreeItem item = getOriginal().getCookie(IProjectTreeItem.class);
170
        return (item != null) ? item.getModelElementXMIID() : "";
151
        return (item != null) ? item.getModelElementXMIID() : "";
171
    }
152
    }
Lines 175-205 Link Here
175
     *  imported element. Delete action is disabled on those sub nodes to prevent
156
     *  imported element. Delete action is disabled on those sub nodes to prevent
176
     *  user from removing model elements inadvertently from imported projects
157
     *  user from removing model elements inadvertently from imported projects
177
     */
158
     */
178
    public static class NestedImportElementChildren extends FilterNode.Children
159
    public static class NestedImportElementChildren extends FilterNode.Children {
179
    {
180
160
181
        public NestedImportElementChildren(Node or)
161
        public NestedImportElementChildren(Node or) {
182
        {
183
            super(or);
162
            super(or);
184
        }
163
        }
185
164
186
        protected Node[] createNodes(Node key)
165
        protected Node[] createNodes(Node key) {
187
        {
188
            NestedImportElementNode node = new NestedImportElementNode(key);
166
            NestedImportElementNode node = new NestedImportElementNode(key);
189
            return new Node[]{node};
167
            return new Node[]{node};
190
        }
168
        }
191
    }
169
    }
192
170
193
    public static class NestedImportElementNode extends FilterNode
171
    public static class NestedImportElementNode extends FilterNode {
194
    {
195
172
196
        public NestedImportElementNode(Node orig)
173
        public NestedImportElementNode(Node orig) {
197
        {
198
            super(orig, new NestedImportElementChildren(orig));
174
            super(orig, new NestedImportElementChildren(orig));
199
        }
175
        }
200
176
201
        public boolean canDestroy()
177
        public boolean canDestroy() {
202
        {
203
            return false;
178
            return false;
204
        }
179
        }
205
    }
180
    }
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/ImportedProjectChildren.java (-134 / +69 lines)
Lines 90-134 Link Here
90
 *
90
 *
91
 * @author Administrator
91
 * @author Administrator
92
 */
92
 */
93
public class ImportedProjectChildren extends Children.Keys implements NodeListener
93
public class ImportedProjectChildren extends Children.Keys implements NodeListener {
94
{
95
94
96
    private UMLProjectHelper mHelper = null;
95
    private UMLProjectHelper mHelper = null;
97
    private HashMap<Object, AbstractNode> mNodeMap = new HashMap<Object, AbstractNode>();
96
    private HashMap<Object, AbstractNode> mNodeMap = new HashMap<Object, AbstractNode>();
98
    private HashMap<String, IProject> ownerMap = new HashMap<String, IProject>();
97
    private HashMap<String, IProject> ownerMap = new HashMap<String, IProject>();
99
98
100
    public ImportedProjectChildren(UMLProjectHelper helper)
99
    public ImportedProjectChildren(UMLProjectHelper helper) {
101
    {
102
        mHelper = helper;
100
        mHelper = helper;
103
    }
101
    }
104
102
105
    public void addNewImportedElement(final IProject project,
103
    public void addNewImportedElement(final IProject project,
106
            final IElement element,
104
            final IElement element,
107
            final IDirectedRelationship imported,
105
            final IDirectedRelationship imported,
108
            final boolean refresh)
106
            final boolean refresh) {
109
    {
107
        if (!(imported instanceof IElementImport) && !(imported instanceof IPackageImport)) {
110
        if (!(imported instanceof IElementImport) && !(imported instanceof IPackageImport))
111
        {
112
            return;
108
            return;
113
        }
109
        }
114
        Project p = ProjectUtil.findNetBeansProjectForModel(project);
110
        Project p = ProjectUtil.findNetBeansProjectForModel(project);
115
        if (SwingUtilities.isEventDispatchThread())
111
        if (SwingUtilities.isEventDispatchThread()) {
116
        {
117
            addImportNode(project, refresh, element, imported);
112
            addImportNode(project, refresh, element, imported);
118
        } else
113
        } else {
119
        {
114
            try {
120
            try
115
                SwingUtilities.invokeLater(new Runnable() {
121
            {
122
                SwingUtilities.invokeLater(new Runnable()
123
                {
124
116
125
                    public void run()
117
                    public void run() {
126
                    {
127
                        addImportNode(project, refresh, element, imported);
118
                        addImportNode(project, refresh, element, imported);
128
                    }
119
                    }
129
                });
120
                });
130
            } catch (Exception ex)
121
            } catch (Exception ex) {
131
            {
132
                Exceptions.printStackTrace(ex);
122
                Exceptions.printStackTrace(ex);
133
            }
123
            }
134
        }
124
        }
Lines 137-144 Link Here
137
    protected void addImportNode(IProject project,
127
    protected void addImportNode(IProject project,
138
            boolean refresh,
128
            boolean refresh,
139
            IElement element,
129
            IElement element,
140
            IElement elementImport)
130
            IElement elementImport) {
141
    {
142
        // keep the logic for the moment to filter out duplicate elements, as UMLImportsUiSupport fires
131
        // keep the logic for the moment to filter out duplicate elements, as UMLImportsUiSupport fires
143
        // multiple events for one import,
132
        // multiple events for one import,
144
        // For some reason I am getting the event more than one time.  So, I have
133
        // For some reason I am getting the event more than one time.  So, I have
Lines 147-166 Link Here
147
136
148
        boolean found = false;
137
        boolean found = false;
149
        Children children = projectNode.getChildren();
138
        Children children = projectNode.getChildren();
150
        for (Node child : children.getNodes())
139
        for (Node child : children.getNodes()) {
151
        {
140
            if (((ImportedElementNode) child).getElementXMIID().equals(element.getXMIID())) {
152
            if (((ImportedElementNode) child).getElementXMIID().equals(element.getXMIID()))
153
            {
154
                found = true;
141
                found = true;
155
                break;
142
                break;
156
            }
143
            }
157
        }
144
        }
158
        if (!found)
145
        if (!found) {
159
        {
160
            Project p = ProjectUtil.findNetBeansProjectForModel(project);
146
            Project p = ProjectUtil.findNetBeansProjectForModel(project);
161
            Node orig = ProjectUtil.findNodeInProjectTree(p, element);
147
            Node orig = ProjectUtil.findNodeInProjectTree(p, element);
162
            if (orig == null)
148
            if (orig == null) {
163
            {
164
                Logger.getLogger(ImportedProjectChildren.class.getName()).
149
                Logger.getLogger(ImportedProjectChildren.class.getName()).
165
                        log(Level.WARNING,
150
                        log(Level.WARNING,
166
                        NbBundle.getMessage(ImportedProjectChildren.class,
151
                        NbBundle.getMessage(ImportedProjectChildren.class,
Lines 169-241 Link Here
169
                return;
154
                return;
170
            }
155
            }
171
            ImportedElementNode node = null;
156
            ImportedElementNode node = null;
172
            if (elementImport instanceof IElementImport)
157
            if (elementImport instanceof IElementImport) {
173
            {
174
                node = new ImportedElementNode(mHelper.getProject(),
158
                node = new ImportedElementNode(mHelper.getProject(),
175
                        orig, (IElementImport) elementImport);
159
                        orig, (IElementImport) elementImport);
176
            } else if (elementImport instanceof IPackageImport)
160
            } else if (elementImport instanceof IPackageImport) {
177
            {
178
                node = new ImportedElementNode(mHelper.getProject(),
161
                node = new ImportedElementNode(mHelper.getProject(),
179
                        orig, (IPackageImport) elementImport);
162
                        orig, (IPackageImport) elementImport);
180
            }
163
            }
181
            Node[] newNodes =
164
            Node[] newNodes = {
182
            {
183
                (Node) node
165
                (Node) node
184
            };
166
            };
185
167
186
            if (children != null)
168
            if (children != null) {
187
            {
188
                children.add(newNodes);
169
                children.add(newNodes);
189
                refreshKeys();
170
                refreshKeys();
190
            }
171
            }
191
        }
172
        }
192
    }
173
    }
193
174
194
    public void removeImportElement(IProject project, IElement element)
175
    public void removeImportElement(IProject project, IElement element) {
195
    {
196
        IElement targetElement = element;
176
        IElement targetElement = element;
197
        if (element instanceof IElementImport)
177
        if (element instanceof IElementImport) {
198
        {
199
            IElementImport imported = (IElementImport) element;
178
            IElementImport imported = (IElementImport) element;
200
            targetElement = imported.getImportedElement();
179
            targetElement = imported.getImportedElement();
201
        } else if (element instanceof IPackageImport)
180
        } else if (element instanceof IPackageImport) {
202
        {
203
            IPackageImport imported = (IPackageImport) element;
181
            IPackageImport imported = (IPackageImport) element;
204
            targetElement = imported.getImportedPackage();
182
            targetElement = imported.getImportedPackage();
205
        }
183
        }
206
184
207
        Node projectNode = mNodeMap.get(project);
185
        Node projectNode = mNodeMap.get(project);
208
        if (projectNode == null)
186
        if (projectNode == null) {
209
        {
210
            return;
187
            return;
211
        }
188
        }
212
        removeNode(projectNode, targetElement);
189
        removeNode(projectNode, targetElement);
213
    }
190
    }
214
191
215
    private void removeNode(Node root, IElement targetElement)
192
    private void removeNode(Node root, IElement targetElement) {
216
    {
217
        Children children = root.getChildren();
193
        Children children = root.getChildren();
218
        Node[] nodes = children.getNodes();
194
        Node[] nodes = children.getNodes();
219
        for (int x = 0; x < nodes.length; x++)
195
        for (int x = 0; x < nodes.length; x++) {
220
        {
221
            ImportedElementCookie cookie = nodes[x].getCookie(ImportedElementCookie.class);
196
            ImportedElementCookie cookie = nodes[x].getCookie(ImportedElementCookie.class);
222
            if (cookie != null)
197
            if (cookie != null) {
223
            {
198
                if (cookie.getElementXMIID().equals(targetElement.getXMIID())) {
224
                if (cookie.getElementXMIID().equals(targetElement.getXMIID()))
199
                    try {
225
                {
226
                    try
227
                    {
228
                        ((ImportedElementNode) nodes[x]).destroy(false);
200
                        ((ImportedElementNode) nodes[x]).destroy(false);
229
                        if (root.getChildren().getNodesCount() == 0)
201
                        if (root.getChildren().getNodesCount() == 0) {
230
                        {
231
                            IProject project = targetElement.getProject();
202
                            IProject project = targetElement.getProject();
232
                            root.destroy();
203
                            root.destroy();
233
                            mNodeMap.values().remove(root);
204
                            mNodeMap.values().remove(root);
234
                            refreshKeys();
205
                            refreshKeys();
235
                            removeModelRootNodeRefreshListener(project);
206
                            removeModelRootNodeRefreshListener(project);
236
                        }
207
                        }
237
                    } catch (Exception e)
208
                    } catch (Exception e) {
238
                    {
239
                    }
209
                    }
240
                    return;
210
                    return;
241
                }
211
                }
Lines 246-278 Link Here
246
    /* retreives the imported projects from the project
216
    /* retreives the imported projects from the project
247
     * @see org.openide.nodes.Children#addNotify()
217
     * @see org.openide.nodes.Children#addNotify()
248
     */
218
     */
249
    protected void addNotify()
219
    protected void addNotify() {
250
    {
251
        IProject project = mHelper.getProject();
220
        IProject project = mHelper.getProject();
252
        HashSet<String> map = new HashSet();
221
        HashSet<String> map = new HashSet();
253
222
254
        ETList<IPackageImport> packages = project.getPackageImports();
223
        ETList<IPackageImport> packages = project.getPackageImports();
255
        if (packages != null)
224
        if (packages != null) {
256
        {
225
            for (IPackageImport importPackage : packages) {
257
            for (IPackageImport importPackage : packages)
258
            {
259
                INamespace ns = importPackage.getImportedPackage();
226
                INamespace ns = importPackage.getImportedPackage();
260
227
261
                // I do not want to show profiles under the imported project.
228
                // I do not want to show profiles under the imported project.
262
                // I want to have another node for profiles, that allows the
229
                // I want to have another node for profiles, that allows the
263
                // the user to apply profiles.
230
                // the user to apply profiles.
264
                if (!(ns instanceof IProfile))
231
                if (!(ns instanceof IProfile)) {
265
                {
232
                    if (map.contains(ns.getXMIID())) {
266
                    if (map.contains(ns.getXMIID()))
267
                    {
268
                        continue;
233
                        continue;
269
                    }
234
                    }
270
                    map.add(ns.getXMIID());
235
                    map.add(ns.getXMIID());
271
236
272
                    IProject p = getOwningProjectOfImportedElement(ns);
237
                    IProject p = getOwningProjectOfImportedElement(ns);
273
238
274
                    if (p == null)
239
                    if (p == null) {
275
                    {
276
                        Logger.getLogger(ImportedProjectChildren.class.getName()).
240
                        Logger.getLogger(ImportedProjectChildren.class.getName()).
277
                                log(Level.WARNING,
241
                                log(Level.WARNING,
278
                                NbBundle.getMessage(ImportedProjectChildren.class,
242
                                NbBundle.getMessage(ImportedProjectChildren.class,
Lines 286-302 Link Here
286
250
287
        ETList<IElementImport> elements = project.getElementImports();
251
        ETList<IElementImport> elements = project.getElementImports();
288
252
289
        for (IElementImport importedElement : elements)
253
        for (IElementImport importedElement : elements) {
290
        {
291
            IElement elem = importedElement.getImportedElement();
254
            IElement elem = importedElement.getImportedElement();
292
            if (map.contains(elem.getXMIID()))
255
            if (map.contains(elem.getXMIID())) {
293
            {
294
                continue;
256
                continue;
295
            }
257
            }
296
            map.add(elem.getXMIID());
258
            map.add(elem.getXMIID());
297
            IProject owner = getOwningProjectOfImportedElement(elem);
259
            IProject owner = getOwningProjectOfImportedElement(elem);
298
            if (owner == null)
260
            if (owner == null) {
299
            {
300
                Logger.getLogger(ImportedProjectChildren.class.getName()).
261
                Logger.getLogger(ImportedProjectChildren.class.getName()).
301
                        log(Level.WARNING,
262
                        log(Level.WARNING,
302
                        NbBundle.getMessage(ImportedProjectChildren.class,
263
                        NbBundle.getMessage(ImportedProjectChildren.class,
Lines 309-355 Link Here
309
        }
270
        }
310
    }
271
    }
311
272
312
    protected IProject getOwningProjectOfImportedElement(IElement elem)
273
    protected IProject getOwningProjectOfImportedElement(IElement elem) {
313
    {
314
        org.dom4j.Node node = null;
274
        org.dom4j.Node node = null;
315
        IProject p = null;
275
        IProject p = null;
316
276
317
        String ownerID = XMLManip.getAttributeValue(elem.getNode(), "owner");
277
        String ownerID = XMLManip.getAttributeValue(elem.getNode(), "owner");
318
278
319
        if (ownerMap.containsKey(ownerID))
279
        if (ownerMap.containsKey(ownerID)) {
320
        {
321
            return ownerMap.get(ownerID);
280
            return ownerMap.get(ownerID);
322
        }
281
        }
323
        node = ExternalFileManager.getExternalNode(elem.getNode());
282
        node = ExternalFileManager.getExternalNode(elem.getNode());
324
283
325
        INamespace sp = UMLXMLManip.getProject(node);
284
        INamespace sp = UMLXMLManip.getProject(node);
326
        if (sp != null)
285
        if (sp != null) {
327
        {
328
            p = sp.getProject();
286
            p = sp.getProject();
329
        }
287
        }
330
        ownerMap.put(ownerID, p);
288
        ownerMap.put(ownerID, p);
331
        return p;
289
        return p;
332
    }
290
    }
333
291
334
    protected void removeNotify()
292
    protected void removeNotify() {
335
    {
336
        setKeys(Collections.EMPTY_SET);
293
        setKeys(Collections.EMPTY_SET);
337
    }
294
    }
338
295
339
    protected Node[] createNodes(Object key)
296
    protected Node[] createNodes(Object key) {
340
    {
297
        Node[] retVal = {mNodeMap.get(key)};
341
        Node[] retVal = { mNodeMap.get(key) };
342
        return retVal;
298
        return retVal;
343
    }
299
    }
344
300
345
    protected Node getOwningProject(IProject project)
301
    protected Node getOwningProject(IProject project) {
346
    {
347
        AbstractNode retVal = null;
302
        AbstractNode retVal = null;
348
        if (project != null)
303
        if (project != null) {
349
        {
350
            retVal = mNodeMap.get(project);
304
            retVal = mNodeMap.get(project);
351
            if (retVal == null)
305
            if (retVal == null) {
352
            {
353
                retVal = new AbstractNode(new Children.SortedArray());
306
                retVal = new AbstractNode(new Children.SortedArray());
354
                retVal.setName(project.getNameWithAlias());
307
                retVal.setName(project.getNameWithAlias());
355
                retVal.setIconBaseWithExtension(ImageUtil.IMAGE_FOLDER + "uml-project.png"); // NOI18N
308
                retVal.setIconBaseWithExtension(ImageUtil.IMAGE_FOLDER + "uml-project.png"); // NOI18N
Lines 361-381 Link Here
361
        return retVal;
314
        return retVal;
362
    }
315
    }
363
316
364
    protected void refreshKeys()
317
    protected void refreshKeys() {
365
    {
366
        setKeys(mNodeMap.keySet());
318
        setKeys(mNodeMap.keySet());
367
    }
319
    }
368
320
369
    private void addModelRootNodeRefreshListener(IProject project)
321
    private void addModelRootNodeRefreshListener(IProject project) {
370
    {
322
        for (Project p : ProjectUtil.getOpenUMLProjects()) {
371
        for (Project p : ProjectUtil.getOpenUMLProjects())
372
        {
373
            UMLProjectHelper helper = p.getLookup().lookup(UMLProjectHelper.class);
323
            UMLProjectHelper helper = p.getLookup().lookup(UMLProjectHelper.class);
374
            if (helper != null && helper.getProject() == project)
324
            if (helper != null && helper.getProject() == project) {
375
            {
376
                UMLPhysicalViewProvider provider = p.getLookup().lookup(UMLPhysicalViewProvider.class);
325
                UMLPhysicalViewProvider provider = p.getLookup().lookup(UMLPhysicalViewProvider.class);
377
                if (provider != null)
326
                if (provider != null) {
378
                {
379
                    UMLModelRootNode node = provider.getModelRootNode();
327
                    UMLModelRootNode node = provider.getModelRootNode();
380
                    node.addNodeListener(this);
328
                    node.addNodeListener(this);
381
                }
329
                }
Lines 383-398 Link Here
383
        }
331
        }
384
    }
332
    }
385
333
386
    private void removeModelRootNodeRefreshListener(IProject project)
334
    private void removeModelRootNodeRefreshListener(IProject project) {
387
    {
335
        for (Project p : ProjectUtil.getOpenUMLProjects()) {
388
        for (Project p : ProjectUtil.getOpenUMLProjects())
389
        {
390
            UMLProjectHelper helper = p.getLookup().lookup(UMLProjectHelper.class);
336
            UMLProjectHelper helper = p.getLookup().lookup(UMLProjectHelper.class);
391
            if (helper != null && helper.getProject() == project)
337
            if (helper != null && helper.getProject() == project) {
392
            {
393
                UMLPhysicalViewProvider provider = p.getLookup().lookup(UMLPhysicalViewProvider.class);
338
                UMLPhysicalViewProvider provider = p.getLookup().lookup(UMLPhysicalViewProvider.class);
394
                if (provider != null)
339
                if (provider != null) {
395
                {
396
                    UMLModelRootNode node = provider.getModelRootNode();
340
                    UMLModelRootNode node = provider.getModelRootNode();
397
                    node.removeNodeListener(this);
341
                    node.removeNodeListener(this);
398
                }
342
                }
Lines 400-445 Link Here
400
        }
344
        }
401
    }
345
    }
402
346
403
    protected void refreshImportedElements()
347
    protected void refreshImportedElements() {
404
    {
405
        setKeys(Collections.emptyList());
348
        setKeys(Collections.emptyList());
406
        mNodeMap.clear();
349
        mNodeMap.clear();
407
        ownerMap.clear();
350
        ownerMap.clear();
408
        
351
409
        try
352
        try {
410
        {
353
            SwingUtilities.invokeLater(new Runnable() {
411
            SwingUtilities.invokeLater(new Runnable()
354
412
            {
355
                public void run() {
413
                public void run()
414
                {
415
                    addNotify();
356
                    addNotify();
416
                }
357
                }
417
            });
358
            });
418
        } catch (Exception ex)
359
        } catch (Exception ex) {
419
        {
420
            Exceptions.printStackTrace(ex);
360
            Exceptions.printStackTrace(ex);
421
        }
361
        }
422
    }
362
    }
423
363
424
    // capture source model node refresh event triggered by filtering function
364
    // capture source model node refresh event triggered by filtering function
425
    public void childrenAdded(NodeMemberEvent ev)
365
    public void childrenAdded(NodeMemberEvent ev) {
426
    {
427
    }
366
    }
428
367
429
    public void childrenRemoved(NodeMemberEvent ev)
368
    public void childrenRemoved(NodeMemberEvent ev) {
430
    {
431
    }
369
    }
432
370
433
    public void childrenReordered(NodeReorderEvent ev)
371
    public void childrenReordered(NodeReorderEvent ev) {
434
    {
435
    }
372
    }
436
373
437
    public void nodeDestroyed(NodeEvent ev)
374
    public void nodeDestroyed(NodeEvent ev) {
438
    {
439
        refreshImportedElements();
375
        refreshImportedElements();
440
    }
376
    }
441
377
442
    public void propertyChange(PropertyChangeEvent evt)
378
    public void propertyChange(PropertyChangeEvent evt) {
443
    {
444
    }
379
    }
445
}
380
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/ModelRootNodeCookie.java (-9 / +10 lines)
Lines 47-67 Link Here
47
 *
47
 *
48
 * Created on March 25, 2005, 7:31 PM
48
 * Created on March 25, 2005, 7:31 PM
49
 */
49
 */
50
package org.netbeans.modules.uml.project.ui.nodes;
50
51
51
package org.netbeans.modules.uml.project.ui.nodes;
52
import org.netbeans.modules.uml.ui.controls.filter.IFilterDialog;
53
import javax.swing.tree.DefaultTreeModel;
52
import javax.swing.tree.DefaultTreeModel;
54
import org.openide.nodes.Node;
53
import org.openide.nodes.Node;
55
54
56
57
/**
55
/**
58
 *
56
 *
59
 * @author Mike
57
 * @author Mike
60
 */
58
 */
61
public interface ModelRootNodeCookie extends Node.Cookie
59
public interface ModelRootNodeCookie extends Node.Cookie {
62
{
60
63
	public void recalculateChildren();
61
    public void recalculateChildren();
64
	public DefaultTreeModel getTreeModelFilter();
62
65
	public void setTreeModelFilter(DefaultTreeModel val);
63
    public DefaultTreeModel getTreeModelFilter();
66
	public void filterListenerRegistered(boolean val);
64
65
    public void setTreeModelFilter(DefaultTreeModel val);
66
67
    public void filterListenerRegistered(boolean val);
67
}
68
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/NBNodeFactory.java (-54 / +43 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
47
45
48
import org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram;
46
import org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram;
Lines 58-121 Link Here
58
 * 
56
 * 
59
 * @author Trey Spiva
57
 * @author Trey Spiva
60
 */
58
 */
61
public class NBNodeFactory implements ProjectTreeNodeFactory
59
public class NBNodeFactory implements ProjectTreeNodeFactory {
62
{
63
60
64
   /**
61
    /**
65
    * 
62
     *
66
    */
63
     */
67
   public NBNodeFactory()
64
    public NBNodeFactory() {
68
   {
65
        super();
69
      super();
66
    }
70
   }
71
67
72
   /* (non-Javadoc)
68
    /* (non-Javadoc)
73
    * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createDiagramNode(org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram)
69
     * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createDiagramNode(org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram)
74
    */
70
     */
75
   public ITreeDiagram createDiagramNode(IProxyDiagram proxy)
71
    public ITreeDiagram createDiagramNode(IProxyDiagram proxy) {
76
   {
72
        return new UMLDiagramNode(proxy);
77
      return new UMLDiagramNode(proxy);
73
    }
78
   }
79
74
80
   /* (non-Javadoc)
75
    /* (non-Javadoc)
81
    * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createFolderNode()
76
     * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createFolderNode()
82
    */
77
     */
83
   public ITreeFolder createFolderNode()
78
    public ITreeFolder createFolderNode() {
84
   {
79
        return new UMLFolderNode();
85
      return new UMLFolderNode();
80
    }
86
   }
87
81
88
   /* (non-Javadoc)
82
    /* (non-Javadoc)
89
    * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createProjectNode()
83
     * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createProjectNode()
90
    */
84
     */
91
   public ITreeItem createProjectNode()
85
    public ITreeItem createProjectNode() {
92
   {
93
//      Debug.out.println("creating project node");
86
//      Debug.out.println("creating project node");
94
      return new UMLElementNode();
87
        return new UMLElementNode();
95
   }
88
    }
96
89
97
   /* (non-Javadoc)
90
    /* (non-Javadoc)
98
    * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createElementNode()
91
     * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createElementNode()
99
    */
92
     */
100
   public ITreeElement createElementNode()
93
    public ITreeElement createElementNode() {
101
   {
94
        return new UMLModelElementNode();
102
      return new UMLModelElementNode();
95
    }
103
   }
104
96
105
   /* (non-Javadoc)
97
    /* (non-Javadoc)
106
    * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createRelationshipNode()
98
     * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createRelationshipNode()
107
    */
99
     */
108
   public ITreeRelElement createRelationshipNode()
100
    public ITreeRelElement createRelationshipNode() {
109
   {
101
        return new UMLRelationshipNode();
110
      return new UMLRelationshipNode();
102
    }
111
   }
112
103
113
   /* (non-Javadoc)
104
    /* (non-Javadoc)
114
    * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createWorkspaceNode()
105
     * @see org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeNodeFactory#createWorkspaceNode()
115
    */
106
     */
116
   public ITreeWorkspace createWorkspaceNode()
107
    public ITreeWorkspace createWorkspaceNode() {
117
   {
108
        return new UMLWorkspaceNode();
118
      return new UMLWorkspaceNode();
109
    }
119
   }
120
121
}
110
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/PackageImportNode.java (-23 / +15 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
46
45
47
import java.io.IOException;
46
import java.io.IOException;
Lines 53-97 Link Here
53
 *
52
 *
54
 * @author Trey Spiva
53
 * @author Trey Spiva
55
 */
54
 */
56
public class PackageImportNode extends UMLModelElementNode
55
public class PackageImportNode extends UMLModelElementNode {
57
{
56
58
    private IPackageImport importedElement = null;
57
    private IPackageImport importedElement = null;
59
    
58
60
    /** Creates a new instance of ImportedElementNode */
59
    /** Creates a new instance of ImportedElementNode */
61
    public PackageImportNode()
60
    public PackageImportNode() {
62
    {
63
    }
61
    }
64
    
62
65
    public PackageImportNode(IPackageImport imported)
63
    public PackageImportNode(IPackageImport imported) {
66
    {
67
        super();
64
        super();
68
        setImportedElement(imported);
65
        setImportedElement(imported);
69
    }
66
    }
70
    
67
71
    public PackageImportNode(Lookup lookup, IPackageImport imported)
68
    public PackageImportNode(Lookup lookup, IPackageImport imported) {
72
    {
73
        super(lookup);
69
        super(lookup);
74
        setImportedElement(imported);
70
        setImportedElement(imported);
75
    }
71
    }
76
    
72
77
    public PackageImportNode(Children ch, Lookup lookup, IPackageImport imported)
73
    public PackageImportNode(Children ch, Lookup lookup, IPackageImport imported) {
78
    {
79
        super(ch, lookup);
74
        super(ch, lookup);
80
        setImportedElement(imported);
75
        setImportedElement(imported);
81
    }
76
    }
82
    
77
83
    public IPackageImport getImportedElement()
78
    public IPackageImport getImportedElement() {
84
    {
85
        return importedElement;
79
        return importedElement;
86
    }
80
    }
87
81
88
    public void setImportedElement(IPackageImport importedElement)
82
    public void setImportedElement(IPackageImport importedElement) {
89
    {
90
        this.importedElement = importedElement;
83
        this.importedElement = importedElement;
91
    }
84
    }
92
    
85
93
    public void destroy() throws IOException
86
    public void destroy() throws IOException {
94
    {
95
        importedElement.delete();
87
        importedElement.delete();
96
    }
88
    }
97
}
89
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLChildren.java (-174 / +140 lines)
Lines 41-52 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
47
45
48
import java.util.TreeSet;
49
50
import org.openide.nodes.Children;
46
import org.openide.nodes.Children;
51
import org.openide.nodes.Node;
47
import org.openide.nodes.Node;
52
48
Lines 54-244 Link Here
54
import org.netbeans.modules.uml.project.ui.ITreeItemExpandContext;
50
import org.netbeans.modules.uml.project.ui.ITreeItemExpandContext;
55
import org.netbeans.modules.uml.project.ui.NetBeansUMLProjectTreeModel;
51
import org.netbeans.modules.uml.project.ui.NetBeansUMLProjectTreeModel;
56
52
57
58
/**
53
/**
59
 *
54
 *
60
 * @author Trey Spiva
55
 * @author Trey Spiva
61
 */
56
 */
62
public class UMLChildren extends Children.Array
57
public class UMLChildren extends Children.Array {
63
{
64
   private ITreeItem mItem = null;
65
58
66
   public UMLChildren()
59
    private ITreeItem mItem = null;
67
   {
68
       super(new UMLChildrenNodesCollection());
69
   }
70
   
71
   /**
72
    * 
73
    */
74
   public UMLChildren(ITreeItem item)
75
   {
76
      this();
77
60
78
      setItem(item);
61
    public UMLChildren() {
79
      //setComparator(new ProjectTreeComparable());
62
        super(new UMLChildrenNodesCollection());
80
   }
63
    }
81
    
82
64
83
   public boolean add(Node[] arr)
65
    /**
84
   {
66
     *
85
       boolean retVal = super.add(arr);
67
     */
68
    public UMLChildren(ITreeItem item) {
69
        this();
70
71
        setItem(item);
72
        //setComparator(new ProjectTreeComparable());
73
    }
74
75
    public boolean add(Node[] arr) {
76
        boolean retVal = super.add(arr);
86
//       refresh();
77
//       refresh();
87
       
88
       return retVal;
89
   }
90
78
79
        return retVal;
80
    }
91
81
92
   /* (non-Javadoc)
93
    * @see org.openide.nodes.Children#addNotify()
94
    */
95
   protected void addNotify()
96
   {
97
      super.addNotify();
98
      
99
      sendNodeExpandEvent();
100
   }
101
82
102
   /* (non-Javadoc)s
83
    /* (non-Javadoc)
103
    * @see org.openide.nodes.Children#removeNotify()
84
     * @see org.openide.nodes.Children#addNotify()
104
    */
85
     */
105
   protected void removeNotify()
86
    protected void addNotify() {
106
   {
87
        super.addNotify();
107
      super.removeNotify();
108
   }
109
   
110
   public boolean areChildrenInitialized()
111
   {
112
      return isInitialized();
113
   }
114
   
115
   //**************************************************
116
   // Data Access Methods
117
   //**************************************************
118
   
119
   /**
120
    * Retrieves the project tree item used to describe the model element that 
121
    * contains the children.
122
    * 
123
    * @return The project tree item.
124
    */
125
   public ITreeItem getItem()
126
   {
127
      return mItem;
128
   }
129
88
130
   /**
89
        sendNodeExpandEvent();
131
    * Sets  the project tree item used to describe the model element that 
90
    }
132
    * contains the children.
133
    * 
134
    * @param item The project tree item.
135
    */
136
   public void setItem(ITreeItem item)
137
   {
138
      mItem = item;
139
   }
140
   
141
   //**************************************************
142
   // Helper Methods
143
   //**************************************************
144
   
145
   /**
146
    * Notify listeners that a node is being expanded.  Listeners are able to add
147
    * nodes to the ProjectTreeItem.
148
    */
149
   protected void sendNodeExpandEvent()
150
   {
151
      final NetBeansUMLProjectTreeModel model = UMLModelRootNode.getProjectTreeModel(); 
152
      final ITreeItem item = getItem();
153
      
154
      // Debug.out.println("UMLChildren Firing node expand event");
155
      if((model != null) && (item != null))  
156
      {
157
         model.fireItemExpanding(item, new ChildrenNodeContext());    
158
         
159
         item.setIsInitalized(true);
160
      }      
161
   }
162
   
163
91
164
  /**
92
    /* (non-Javadoc)s
165
    * Test to see if we can redraw the children list on demand, would
93
     * @see org.openide.nodes.Children#removeNotify()
166
   * help with the filter action impl if it works
94
     */
167
    */
95
    protected void removeNotify() {
168
   public void recalculateChildren()
96
        super.removeNotify();
169
   {
97
    }
170
      final NetBeansUMLProjectTreeModel model = UMLModelRootNode.getProjectTreeModel(); 
171
      final ITreeItem item = getItem();
172
      item.setIsInitalized(false);
173
      
174
      // Debug.out.println("UMLChildren.recalculateChildren");
175
      if((model != null) && (item != null))  
176
      {
177
         // MCF - we have to remove the existing nodes at some point,
178
         // otherwise new nodes are added in addition to the prior ones
179
         // Not sure if this is the most efficient thing to do or if this
180
         // is the right place to do it.
181
	 MUTEX.readAccess(new Runnable() 
182
	 {
183
	     public void run() 
184
	     {
185
		 if (nodes != null) 
186
		 {
187
		     remove(getNodes());
188
		     refresh();
189
		 }
190
	     }
191
	 });  
192
          
193
	 MUTEX.readAccess(new Runnable() 
194
	 {
195
	     public void run() 
196
	     {
197
		 model.fireItemExpanding(item, new ChildrenNodeContext());  
198
	     }
199
	 });  
200
         
201
         item.setIsInitalized(true);
202
      }      
203
   }
204
98
205
 
99
    public boolean areChildrenInitialized() {
206
   /** 
100
        return isInitialized();
207
    *  update the nodemap hash in the model to avoid "ghost" nodes in the hash
101
    }
208
    */
209
   public boolean remove(Node[] nodes)
210
   {       
211
       NetBeansUMLProjectTreeModel model = UMLModelRootNode.getProjectTreeModel(); 
212
       if (model != null) 
213
       { 
214
	   for (int i = 0; i < nodes.length; i++) 
215
	   {
216
	       if (nodes[i] instanceof ITreeItem) 
217
	       {
218
		   model.removeInstanceFromHash((ITreeItem)nodes[i]);
219
	       }
220
	   }
221
       }
222
       return super.remove(nodes);
223
   }
224
   
225
102
226
   public class ChildrenNodeContext implements ITreeItemExpandContext
103
    //**************************************************
227
   {
104
    // Data Access Methods
105
    //**************************************************
106
    /**
107
     * Retrieves the project tree item used to describe the model element that
108
     * contains the children.
109
     *
110
     * @return The project tree item.
111
     */
112
    public ITreeItem getItem() {
113
        return mItem;
114
    }
228
115
229
      /* (non-Javadoc)
116
    /**
230
       * @see org.netbeans.modules.uml.netbeans.umlproject.ui.IProjectTreeExpandContext#itemAdded(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
117
     * Sets  the project tree item used to describe the model element that
231
       */
118
     * contains the children.
232
      public void itemAdded(ITreeItem item)
119
     *
233
      {
120
     * @param item The project tree item.
234
         Node[] nodes = {new UMLElementNode(item)};
121
     */
235
         boolean isAdded = add(nodes);
122
    public void setItem(ITreeItem item) {
236
      }
123
        mItem = item;
237
      
124
    }
238
      public String toString()
239
      {
240
         return mItem.getDisplayedName();
241
      }
242
   }
243
125
126
    //**************************************************
127
    // Helper Methods
128
    //**************************************************
129
    /**
130
     * Notify listeners that a node is being expanded.  Listeners are able to add
131
     * nodes to the ProjectTreeItem.
132
     */
133
    protected void sendNodeExpandEvent() {
134
        final NetBeansUMLProjectTreeModel model = UMLModelRootNode.getProjectTreeModel();
135
        final ITreeItem item = getItem();
136
137
        // Debug.out.println("UMLChildren Firing node expand event");
138
        if ((model != null) && (item != null)) {
139
            model.fireItemExpanding(item, new ChildrenNodeContext());
140
141
            item.setIsInitalized(true);
142
        }
143
    }
144
145
    /**
146
     * Test to see if we can redraw the children list on demand, would
147
     * help with the filter action impl if it works
148
     */
149
    public void recalculateChildren() {
150
        final NetBeansUMLProjectTreeModel model = UMLModelRootNode.getProjectTreeModel();
151
        final ITreeItem item = getItem();
152
        item.setIsInitalized(false);
153
154
        // Debug.out.println("UMLChildren.recalculateChildren");
155
        if ((model != null) && (item != null)) {
156
            // MCF - we have to remove the existing nodes at some point,
157
            // otherwise new nodes are added in addition to the prior ones
158
            // Not sure if this is the most efficient thing to do or if this
159
            // is the right place to do it.
160
            MUTEX.readAccess(new Runnable() {
161
162
                public void run() {
163
                    if (nodes != null) {
164
                        remove(getNodes());
165
                        refresh();
166
                    }
167
                }
168
            });
169
170
            MUTEX.readAccess(new Runnable() {
171
172
                public void run() {
173
                    model.fireItemExpanding(item, new ChildrenNodeContext());
174
                }
175
            });
176
177
            item.setIsInitalized(true);
178
        }
179
    }
180
181
    /**
182
     *  update the nodemap hash in the model to avoid "ghost" nodes in the hash
183
     */
184
    public boolean remove(Node[] nodes) {
185
        NetBeansUMLProjectTreeModel model = UMLModelRootNode.getProjectTreeModel();
186
        if (model != null) {
187
            for (int i = 0; i < nodes.length; i++) {
188
                if (nodes[i] instanceof ITreeItem) {
189
                    model.removeInstanceFromHash((ITreeItem) nodes[i]);
190
                }
191
            }
192
        }
193
        return super.remove(nodes);
194
    }
195
196
    public class ChildrenNodeContext implements ITreeItemExpandContext {
197
198
        /* (non-Javadoc)
199
         * @see org.netbeans.modules.uml.netbeans.umlproject.ui.IProjectTreeExpandContext#itemAdded(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
200
         */
201
        public void itemAdded(ITreeItem item) {
202
            Node[] nodes = {new UMLElementNode(item)};
203
            boolean isAdded = add(nodes);
204
        }
205
206
        public String toString() {
207
            return mItem.getDisplayedName();
208
        }
209
    }
244
}
210
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLChildrenNodesCollection.java (-168 / +96 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
47
45
48
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeEvent;
Lines 63-147 Link Here
63
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem;
61
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem;
64
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeDiagram;
62
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeDiagram;
65
63
64
public class UMLChildrenNodesCollection implements Collection<Node>, NodeListener {
66
65
67
68
public class UMLChildrenNodesCollection implements Collection<Node>, NodeListener
69
{
70
    
71
    TreeMap<Key, ArrayList<Node>> map = new TreeMap<Key, ArrayList<Node>>();
66
    TreeMap<Key, ArrayList<Node>> map = new TreeMap<Key, ArrayList<Node>>();
72
    Hashtable<Node, Key> hash = new Hashtable<Node, Key>();
67
    Hashtable<Node, Key> hash = new Hashtable<Node, Key>();
73
74
    static int cnt = 0;
68
    static int cnt = 0;
75
    int ind = cnt++;
69
    int ind = cnt++;
76
70
77
    public int size() 
71
    public int size() {
78
    {
72
        return hash.size();
79
        return hash.size();        
80
    }
73
    }
81
74
82
    public boolean isEmpty() 
75
    public boolean isEmpty() {
83
    {
84
        return hash.isEmpty();
76
        return hash.isEmpty();
85
    }
77
    }
86
78
87
    public boolean contains(Object o) 
79
    public boolean contains(Object o) {
88
    {        
89
        Node n = null;
80
        Node n = null;
90
        if (o instanceof Node) 
81
        if (o instanceof Node) {
91
        {
82
            n = (Node) o;
92
            n = (Node)o;
83
        } else {
93
        } 
94
        else 
95
        {
96
            return false;
84
            return false;
97
        }
85
        }
98
        Key k = hash.get(n);
86
        Key k = hash.get(n);
99
        if (k != null) 
87
        if (k != null) {
100
        {
101
            ArrayList<Node> list = map.get(k);
88
            ArrayList<Node> list = map.get(k);
102
            if (list != null) 
89
            if (list != null) {
103
            {
90
                if (list.contains(n)) {
104
                if (list.contains(n)) 
105
                {
106
                    return true;
91
                    return true;
107
                }
92
                }
108
            }
93
            }
109
        }
94
        }
110
        Key k2 = calculateKey(n);
95
        Key k2 = calculateKey(n);
111
        if (! k2.equals(k)) 
96
        if (!k2.equals(k)) {
112
        {
113
            ArrayList<Node> list = map.get(k2);
97
            ArrayList<Node> list = map.get(k2);
114
            if (list != null) 
98
            if (list != null) {
115
            {
116
                return list.contains(n);
99
                return list.contains(n);
117
            }
100
            }
118
        }
101
        }
119
        return false;
102
        return false;
120
    }
103
    }
121
104
122
    public Iterator<Node> iterator() 
105
    public Iterator<Node> iterator() {
123
    {
124
        ArrayList<Node> list = asList();
106
        ArrayList<Node> list = asList();
125
        return list.iterator(); 
107
        return list.iterator();
126
    }
108
    }
127
109
128
    public <T> T[] toArray(T[] a) 
110
    public <T> T[] toArray(T[] a) {
129
    {
130
        ArrayList<Node> list = asList();
111
        ArrayList<Node> list = asList();
131
        return list.toArray(a);
112
        return list.toArray(a);
132
    }
113
    }
133
114
134
    public Object[] toArray() 
115
    public Object[] toArray() {
135
    {
136
        ArrayList<Node> list = asList();
116
        ArrayList<Node> list = asList();
137
        return list.toArray();
117
        return list.toArray();
138
    }
118
    }
139
119
140
    public boolean add(Node n)
120
    public boolean add(Node n) {
141
    {   
142
        boolean added = false;
121
        boolean added = false;
143
        if (! hash.containsKey(n)) 
122
        if (!hash.containsKey(n)) {
144
        {
145
            Key k = calculateKey(n);
123
            Key k = calculateKey(n);
146
            addToMap(n, k);
124
            addToMap(n, k);
147
            hash.put(n, k);
125
            hash.put(n, k);
Lines 151-176 Link Here
151
        return added;
129
        return added;
152
    }
130
    }
153
131
154
    void addToMap(Node n, Key k) 
132
    void addToMap(Node n, Key k) {
155
    {
156
        ArrayList<Node> list = map.get(k);
133
        ArrayList<Node> list = map.get(k);
157
        if (list == null) 
134
        if (list == null) {
158
        {
159
            list = new ArrayList<Node>(1);
135
            list = new ArrayList<Node>(1);
160
            map.put(k, list);
136
            map.put(k, list);
161
        }
137
        }
162
        list.add(n);
138
        list.add(n);
163
    }
139
    }
164
140
165
    public boolean remove(Object o) 
141
    public boolean remove(Object o) {
166
    {
167
        Node n = null;
142
        Node n = null;
168
        if (o instanceof Node) 
143
        if (o instanceof Node) {
169
        {
144
            n = (Node) o;
170
            n = (Node)o;
145
        } else {
171
        } 
172
        else 
173
        {
174
            return false;
146
            return false;
175
        }
147
        }
176
        boolean removed = false;
148
        boolean removed = false;
Lines 178-205 Link Here
178
        Key k = hash.get(n);
150
        Key k = hash.get(n);
179
        removed = removeFromMap(n, k);
151
        removed = removeFromMap(n, k);
180
        Key k2 = calculateKey(n);
152
        Key k2 = calculateKey(n);
181
        if (! k2.equals(k)) 
153
        if (!k2.equals(k)) {
182
        {
183
            removed |= removeFromMap(n, k2);
154
            removed |= removeFromMap(n, k2);
184
        }
155
        }
185
156
186
        hash.remove(n);
157
        hash.remove(n);
187
        n.removeNodeListener(this);
158
        n.removeNodeListener(this);
188
        
159
189
        return removed;
160
        return removed;
190
    }
161
    }
191
162
192
    boolean removeFromMap(Node n, Key k) 
163
    boolean removeFromMap(Node n, Key k) {
193
    {
194
        boolean removed = false;
164
        boolean removed = false;
195
        if (k != null) 
165
        if (k != null) {
196
        {
197
            ArrayList<Node> list = map.get(k);
166
            ArrayList<Node> list = map.get(k);
198
            if (list != null) 
167
            if (list != null) {
199
            {
200
                removed = list.remove(n);
168
                removed = list.remove(n);
201
                if (list.size() == 0) 
169
                if (list.size() == 0) {
202
                {
203
                    map.remove(k);
170
                    map.remove(k);
204
                }
171
                }
205
            }
172
            }
Lines 207-321 Link Here
207
        return removed;
174
        return removed;
208
    }
175
    }
209
176
210
    public boolean addAll(Collection<? extends Node> c) 
177
    public boolean addAll(Collection<? extends Node> c) {
211
    {
212
        boolean changed = false;
178
        boolean changed = false;
213
        for(Node n : c) 
179
        for (Node n : c) {
214
        {
215
            changed |= add(n);
180
            changed |= add(n);
216
        }
181
        }
217
        return changed;
182
        return changed;
218
    }
183
    }
219
184
220
    public boolean removeAll(Collection<?> c) 
185
    public boolean removeAll(Collection<?> c) {
221
    {
222
        boolean changed = false;
186
        boolean changed = false;
223
        for(Object n : c) 
187
        for (Object n : c) {
224
        {
225
            changed |= remove(n);
188
            changed |= remove(n);
226
        }
189
        }
227
        return changed;       
190
        return changed;
228
    }
191
    }
229
    
192
230
    public boolean containsAll(Collection<?> c)
193
    public boolean containsAll(Collection<?> c) {
231
    {
232
        boolean contains = true;
194
        boolean contains = true;
233
        for(Object n : c) 
195
        for (Object n : c) {
234
        {
235
            contains &= contains(n);
196
            contains &= contains(n);
236
        }
197
        }
237
        return contains;        
198
        return contains;
238
    }
199
    }
239
200
240
    public boolean retainAll(Collection<?> c) 
201
    public boolean retainAll(Collection<?> c) {
241
    {
242
        ArrayList<Node> list = asList();
202
        ArrayList<Node> list = asList();
243
        boolean changed = false;
203
        boolean changed = false;
244
        for(Node n : list) 
204
        for (Node n : list) {
245
        {
205
            if (!c.contains(n)) {
246
            if (! c.contains(n)) 
206
                changed |= remove(n);
247
            {
207
            }
248
               changed |= remove(n);
249
            } 
250
        }
208
        }
251
        return changed;        
209
        return changed;
252
    }
210
    }
253
211
254
    public void clear() 
212
    public void clear() {
255
    {
256
        hash.clear();
213
        hash.clear();
257
        map.clear();
214
        map.clear();
258
    }
215
    }
259
216
260
    @Override
217
    @Override
261
    public boolean equals(Object o) 
218
    public boolean equals(Object o) {
262
    {
263
        return (o == null ? false : hashCode() == o.hashCode());
219
        return (o == null ? false : hashCode() == o.hashCode());
264
    }
220
    }
265
    
221
266
    @Override
222
    @Override
267
    public int hashCode() 
223
    public int hashCode() {
268
    {
269
        int h = (hash == null ? 0 : hash.hashCode());
224
        int h = (hash == null ? 0 : hash.hashCode());
270
        int m = (map == null ? 0 : map.hashCode());
225
        int m = (map == null ? 0 : map.hashCode());
271
        return h ^ m;       
226
        return h ^ m;
272
    }
227
    }
273
228
274
    
229
    void dumpMap() {
275
    void dumpMap() 
276
    {
277
        ArrayList<Node> res = new ArrayList<Node>(hash.size());
230
        ArrayList<Node> res = new ArrayList<Node>(hash.size());
278
        Set<Key> ks = map.keySet();
231
        Set<Key> ks = map.keySet();
279
        for(Key k : ks) 
232
        for (Key k : ks) {
280
        {
233
            System.out.println("  key: " + k.name);
281
            System.out.println("  key: "+k.name);            
234
            ArrayList<Node> list = map.get(k);
282
            ArrayList<Node> list = map.get(k);            
235
            for (Node n : list) {
283
            for(Node n : list) 
236
                System.out.println("    n: " + n);
284
            {
285
                System.out.println("    n: "+n);                           
286
            }
237
            }
287
        }
238
        }
288
    }
239
    }
289
240
290
    ArrayList<Node> asList() 
241
    ArrayList<Node> asList() {
291
    {
292
        ArrayList<Node> res = new ArrayList<Node>(hash.size());
242
        ArrayList<Node> res = new ArrayList<Node>(hash.size());
293
        Collection<ArrayList<Node>> c = map.values();
243
        Collection<ArrayList<Node>> c = map.values();
294
        for(ArrayList<Node> list : c) 
244
        for (ArrayList<Node> list : c) {
295
        {
245
            for (Node n : list) {
296
            for(Node n : list) 
297
            {
298
                res.add(n);
246
                res.add(n);
299
            }
247
            }
300
        }
248
        }
301
        return res;
249
        return res;
302
    }
250
    }
303
251
304
    Key calculateKey(Node n) 
252
    Key calculateKey(Node n) {
305
    {
253
        if (n instanceof ITreeItem) {
306
        if(n instanceof ITreeItem)
254
            ITreeItem item = (ITreeItem) n;
307
        { 
255
308
            ITreeItem item = (ITreeItem)n;
309
            
310
            long priority = item.getSortPriority();
256
            long priority = item.getSortPriority();
311
            String name = "";
257
            String name = "";
312
            if (n instanceof ITreeDiagram) 
258
            if (n instanceof ITreeDiagram) {
313
            {
259
                ITreeDiagram diagram = (ITreeDiagram) n;
314
                ITreeDiagram diagram = (ITreeDiagram)n;
315
                name = diagram.getData().getDescription();
260
                name = diagram.getData().getDescription();
316
            } 
261
            } else {
317
            else 
318
            {
319
                name = item.getDisplayedName().toLowerCase();
262
                name = item.getDisplayedName().toLowerCase();
320
            }
263
            }
321
            return new Key(priority, name);
264
            return new Key(priority, name);
Lines 323-392 Link Here
323
        return new Key(0, "");
266
        return new Key(0, "");
324
    }
267
    }
325
268
326
    class Key implements Comparable<Key>
269
    class Key implements Comparable<Key> {
327
    {
270
328
        long priority;
271
        long priority;
329
        String name;
272
        String name;
330
        
273
331
        Key(long priority, String name) 
274
        Key(long priority, String name) {
332
        {
333
            this.priority = priority;
275
            this.priority = priority;
334
            this.name = name;
276
            this.name = name;
335
        }
277
        }
336
278
337
        public int compareTo(Key other) 
279
        public int compareTo(Key other) {
338
        {
280
            if (this.priority > other.priority) {
339
            if (this.priority > other.priority) 
281
                return 1;
340
            {
282
            } else if (this.priority < other.priority) {
341
                return 1; 
283
                return -1;
342
            } 
284
            } else {
343
            else if (this.priority < other.priority)
285
                if (name != null) {
344
            {
345
                return -1;                
346
            }
347
            else 
348
            {
349
                if (name != null) 
350
                {
351
                    return name.compareTo(other.name);
286
                    return name.compareTo(other.name);
352
                }
287
                } else {
353
                else 
354
                {
355
                    return -1;
288
                    return -1;
356
                }
289
                }
357
            }
290
            }
358
        }
291
        }
359
292
360
        @Override
293
        @Override
361
        public boolean equals(Object o) 
294
        public boolean equals(Object o) {
362
        {
295
            if (!(o instanceof Key)) {
363
            if (! (o instanceof Key)) 
364
            {
365
                return false;
296
                return false;
366
            }
297
            }
367
            Key other = (Key)o;
298
            Key other = (Key) o;
368
            if (this.name != null && this.name.equals(other.name)
299
            if (this.name != null && this.name.equals(other.name)
369
                && this.priority == other.priority) 
300
                    && this.priority == other.priority) {
370
            {
371
                return true;
301
                return true;
372
            }
302
            }
373
            return false;
303
            return false;
374
        }
304
        }
375
   
376
    }
305
    }
377
306
378
    public void propertyChange (PropertyChangeEvent ev) 
307
    public void propertyChange(PropertyChangeEvent ev) {
379
    {
380
        Object src = ev.getSource();
308
        Object src = ev.getSource();
381
        if (src instanceof Node) 
309
        if (src instanceof Node) {
382
        {
383
            Node n = (Node) src;
310
            Node n = (Node) src;
384
            String propName = ev.getPropertyName();
311
            String propName = ev.getPropertyName();
385
            if (propName != null) 
312
            if (propName != null) {
386
            {
313
                if (propName.equals(Node.PROP_DISPLAY_NAME)
387
                if (propName.equals(Node.PROP_DISPLAY_NAME ) 
314
                        || propName.equals(Node.PROP_NAME)) {
388
                    || propName.equals(Node.PROP_NAME ))
389
                { 
390
                    removeFromMap(n, hash.get(n));
315
                    removeFromMap(n, hash.get(n));
391
                    addToMap(n, calculateKey(n));
316
                    addToMap(n, calculateKey(n));
392
                    hash.put(n, calculateKey(n));
317
                    hash.put(n, calculateKey(n));
Lines 394-406 Link Here
394
            }
319
            }
395
        }
320
        }
396
    }
321
    }
397
    
398
    public void childrenAdded(NodeMemberEvent ev) {}
399
322
400
    public void childrenRemoved(NodeMemberEvent ev) {}
323
    public void childrenAdded(NodeMemberEvent ev) {
324
    }
401
325
402
    public void childrenReordered(NodeReorderEvent ev) {}
326
    public void childrenRemoved(NodeMemberEvent ev) {
327
    }
403
328
404
    public void nodeDestroyed(NodeEvent ev) {}
329
    public void childrenReordered(NodeReorderEvent ev) {
330
    }
405
331
332
    public void nodeDestroyed(NodeEvent ev) {
333
    }
406
}
334
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLDiagramNode.java (-321 / +217 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
46
45
47
import org.netbeans.modules.uml.ui.support.ADTransferable;
46
import org.netbeans.modules.uml.ui.support.ADTransferable;
Lines 83-93 Link Here
83
/**
82
/**
84
 *
83
 *
85
 * @author Trey Spiva
84
 * @author Trey Spiva
86
  */ //TODO
85
 */ //TODO
87
@SuppressWarnings("unchecked")
86
@SuppressWarnings("unchecked")
88
public class UMLDiagramNode extends UMLElementNode
87
public class UMLDiagramNode extends UMLElementNode
89
        implements ITreeDiagram    //, IDrawingAreaEventsSink
88
        implements ITreeDiagram //, IDrawingAreaEventsSink
90
{
89
{
90
91
    private IProxyDiagram mDiagram = null;
91
    private IProxyDiagram mDiagram = null;
92
    private String mDiagramType = ELEMENT_TYPE_DIAGRAM;
92
    private String mDiagramType = ELEMENT_TYPE_DIAGRAM;
93
    private DiagramPrintCookie mPrintCookie = null;
93
    private DiagramPrintCookie mPrintCookie = null;
Lines 97-160 Link Here
97
    //
97
    //
98
    public static final String ETLD_EXTENSION = "etld"; // NOI18N
98
    public static final String ETLD_EXTENSION = "etld"; // NOI18N
99
    public static final String ETLP_EXTENSION = "etlp"; // NOI18N
99
    public static final String ETLP_EXTENSION = "etlp"; // NOI18N
100
    
100
101
    public UMLDiagramNode(IProxyDiagram diagram)
101
    public UMLDiagramNode(IProxyDiagram diagram) {
102
    {
103
        super();
102
        super();
104
        initializeNode(diagram);
103
        initializeNode(diagram);
105
    }
104
    }
106
    
105
107
    public UMLDiagramNode(Lookup l, IProxyDiagram diagram)
106
    public UMLDiagramNode(Lookup l, IProxyDiagram diagram) {
108
    {
109
        super(l);
107
        super(l);
110
        initializeNode(diagram);
108
        initializeNode(diagram);
111
    }
109
    }
112
    
110
113
    private void initializeNode(IProxyDiagram diagram)
111
    private void initializeNode(IProxyDiagram diagram) {
114
    {
115
        setDiagram(diagram);
112
        setDiagram(diagram);
116
        setFilename(diagram.getFilename());
113
        setFilename(diagram.getFilename());
117
        setDiagramType(diagram.getDiagramKindName());
114
        setDiagramType(diagram.getDiagramKindName());
118
        registerListeners();
115
        registerListeners();
119
        getCookieSet().add(this);
116
        getCookieSet().add(this);
120
    }
117
    }
121
    
118
122
    public String getShortDescription()
119
    public String getShortDescription() {
123
    {
124
        StringBuffer fullNameSpace = new StringBuffer();
120
        StringBuffer fullNameSpace = new StringBuffer();
125
        IProject project = getDiagram().getProject();
121
        IProject project = getDiagram().getProject();
126
        String qname = getDiagram().getQualifiedName();
122
        String qname = getDiagram().getQualifiedName();
127
        fullNameSpace.append(project + "::" + qname); // NOI18N
123
        fullNameSpace.append(project + "::" + qname); // NOI18N
128
        
124
129
        return fullNameSpace.toString();
125
        return fullNameSpace.toString();
130
    }
126
    }
131
    
127
132
    
128
    public void registerListeners() {
133
    public void registerListeners()
129
        if (isListenersRegistered()) {
134
    {
135
        if (isListenersRegistered())
136
            return;
130
            return;
137
        
131
        }
132
138
//        getDispatchHelper().registerDrawingAreaEvents(this);
133
//        getDispatchHelper().registerDrawingAreaEvents(this);
139
        setListenersRegistered(true);
134
        setListenersRegistered(true);
140
    }
135
    }
141
    
136
142
    public void unregisterListeners()
137
    public void unregisterListeners() {
143
    {
144
//        getDispatchHelper().revokeDrawingAreaSink(this);
138
//        getDispatchHelper().revokeDrawingAreaSink(this);
145
        setListenersRegistered(false);
139
        setListenersRegistered(false);
146
    }
140
    }
147
    
141
148
    
149
    // enables the node to be renamed
142
    // enables the node to be renamed
150
    public boolean canRename()
143
    public boolean canRename() {
151
    {
152
        return !isOldDiagramFormat();
144
        return !isOldDiagramFormat();
153
    }
145
    }
154
146
155
    @Override
147
    @Override
156
    public boolean canCopy()
148
    public boolean canCopy() {
157
    {
158
        return !isOldDiagramFormat();
149
        return !isOldDiagramFormat();
159
    }
150
    }
160
151
Lines 162-195 Link Here
162
    public boolean canCut() {
153
    public boolean canCut() {
163
        return !isOldDiagramFormat();
154
        return !isOldDiagramFormat();
164
    }
155
    }
165
    
156
166
    @Override
157
    @Override
167
    public void destroy() throws IOException
158
    public void destroy() throws IOException {
168
    {
169
        ProxyDiagramManager proxyDiagramManager = ProxyDiagramManager.instance();
159
        ProxyDiagramManager proxyDiagramManager = ProxyDiagramManager.instance();
170
        proxyDiagramManager.removeDiagram(getDiagram().getFilename());
160
        proxyDiagramManager.removeDiagram(getDiagram().getFilename());
171
        
161
172
        super.destroy();
162
        super.destroy();
173
    }
163
    }
174
    
164
175
   /* (non-Javadoc)
165
    /* (non-Javadoc)
176
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeDiagram#getDiagram()
166
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeDiagram#getDiagram()
177
    */
167
     */
178
    public IProxyDiagram getDiagram()
168
    public IProxyDiagram getDiagram() {
179
    {
180
        return mDiagram;
169
        return mDiagram;
181
    }
170
    }
182
    
171
183
    /**
172
    /**
184
     * Set the diagram that is wrapped by the node.
173
     * Set the diagram that is wrapped by the node.
185
     *
174
     *
186
     * @param diagram The diagram.
175
     * @param diagram The diagram.
187
     */
176
     */
188
    public void setDiagram(IProxyDiagram diagram)
177
    public void setDiagram(IProxyDiagram diagram) {
189
    {
190
        mDiagram = diagram;
178
        mDiagram = diagram;
191
    }
179
    }
192
    
180
193
    /**
181
    /**
194
     * Sets the diagram type.  The diagram type name is also used to determine
182
     * Sets the diagram type.  The diagram type name is also used to determine
195
     * the icon that represents the node.  If <i>_CLOSED</i> is appended to the
183
     * the icon that represents the node.  If <i>_CLOSED</i> is appended to the
Lines 197-217 Link Here
197
     *
185
     *
198
     * @param name The diagram type name.
186
     * @param name The diagram type name.
199
     */
187
     */
200
    public void setDiagramType(String name)
188
    public void setDiagramType(String name) {
201
    {
202
        mDiagramType = name;
189
        mDiagramType = name;
203
        fireIconChange();
190
        fireIconChange();
204
    }
191
    }
205
192
206
    
193
    public DiagramPrintCookie getPrintCookie() {
207
    public DiagramPrintCookie getPrintCookie()
194
        if (mPrintCookie == null) {
208
    {
209
        if (mPrintCookie == null)
210
            mPrintCookie = new DiagramPrintCookie();
195
            mPrintCookie = new DiagramPrintCookie();
211
        
196
        }
197
212
        return mPrintCookie;
198
        return mPrintCookie;
213
    }
199
    }
214
    
200
215
    /**
201
    /**
216
     * Retrieves the diagram type.  The diagram type name is also used to
202
     * Retrieves the diagram type.  The diagram type name is also used to
217
     * determine the icon that represents the node.  If <i>_CLOSED</i> is
203
     * determine the icon that represents the node.  If <i>_CLOSED</i> is
Lines 219-291 Link Here
219
     *
205
     *
220
     * @return The diagram type name.
206
     * @return The diagram type name.
221
     */
207
     */
222
    public String getDiagramType()
208
    public String getDiagramType() {
223
    {
224
        return mDiagramType;
209
        return mDiagramType;
225
    }
210
    }
226
    
211
227
    @Override
212
    @Override
228
    public Transferable clipboardCopy()
213
    public Transferable clipboardCopy()
229
    throws IOException
214
            throws IOException {
230
    {
231
        ADTransferable retVal = new ADTransferable("DRAGGEDITEMS"); // NOI18N
215
        ADTransferable retVal = new ADTransferable("DRAGGEDITEMS"); // NOI18N
232
        retVal.addDiagramLocation(getDiagram().getFilename());
216
        retVal.addDiagramLocation(getDiagram().getFilename());
233
        
217
234
        DispatchHelper heleper = new DispatchHelper();
218
        DispatchHelper heleper = new DispatchHelper();
235
        org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeEventDispatcher disp = heleper.getProjectTreeDispatcher();
219
        org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeEventDispatcher disp = heleper.getProjectTreeDispatcher();
236
        
220
237
        if (disp != null)
221
        if (disp != null) {
238
        {
239
            org.netbeans.modules.uml.core.eventframework.IEventPayload payload =
222
            org.netbeans.modules.uml.core.eventframework.IEventPayload payload =
240
                    disp.createPayload("ProjectTreeBeginDrag"); //$NON-NLS-1$
223
                    disp.createPayload("ProjectTreeBeginDrag"); //$NON-NLS-1$
241
            
224
242
            org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeDragVerify context =
225
            org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeDragVerify context =
243
                    new org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeDragVerifyImpl();
226
                    new org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeDragVerifyImpl();
244
            
227
245
            if (this instanceof ITreeItem)
228
            if (this instanceof ITreeItem) {
246
            {
229
                IProjectTreeItem[] items = {((ITreeItem) this).getData()};
247
                IProjectTreeItem[] items = {((ITreeItem)this).getData()};
248
                disp.fireBeginDrag(null, items, context, payload);
230
                disp.fireBeginDrag(null, items, context, payload);
249
            }
231
            }
250
            
232
251
        }
233
        }
252
        return retVal;
234
        return retVal;
253
    }
235
    }
254
    
236
255
    
256
    @Override
237
    @Override
257
    public Action getPreferredAction()
238
    public Action getPreferredAction() {
258
    {
259
        // disable double click open action for those unsupported diagram types for 6.5 M1
239
        // disable double click open action for those unsupported diagram types for 6.5 M1
260
        int kind = getDiagram().getDiagramKind();
240
        int kind = getDiagram().getDiagramKind();
261
        if (kind != IDiagramKind.DK_COLLABORATION_DIAGRAM &&
241
        if (kind != IDiagramKind.DK_COLLABORATION_DIAGRAM
262
            kind != IDiagramKind.DK_COMPONENT_DIAGRAM &&
242
                && kind != IDiagramKind.DK_COMPONENT_DIAGRAM
263
            kind != IDiagramKind.DK_DEPLOYMENT_DIAGRAM )
243
                && kind != IDiagramKind.DK_DEPLOYMENT_DIAGRAM) {
264
            return super.getPreferredAction();
244
            return super.getPreferredAction();
265
        else
245
        } else {
266
            return null;
246
            return null;
247
        }
267
    }
248
    }
268
    
249
269
    
270
    @Override
250
    @Override
271
    public Action[] getActions(boolean context)
251
    public Action[] getActions(boolean context) {
272
    {
252
        ArrayList<Action> actions = new ArrayList<Action>();
273
        ArrayList<Action> actions = new ArrayList <Action>();
253
274
        
275
        int kind = getDiagram().getDiagramKind();
254
        int kind = getDiagram().getDiagramKind();
276
        // temporarily take out open action from those three diagram types for 6.5 M1
255
        // temporarily take out open action from those three diagram types for 6.5 M1
277
        if (kind != IDiagramKind.DK_COLLABORATION_DIAGRAM &&
256
        if (kind != IDiagramKind.DK_COLLABORATION_DIAGRAM
278
            kind != IDiagramKind.DK_COMPONENT_DIAGRAM &&
257
                && kind != IDiagramKind.DK_COMPONENT_DIAGRAM
279
            kind != IDiagramKind.DK_DEPLOYMENT_DIAGRAM )
258
                && kind != IDiagramKind.DK_DEPLOYMENT_DIAGRAM) {
280
        {
281
            actions.add(SystemAction.get(OpenAction.class));
259
            actions.add(SystemAction.get(OpenAction.class));
282
            actions.add(null);
260
            actions.add(null);
283
        }
261
        }
284
        
262
285
        // see #102294
263
        // see #102294
286
        if ( kind != IDiagramKind.DK_SEQUENCE_DIAGRAM &&
264
        if (kind != IDiagramKind.DK_SEQUENCE_DIAGRAM
287
                kind != IDiagramKind.DK_COLLABORATION_DIAGRAM && !isOldDiagramFormat())
265
                && kind != IDiagramKind.DK_COLLABORATION_DIAGRAM && !isOldDiagramFormat()) {
288
        {
289
            actions.add(SystemAction.get(CopyDiagramAction.class));
266
            actions.add(SystemAction.get(CopyDiagramAction.class));
290
        }
267
        }
291
        actions.add(SystemAction.get(RenameAction.class));
268
        actions.add(SystemAction.get(RenameAction.class));
Lines 299-318 Link Here
299
        actions.toArray(retVal);
276
        actions.toArray(retVal);
300
        return retVal;
277
        return retVal;
301
    }
278
    }
302
      
279
303
    //**************************************************
280
    //**************************************************
304
    // Helper Methods
281
    // Helper Methods
305
    //**************************************************
282
    //**************************************************
306
    
307
    /**
283
    /**
308
     * @param string
284
     * @param string
309
     */
285
     */
310
    protected void setFilename(String value)
286
    protected void setFilename(String value) {
311
    {
312
        IProjectTreeItem data = getData();
287
        IProjectTreeItem data = getData();
313
        
288
314
        if (data != null)
289
        if (data != null) {
315
        {
316
//            String filename = StringUtilities
290
//            String filename = StringUtilities
317
//                    .ensureExtension(value, FileExtensions.DIAGRAM_LAYOUT_EXT);
291
//                    .ensureExtension(value, FileExtensions.DIAGRAM_LAYOUT_EXT);
318
//            
292
//            
Lines 323-407 Link Here
323
            data.setDescription(value);
297
            data.setDescription(value);
324
        }
298
        }
325
    }
299
    }
326
    
300
327
    @Override
301
    @Override
328
    public boolean equals(Object obj)
302
    public boolean equals(Object obj) {
329
    {
330
        boolean retVal = false;
303
        boolean retVal = false;
331
        
304
332
        if ( (obj != null) && (this.hashCode() == obj.hashCode()))
305
        if ((obj != null) && (this.hashCode() == obj.hashCode())) {
333
            return true;
306
            return true;
334
        
307
        }
335
        if (obj instanceof ITreeDiagram)
308
336
        {
309
        if (obj instanceof ITreeDiagram) {
337
            ITreeDiagram diagram = (ITreeDiagram)obj;
310
            ITreeDiagram diagram = (ITreeDiagram) obj;
338
            
311
339
            String testDescription = diagram.getData().getDescription();
312
            String testDescription = diagram.getData().getDescription();
340
            String myDescription   = getData().getDescription();
313
            String myDescription = getData().getDescription();
341
            
314
342
            retVal = myDescription.equals(testDescription);
315
            retVal = myDescription.equals(testDescription);
343
        }
316
        } else if (obj instanceof String) {
344
        
317
            String myDescription = getData().getDescription();
345
        else if (obj instanceof String)
318
            retVal = myDescription.equals((String) obj);
346
        {
319
        } // TODO: meteora
347
            String myDescription   = getData().getDescription();
320
        //        else if (obj instanceof IDrawingAreaControl)
348
            retVal = myDescription.equals((String)obj);
321
        //        {
349
        }
322
        //            IDrawingAreaControl control = (IDrawingAreaControl)obj;
350
        // TODO: meteora
323
        //
351
//        else if (obj instanceof IDrawingAreaControl)
324
        //            String testDescription = control.getFilename();
352
//        {
325
        //            String myDescription   = getData().getDescription();
353
//            IDrawingAreaControl control = (IDrawingAreaControl)obj;
326
        //
354
//            
327
        //            retVal = myDescription.equals(testDescription);
355
//            String testDescription = control.getFilename();
328
        //        }
356
//            String myDescription   = getData().getDescription();
329
        else if (obj instanceof IProxyDiagram) {
357
//            
330
            IProxyDiagram control = (IProxyDiagram) obj;
358
//            retVal = myDescription.equals(testDescription);
331
359
//        }
360
        
361
        else if (obj instanceof IProxyDiagram)
362
        {
363
            IProxyDiagram control = (IProxyDiagram)obj;
364
            
365
            String testDescription = control.getFilename();
332
            String testDescription = control.getFilename();
366
            String myDescription   = getData().getDescription();
333
            String myDescription = getData().getDescription();
367
            
334
368
            retVal = myDescription.equals(testDescription);
335
            retVal = myDescription.equals(testDescription);
369
        }
336
        } else if (obj instanceof IDiagram) {
370
        
337
            IDiagram control = (IDiagram) obj;
371
        else if (obj instanceof IDiagram)
338
372
        {
373
            IDiagram control = (IDiagram)obj;
374
            
375
            String testDescription = control.getFilename();
339
            String testDescription = control.getFilename();
376
            String myDescription   = getData().getDescription();
340
            String myDescription = getData().getDescription();
377
            
341
378
            retVal = myDescription.equals(testDescription);
342
            retVal = myDescription.equals(testDescription);
379
        }
343
        } else {
380
        
381
        else
382
        {
383
            retVal = super.equals(obj);
344
            retVal = super.equals(obj);
384
        }
345
        }
385
        
346
386
        return retVal;
347
        return retVal;
387
    }
348
    }
388
    
349
389
    @Override
350
    @Override
390
    public String getType()
351
    public String getType() {
391
    {
392
        return mDiagramType;
352
        return mDiagramType;
393
    }
353
    }
394
    
354
395
    
355
    public void setName(String newName) {
396
    
356
        if (!Util.isDiagramNameValid(newName)) {
397
    public void setName(String newName)
398
    {
399
        if (!Util.isDiagramNameValid(newName))
400
        {
401
            NotifyDescriptor.Message msg =
357
            NotifyDescriptor.Message msg =
402
                    new NotifyDescriptor.Message(NbBundle.getMessage(
358
                    new NotifyDescriptor.Message(NbBundle.getMessage(
403
                                                 AddPackageVisualPanel1.class,
359
                    AddPackageVisualPanel1.class,
404
                                                 "MSG_Invalid_Diagram_Name", newName)); // NOI18N
360
                    "MSG_Invalid_Diagram_Name", newName)); // NOI18N
405
            DialogDisplayer.getDefault().notify(msg);
361
            DialogDisplayer.getDefault().notify(msg);
406
            return;
362
            return;
407
        }
363
        }
Lines 410-489 Link Here
410
        IDiagram diagram = null;
366
        IDiagram diagram = null;
411
        String diagramName = null;
367
        String diagramName = null;
412
        boolean proceed = true;
368
        boolean proceed = true;
413
        
369
414
        if (proxyDiagram != null )
370
        if (proxyDiagram != null) {
415
        {
371
            if (nodeName.equals("")) // this's the case when a diagram is first open
416
            if (nodeName.equals(""))  // this's the case when a diagram is first open
372
            {
417
            {   
373
                setNodeName(nodeName, newName);
418
                setNodeName (nodeName, newName);
419
                return;
374
                return;
420
            }
375
            }
421
            diagramName = proxyDiagram.getName();  // get the diagram's name
376
            diagramName = proxyDiagram.getName();  // get the diagram's name
422
            if ( proxyDiagram.isOpen())
377
            if (proxyDiagram.isOpen()) {
423
            {
424
                diagram = proxyDiagram.getDiagram();  // get UIDiagram object
378
                diagram = proxyDiagram.getDiagram();  // get UIDiagram object
425
                boolean dirty =  diagram.isDirty();
379
                boolean dirty = diagram.isDirty();
426
                
380
427
                // take care the diagram name first
381
                // take care the diagram name first
428
                if (!newName.equals(diagramName)) // diagram name not equals to new name
382
                if (!newName.equals(diagramName)) // diagram name not equals to new name
429
                {
383
                {
430
                    if ( dirty )   // ask users if they want to save diagram before changing name
384
                    if (dirty) // ask users if they want to save diagram before changing name
431
                    {
385
                    {
432
                         proceed = (askToSaveDiagram(diagramName) == UMLDiagramNode.RESULT_YES);
386
                        proceed = (askToSaveDiagram(diagramName) == UMLDiagramNode.RESULT_YES);
433
                    }
387
                    }
434
                    
388
435
                    proceed = (!dirty || proceed);
389
                    proceed = (!dirty || proceed);
436
                    
390
437
                    if (proceed) // go ahead changing the diagram name and save the diagram
391
                    if (proceed) // go ahead changing the diagram name and save the diagram
438
                    {
392
                    {
439
                        try
393
                        try {   // change diagram name and diagram tab name
440
                        {   // change diagram name and diagram tab name
441
                            proxyDiagram.setName(newName);
394
                            proxyDiagram.setName(newName);
442
                            if (ProductHelper.getShowAliasedNames())
395
                            if (ProductHelper.getShowAliasedNames()) {
443
                            {
444
                                proxyDiagram.setAlias(newName);
396
                                proxyDiagram.setAlias(newName);
445
                            }
397
                            }
446
                            diagram.save(); // autosave diagram after rename
398
                            diagram.save(); // autosave diagram after rename
447
                        }
399
                        } catch (IOException ex) {
448
                        catch (IOException ex)
449
                        {
450
                            Exceptions.printStackTrace(ex);
400
                            Exceptions.printStackTrace(ex);
451
                        }
401
                        }
452
                     }
402
                    }
453
                }
403
                }
454
                
404
455
                // take care the diagram node on project tree
405
                // take care the diagram node on project tree
456
                if (!getName().equals(newName) &&  proceed)  
406
                if (!getName().equals(newName) && proceed) {
457
                {
407
                    setNodeName(diagramName, newName);
458
                    setNodeName (diagramName, newName);
459
                }
408
                }
460
            }
409
            } else // Diagram is not open
461
            else // Diagram is not open
462
            {
410
            {
463
                // TODO: update the diagram name from diagram file using file IO.
411
                // TODO: update the diagram name from diagram file using file IO.
464
                // Since the diagram is not open, no need to check for diagram dirty state.
412
                // Since the diagram is not open, no need to check for diagram dirty state.
465
                proxyDiagram.setName(newName);
413
                proxyDiagram.setName(newName);
466
                setNodeName (nodeName, newName);
414
                setNodeName(nodeName, newName);
467
            }
415
            }
468
        }
416
        }
469
    }
417
    }
470
    
418
471
    private void setNodeName (String oldName, String newName)
419
    private void setNodeName(String oldName, String newName) {
472
    {
473
        // change diagram node name
420
        // change diagram node name
474
        super.setName(newName); 
421
        super.setName(newName);
475
        super.setDisplayName(newName);
422
        super.setDisplayName(newName);
476
        getData().setItemText(newName);
423
        getData().setItemText(newName);
477
        fireNameChange(oldName, newName);
424
        fireNameChange(oldName, newName);
478
        fireDisplayNameChange(oldName, newName);
425
        fireDisplayNameChange(oldName, newName);
479
        firePropertySetsChange(null, retreiveProperties());
426
        firePropertySetsChange(null, retreiveProperties());
480
    }
427
    }
481
    
482
    
483
//    public void setDisplayName(String val)
428
//    public void setDisplayName(String val)
484
//    {
429
//    {
485
//        setName(val);
430
//        setName(val);
486
        
487
//        IProjectTreeItem item = getData(); 
431
//        IProjectTreeItem item = getData(); 
488
//        if (item != null)
432
//        if (item != null)
489
//        {
433
//        {
Lines 530-566 Link Here
530
//            } 
474
//            } 
531
//        }
475
//        }
532
//    }
476
//    }
533
    
534
    private static final int RESULT_CANCEL = 0;
477
    private static final int RESULT_CANCEL = 0;
535
    private static final int RESULT_YES = 1;
478
    private static final int RESULT_YES = 1;
536
    
479
537
    private int askToSaveDiagram(String diagramName)
480
    private int askToSaveDiagram(String diagramName) {
538
    {
539
        String title = NbBundle.getMessage(UMLDiagramNode.class,
481
        String title = NbBundle.getMessage(UMLDiagramNode.class,
540
                "LBL_DIALOG_TITLE_SaveDiagram"); // NOI18N
482
                "LBL_DIALOG_TITLE_SaveDiagram"); // NOI18N
541
        
483
542
        String message = NbBundle.getMessage(
484
        String message = NbBundle.getMessage(
543
                UMLDiagramNode.class,
485
                UMLDiagramNode.class,
544
                "LBL_DIALOG_MSG_RenamePreSaveDiagram", // NOI18N
486
                "LBL_DIALOG_MSG_RenamePreSaveDiagram", // NOI18N
545
                diagramName); 
487
                diagramName);
546
        
488
547
        int result = RESULT_CANCEL;
489
        int result = RESULT_CANCEL;
548
        
490
549
        Object response = SaveNotifierYesNo.getDefault().displayNotifier(
491
        Object response = SaveNotifierYesNo.getDefault().displayNotifier(
550
                title, message, SaveNotifierYesNo.SAVE_CANCEL);
492
                title, message, SaveNotifierYesNo.SAVE_CANCEL);
551
        
493
552
        if (response == NotifyDescriptor.YES_OPTION)
494
        if (response == NotifyDescriptor.YES_OPTION) {
553
        {
554
            result = RESULT_YES;
495
            result = RESULT_YES;
555
        }
496
        } else // cancel or closed (x button)
556
        else // cancel or closed (x button)
557
        {
497
        {
558
            result = RESULT_CANCEL;
498
            result = RESULT_CANCEL;
559
        }
499
        }
560
        
500
561
        return result;
501
        return result;
562
    }
502
    }
563
    
503
564
//    public String getDisplayName()
504
//    public String getDisplayName()
565
//    {
505
//    {
566
//        String retVal = ""; // NOI18N
506
//        String retVal = ""; // NOI18N
Lines 579-604 Link Here
579
//        
519
//        
580
//        return retVal;
520
//        return retVal;
581
//    }
521
//    }
582
    
522
    public String getElementType() {
583
    
584
    public String getElementType()
585
    {
586
        String retVal = ""; // NOI18N
523
        String retVal = ""; // NOI18N
587
        IProjectTreeItem item = getData();
524
        IProjectTreeItem item = getData();
588
        
525
589
        if (item != null)
526
        if (item != null) {
590
        {
591
            IProxyDiagram dia = item.getDiagram();
527
            IProxyDiagram dia = item.getDiagram();
592
            if (dia != null)
528
            if (dia != null) {
593
            {
594
                IDiagram openDia = dia.getDiagram();
529
                IDiagram openDia = dia.getDiagram();
595
                if (openDia != null)
530
                if (openDia != null) {
596
                {
597
                    retVal = ELEMENT_TYPE_DIAGRAM;
531
                    retVal = ELEMENT_TYPE_DIAGRAM;
598
                }
532
                } else {
599
                
600
                else
601
                {
602
                    //its an unopen diagram
533
                    //its an unopen diagram
603
                    retVal = ELEMENT_TYPE_PROXY_DIAGRAM;
534
                    retVal = ELEMENT_TYPE_PROXY_DIAGRAM;
604
                }
535
                }
Lines 606-660 Link Here
606
        }
537
        }
607
        return retVal;
538
        return retVal;
608
    }
539
    }
609
    
540
610
    public IElement getModelElement()
541
    public IElement getModelElement() {
611
    {
612
        IElement retVal = null;
542
        IElement retVal = null;
613
        
543
614
        IProjectTreeItem item = getData();
544
        IProjectTreeItem item = getData();
615
        if (item != null)
545
        if (item != null) {
616
        {
617
            IProxyDiagram dia = item.getDiagram();
546
            IProxyDiagram dia = item.getDiagram();
618
            if (dia != null)
547
            if (dia != null) {
619
            {
620
                //its an unopen diagram
548
                //its an unopen diagram
621
                retVal = dia.getDiagram();
549
                retVal = dia.getDiagram();
622
            }
550
            }
623
        }
551
        }
624
        
552
625
        return retVal;
553
        return retVal;
626
    }
554
    }
627
    
555
628
    /**
556
    /**
629
     * Builds the proerty set structure.
557
     * Builds the proerty set structure.
630
     */
558
     */
631
    protected Node.PropertySet[] buildProperties()
559
    protected Node.PropertySet[] buildProperties() {
632
    {
633
        Node.PropertySet[] retVal = null;
560
        Node.PropertySet[] retVal = null;
634
        
561
635
        IElement element = getModelElement();
562
        IElement element = getModelElement();
636
        
563
637
        DefinitionPropertyBuilder builder = DefinitionPropertyBuilder.instance();
564
        DefinitionPropertyBuilder builder = DefinitionPropertyBuilder.instance();
638
        if (element != null)
565
        if (element != null) {
639
        {
640
            // In this case we actually have a IDiagram Instance.
566
            // In this case we actually have a IDiagram Instance.
641
            retVal = builder.retreiveProperties(element.getElementType(), element);
567
            retVal = builder.retreiveProperties(element.getElementType(), element);
642
        }
568
        } else {
643
        
644
        else
645
        {
646
            // In this case we only have a IProxyDiagram instance.
569
            // In this case we only have a IProxyDiagram instance.
647
            IProjectTreeItem item = getData();
570
            IProjectTreeItem item = getData();
648
            if (item != null)
571
            if (item != null) {
649
            {
650
                IProxyDiagram proxy = item.getDiagram();
572
                IProxyDiagram proxy = item.getDiagram();
651
                retVal = builder.retreiveProperties(getElementType(), proxy);
573
                retVal = builder.retreiveProperties(getElementType(), proxy);
652
            }
574
            }
653
        }
575
        }
654
        
576
655
        return retVal;
577
        return retVal;
656
    }
578
    }
657
    
579
658
    // The node should not be listening to drawing area events.  It is up to the
580
    // The node should not be listening to drawing area events.  It is up to the
659
    // project tree engine to respond to the events.
581
    // project tree engine to respond to the events.
660
//    public void onDrawingAreaTooltipPreDisplay(
582
//    public void onDrawingAreaTooltipPreDisplay(
Lines 754-767 Link Here
754
//    public void onDrawingAreaActivated(
676
//    public void onDrawingAreaActivated(
755
//            IDiagram pParentDiagram, IResultCell cell)
677
//            IDiagram pParentDiagram, IResultCell cell)
756
//    {}
678
//    {}
757
    
679
    protected boolean save(IDiagram diag, boolean confirm) {
758
    
759
    protected boolean save(IDiagram diag, boolean confirm)
760
    {
761
        return save(diag, confirm, null);
680
        return save(diag, confirm, null);
762
    }
681
    }
763
    
682
764
    
765
    // Thuy rewrites the mehod
683
    // Thuy rewrites the mehod
766
//    protected boolean save(IDiagram diag, boolean confirm, String dialogMsg)
684
//    protected boolean save(IDiagram diag, boolean confirm, String dialogMsg)
767
//    {
685
//    {
Lines 795-898 Link Here
795
//        
713
//        
796
//        return false;
714
//        return false;
797
//    }
715
//    }
798
        
716
    protected boolean save(IDiagram diag, boolean confirm, String dialogMsg) {
799
    protected boolean save(IDiagram diag, boolean confirm, String dialogMsg)
800
    {
801
        //prompt to save..
717
        //prompt to save..
802
        boolean isSaved = false;
718
        boolean isSaved = false;
803
        //IProxyDiagram pDiagram = getDiagram(); 
719
        //IProxyDiagram pDiagram = getDiagram(); 
804
        if ( diag != null && diag.isDirty() && 
720
        if (diag != null && diag.isDirty()
805
                dialogMsg != null && dialogMsg.trim().length() > 0 ) 
721
                && dialogMsg != null && dialogMsg.trim().length() > 0) {
806
        {
807
            //String name = pDiagram.getName();
722
            //String name = pDiagram.getName();
808
            boolean confirmSaveFromDialog = userConfirmedSave("", dialogMsg);
723
            boolean confirmSaveFromDialog = userConfirmedSave("", dialogMsg);
809
        
724
810
            if (!confirm || confirmSaveFromDialog)
725
            if (!confirm || confirmSaveFromDialog) {
811
            {
726
                try {
812
                try
813
                {
814
                    diag.save();
727
                    diag.save();
815
                    isSaved = true;
728
                    isSaved = true;
816
                } 
729
                } catch (IOException e) {
817
                catch (IOException e)
818
                {
819
                    Exceptions.printStackTrace(e);
730
                    Exceptions.printStackTrace(e);
820
                }
731
                }
821
            }
732
            }
822
        }
733
        }
823
        return isSaved;
734
        return isSaved;
824
    }
735
    }
825
    
826
    
827
    private static boolean alwaysSaveProject = false;
736
    private static boolean alwaysSaveProject = false;
828
    
737
829
    private boolean userConfirmedSave(String name, String dialogMsg)
738
    private boolean userConfirmedSave(String name, String dialogMsg) {
830
    {
831
        //Kris Richards - this preference is now always "PSK_YES"
739
        //Kris Richards - this preference is now always "PSK_YES"
832
740
833
        
741
834
        String title = NbBundle.getMessage(UMLDiagramNode.class,
742
        String title = NbBundle.getMessage(UMLDiagramNode.class,
835
                "LBL_DIALOG_TITLE_SaveDiagram"); // NOI18N
743
                "LBL_DIALOG_TITLE_SaveDiagram"); // NOI18N
836
        
744
837
        if (dialogMsg == null || dialogMsg.equals("")) // NOI18N
745
        if (dialogMsg == null || dialogMsg.equals("")) // NOI18N
838
        {
746
        {
839
            dialogMsg = NbBundle.getMessage(
747
            dialogMsg = NbBundle.getMessage(
840
                UMLDiagramNode.class,
748
                    UMLDiagramNode.class,
841
                "LBL_DIALOG_MSG_RenamePreSaveDiagram",  // NOI18N
749
                    "LBL_DIALOG_MSG_RenamePreSaveDiagram", // NOI18N
842
                getDiagram().getDiagram().getName());
750
                    getDiagram().getDiagram().getName());
843
        }
751
        }
844
        
752
845
        boolean success = false;
753
        boolean success = false;
846
        
754
847
        // prompt user to save the target UML diagram
755
        // prompt user to save the target UML diagram
848
        
756
849
        Object result = SaveNotifierOkCancel.getDefault()
757
        Object result = SaveNotifierOkCancel.getDefault().displayNotifier(title, dialogMsg);
850
            .displayNotifier(title, dialogMsg);
758
851
        
759
        if (result == NotifyDescriptor.OK_OPTION) {
852
        if (result == NotifyDescriptor.OK_OPTION)
853
            success = true;
760
            success = true;
854
        
761
        } else // cancel or closed (x button)
855
        else // cancel or closed (x button)
856
        {
762
        {
857
            success = false;
763
            success = false;
858
            bCancelSaveDialog = true;
764
            bCancelSaveDialog = true;
859
        }
765
        }
860
        
766
861
        return success;
767
        return success;
862
    }
768
    }
863
    private boolean isOldDiagramFormat()
769
864
    {
770
    private boolean isOldDiagramFormat() {
865
        boolean ret=mDiagram.getFilename().endsWith("."+ETLD_EXTENSION);
771
        boolean ret = mDiagram.getFilename().endsWith("." + ETLD_EXTENSION);
866
        return ret;
772
        return ret;
867
    }
773
    }
868
774
869
    
775
    public class DiagramCookie implements Cookie {
870
    public class DiagramCookie implements Cookie
776
871
    { 
777
        public IProxyDiagram getDiagram() {
872
        public IProxyDiagram getDiagram()
873
        {
874
            return UMLDiagramNode.this.getDiagram();
778
            return UMLDiagramNode.this.getDiagram();
875
        }
779
        }
876
    }
780
    }
877
    
781
878
    
782
    public class DiagramPrintCookie implements PrintCookie {
879
    public class DiagramPrintCookie implements PrintCookie
783
880
    {
784
        public void print() {
881
        
882
        public void print()
883
        {
884
            IProjectTreeItem item = getData();
785
            IProjectTreeItem item = getData();
885
            IProductDiagramManager pDiaMgr =
786
            IProductDiagramManager pDiaMgr =
886
                    ProductHelper.getProductDiagramManager();
787
                    ProductHelper.getProductDiagramManager();
887
            
788
888
            if (item != null && pDiaMgr != null)
789
            if (item != null && pDiaMgr != null) {
889
            {
890
                IProxyDiagram proxyDia = item.getDiagram();
790
                IProxyDiagram proxyDia = item.getDiagram();
891
                if (proxyDia != null)
791
                if (proxyDia != null) {
892
                {
893
                    IDiagram diagram = proxyDia.getDiagram();
792
                    IDiagram diagram = proxyDia.getDiagram();
894
                    if (diagram != null)
793
                    if (diagram != null) {
895
                    {
896
                        //TODO: Does the diagram need to really know about printgraph? It should be handled by TopComp?
794
                        //TODO: Does the diagram need to really know about printgraph? It should be handled by TopComp?
897
//                        diagram.printGraph(true);
795
//                        diagram.printGraph(true);
898
                    }
796
                    }
Lines 900-921 Link Here
900
            }
798
            }
901
        }
799
        }
902
    }
800
    }
903
    
801
904
    public boolean isListenersRegistered()
802
    public boolean isListenersRegistered() {
905
    {
906
        return listenersRegistered;
803
        return listenersRegistered;
907
    }
804
    }
908
    
805
909
    public void setListenersRegistered(boolean listenersRegistered)
806
    public void setListenersRegistered(boolean listenersRegistered) {
910
    {
911
        this.listenersRegistered = listenersRegistered;
807
        this.listenersRegistered = listenersRegistered;
912
    }
808
    }
913
    
809
914
    public DispatchHelper getDispatchHelper()
810
    public DispatchHelper getDispatchHelper() {
915
    {
811
        if (dispatchHelper == null) {
916
        if (dispatchHelper == null)
917
            dispatchHelper = new DispatchHelper();
812
            dispatchHelper = new DispatchHelper();
918
        
813
        }
814
919
        return dispatchHelper;
815
        return dispatchHelper;
920
    }
816
    }
921
}
817
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLDiagramsRootNode.java (-175 / +120 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
46
45
47
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
46
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
Lines 74-103 Link Here
74
import org.openide.util.datatransfer.NewType;
73
import org.openide.util.datatransfer.NewType;
75
import org.openide.util.datatransfer.PasteType;
74
import org.openide.util.datatransfer.PasteType;
76
75
77
78
79
/**
76
/**
80
 * UMLDiagramsRootNode displays the UML diagrams
77
 * UMLDiagramsRootNode displays the UML diagrams
81
 * @author Mike Frisino
78
 * @author Mike Frisino
82
 */
79
 */
83
// TODO: meteora
80
// TODO: meteora
84
public final class UMLDiagramsRootNode extends UMLModelElementNode
81
public final class UMLDiagramsRootNode extends UMLModelElementNode
85
    implements IDrawingAreaEventsSink
82
        implements IDrawingAreaEventsSink {
86
{
83
87
    
88
    private static final String ICON =
84
    private static final String ICON =
89
        ImageUtil.IMAGE_FOLDER + "diagrams-root-node.png"; //NOI18N
85
            ImageUtil.IMAGE_FOLDER + "diagrams-root-node.png"; //NOI18N
90
    
91
    static final RequestProcessor rp = new RequestProcessor();
86
    static final RequestProcessor rp = new RequestProcessor();
92
    private static Icon folderIconCache;
87
    private static Icon folderIconCache;
93
    private static Icon openedFolderIconCache;
88
    private static Icon openedFolderIconCache;
94
    
95
    private final String displayName;
89
    private final String displayName;
96
    private UMLProjectHelper helper = null;
90
    private UMLProjectHelper helper = null;
97
    
91
98
    /**
92
    /**
99
     * Creates new LibrariesNode named displayName displaying classPathProperty classpath
93
     * Creates new LibrariesNode named displayName displaying classPathProperty classpath
100
     * and optionaly Java platform.
94
     * and optionally Java platform.
101
     * @param displayName the display name of the node
95
     * @param displayName the display name of the node
102
     * @param eval {@link PropertyEvaluator} used for listening
96
     * @param eval {@link PropertyEvaluator} used for listening
103
     * @param helper {@link UpdateHelper} used for reading and updating project's metadata
97
     * @param helper {@link UpdateHelper} used for reading and updating project's metadata
Lines 109-185 Link Here
109
     * if the platform should not be displayed
103
     * if the platform should not be displayed
110
     * @param diagramsNodeActions actions which should be available on the created node.
104
     * @param diagramsNodeActions actions which should be available on the created node.
111
     */
105
     */
112
    UMLDiagramsRootNode( UMLProject project, UMLProjectHelper helper,
106
    UMLDiagramsRootNode(UMLProject project, UMLProjectHelper helper,
113
        PropertyEvaluator eval)
107
            PropertyEvaluator eval) {
114
        
108
        super(new DiagramsChildren(eval, helper), Lookups.singleton(project));
115
    {
109
        ((DiagramsChildren) this.getChildren()).setNode(this);
116
        super(new DiagramsChildren( eval, helper), Lookups.singleton(project));
110
117
        ((DiagramsChildren)this.getChildren()).setNode(this);
118
        
119
        this.setIconBaseWithExtension(ICON);
111
        this.setIconBaseWithExtension(ICON);
120
        setElement(helper.getProject());
112
        setElement(helper.getProject());
121
        
113
122
        this.helper = helper;
114
        this.helper = helper;
123
        
115
124
        this.displayName = NbBundle.getMessage(
116
        this.displayName = NbBundle.getMessage(
125
            UMLModelRootNode.class, "CTL_UMLDiagramsRootNode"); //NOI18N
117
                UMLModelRootNode.class, "CTL_UMLDiagramsRootNode"); //NOI18N
126
        
118
127
        DispatchHelper dispatcher = new DispatchHelper();
119
        DispatchHelper dispatcher = new DispatchHelper();
128
        dispatcher.registerDrawingAreaEvents(this);
120
        dispatcher.registerDrawingAreaEvents(this);
129
        
121
130
        // this.displayName = "DiagramsRootNode-Trey";
122
        // this.displayName = "DiagramsRootNode-Trey";
131
        // setName( ProjectUtils.getInformation( project ).getDisplayName() );
123
        // setName( ProjectUtils.getInformation( project ).getDisplayName() );
132
    }
124
    }
133
    
125
134
    /**
126
    /**
135
     * Adds the model element to the lookup.
127
     * Adds the model element to the lookup.
136
     *
128
     *
137
     * @param element The Model element that represents the project.
129
     * @param element The Model element that represents the project.
138
     */
130
     */
139
    protected void addElementCookie(IElement element)
131
    protected void addElementCookie(IElement element) {
140
    {
141
    }
132
    }
142
  
133
143
    
134
    public String getDisplayName() {
144
    public String getDisplayName()
145
    {
146
        return this.displayName;
135
        return this.displayName;
147
    }
136
    }
148
    
137
149
    public String getName()
138
    public String getName() {
150
    {
151
        return this.getDisplayName();
139
        return this.getDisplayName();
152
    }
140
    }
153
    
154
    	/**
155
	 * Get the new types that can be created in this node. For example, a node
156
	 * representing a class will permit attributes, operations, classes,
157
	 * interfaces, and enumerations to be added.
158
	 *
159
	 * @return An array of new type operations that are allowed.
160
	 */
161
    public NewType[] getNewTypes()
162
    {
163
		String elType = getElementType();
164
		NewType[] retVal = null;
165
141
166
		return new NewType[]
142
    /**
167
		{
143
     * Get the new types that can be created in this node. For example, a node
168
			new NewDiagramType(getModelElement()),
144
     * representing a class will permit attributes, operations, classes,
145
     * interfaces, and enumerations to be added.
146
     *
147
     * @return An array of new type operations that are allowed.
148
     */
149
    public NewType[] getNewTypes() {
150
        String elType = getElementType();
151
        NewType[] retVal = null;
169
152
170
		};
153
        return new NewType[]{
154
                    new NewDiagramType(getModelElement()),};
171
    }
155
    }
172
156
173
    public Action[] getActions( boolean context )
157
    public Action[] getActions(boolean context) {
174
    {
158
        return super.getNewMenuAction();
175
       return super.getNewMenuAction();
176
//       return new Action[]
159
//       return new Action[]
177
//       {
160
//       {
178
//          SystemAction.get(NewAction.class),
161
//          SystemAction.get(NewAction.class),
179
//       };
162
//       };
180
    }
163
    }
181
164
182
    
183
    /**
165
    /**
184
     * Retrieves the associated model element.  The model element will be the
166
     * Retrieves the associated model element.  The model element will be the
185
     * IProject that represent the project.
167
     * IProject that represent the project.
Lines 187-366 Link Here
187
     * @return The IProject instance.
169
     * @return The IProject instance.
188
     * @see IProject
170
     * @see IProject
189
     */
171
     */
190
    public IElement getModelElement()
172
    public IElement getModelElement() {
191
    {
192
        return helper.getProject();
173
        return helper.getProject();
193
    }
174
    }
194
    
175
195
    public boolean canCopy()
176
    public boolean canCopy() {
196
    {
197
        return false;
177
        return false;
198
    }
178
    }
199
    
179
200
    public boolean canCut()
180
    public boolean canCut() {
201
    {
202
        return false;
181
        return false;
203
    }
182
    }
204
    
183
205
    public boolean canDestroy()
184
    public boolean canDestroy() {
206
    {
207
        return false;
185
        return false;
208
    }
186
    }
209
    
187
210
    public boolean canRename()
188
    public boolean canRename() {
211
    {
212
        return false;
189
        return false;
213
    }
190
    }
214
    
191
215
    /**
192
    /**
216
     * Check if the specified node is the same UMLDiagramsRootNode
193
     * Check if the specified node is the same UMLDiagramsRootNode
217
     * instance.
194
     * instance.
218
     */
195
     */
219
    public boolean equals(Object obj)
196
    public boolean equals(Object obj) {
220
    {
221
        boolean retVal = false;
197
        boolean retVal = false;
222
        
198
223
        // First check if the object is a UMLDiagramNode.  If we
199
        // First check if the object is a UMLDiagramNode.  If we
224
        // did not make this check then the model node would look
200
        // did not make this check then the model node would look
225
        // like the same node.
201
        // like the same node.
226
        if(obj instanceof UMLDiagramsRootNode)
202
        if (obj instanceof UMLDiagramsRootNode) {
227
        {
228
            retVal = super.equals(obj);
203
            retVal = super.equals(obj);
229
        }
204
        }
230
        
205
231
        return retVal;
206
        return retVal;
232
    }
207
    }
233
    
208
234
    private static class DiagramsChildren extends UMLChildren
209
    private static class DiagramsChildren extends UMLChildren {
235
    {
210
236
        private UMLDiagramsRootNode node = null;
211
        private UMLDiagramsRootNode node = null;
237
        private final PropertyEvaluator eval;
212
        private final PropertyEvaluator eval;
238
        private final UMLProjectHelper helper;
213
        private final UMLProjectHelper helper;
239
        
214
240
        DiagramsChildren(PropertyEvaluator eval, UMLProjectHelper helper)
215
        DiagramsChildren(PropertyEvaluator eval, UMLProjectHelper helper) {
241
        {
242
            this.eval = eval;
216
            this.eval = eval;
243
            this.helper = helper;
217
            this.helper = helper;
244
        }
218
        }
245
        
219
246
        public Node findChild(String name)
220
        public Node findChild(String name) {
247
        {
248
            Node[] list = getNodes();
221
            Node[] list = getNodes();
249
            
222
250
            if(list.length == 0)
223
            if (list.length == 0) {
251
            {
252
                return null;
224
                return null;
253
            }
225
            }
254
            
226
255
            if(name == null)
227
            if (name == null) {
256
            {
257
                // return any node
228
                // return any node
258
                return list[0];
229
                return list[0];
259
            }
230
            }
260
            
231
261
            
232
262
            for(int i = 0; i < list.length; i++)
233
            for (int i = 0; i < list.length; i++) {
263
            {
234
                if (list[i] instanceof ITreeDiagram) {
264
                if(list[i] instanceof ITreeDiagram)
235
                    ITreeDiagram diagram = (ITreeDiagram) list[i];
265
                {
266
                    ITreeDiagram diagram = (ITreeDiagram)list[i];
267
                    IProxyDiagram proxy = diagram.getDiagram();
236
                    IProxyDiagram proxy = diagram.getDiagram();
268
                    if (name.equals(proxy.getFilename()))
237
                    if (name.equals(proxy.getFilename())) {
269
                    {
270
                        // ok, we have found it
238
                        // ok, we have found it
271
                        return list[i];
239
                        return list[i];
272
                    }
240
                    }
273
                }
241
                }
274
            }
242
            }
275
            return null;
243
            return null;
276
            
244
277
        }
245
        }
278
        
246
279
        /**
247
        /**
280
         * Notify listeners that a node is being expanded.  Listeners are able to add
248
         * Notify listeners that a node is being expanded.  Listeners are able to add
281
         * nodes to the ProjectTreeItem.
249
         * nodes to the ProjectTreeItem.
282
         */
250
         */
283
        protected void sendNodeExpandEvent()
251
        protected void sendNodeExpandEvent() {
284
        {
285
            NetBeansUMLProjectTreeModel model = UMLModelRootNode.getProjectTreeModel();
252
            NetBeansUMLProjectTreeModel model = UMLModelRootNode.getProjectTreeModel();
286
            
253
287
            // Debug.out.println("Firing node expand event");
254
            // Debug.out.println("Firing node expand event");
288
            if(model != null)
255
            if (model != null) {
289
            {
290
                model.fireDiagramsExpanding(node, helper.getProject());
256
                model.fireDiagramsExpanding(node, helper.getProject());
291
                
257
292
            }
258
            }
293
        }
259
        }
294
        
260
295
        public void setNode(UMLDiagramsRootNode node)
261
        public void setNode(UMLDiagramsRootNode node) {
296
        {
297
            this.node = node;
262
            this.node = node;
298
        }
263
        }
299
    }
264
    }
300
    
265
301
    
266
    private static class SimpleFileFilter extends FileFilter {
302
    
267
303
    private static class SimpleFileFilter extends FileFilter
304
    {
305
        private String description;
268
        private String description;
306
        private Collection extensions;
269
        private Collection extensions;
307
        
270
308
        
271
        public SimpleFileFilter(String description, String[] extensions) {
309
        public SimpleFileFilter(String description, String[] extensions)
310
        {
311
            this.description = description;
272
            this.description = description;
312
            this.extensions = Arrays.asList(extensions);
273
            this.extensions = Arrays.asList(extensions);
313
        }
274
        }
314
        
275
315
        public boolean accept(File f)
276
        public boolean accept(File f) {
316
        {
317
            return true; // mcf hack
277
            return true; // mcf hack
318
            /*
278
            /*
319
            if (f.isDirectory())
279
            if (f.isDirectory())
320
                return true;
280
            return true;
321
            try {
281
            try {
322
                return FileUtil.isArchiveFile(f.toURI().toURL());
282
            return FileUtil.isArchiveFile(f.toURI().toURL());
323
            } catch (MalformedURLException mue) {
283
            } catch (MalformedURLException mue) {
324
                ErrorManager.getDefault().notify(mue);
284
            ErrorManager.getDefault().notify(mue);
325
                return false;
285
            return false;
326
            }
286
            }
327
             */
287
             */
328
        }
288
        }
329
        
289
330
        public String getDescription()
290
        public String getDescription() {
331
        {
332
            return this.description;
291
            return this.description;
333
        }
292
        }
334
    }
293
    }
335
    
294
336
    
295
    public void recalculateChildren() {
337
    public void recalculateChildren()
296
        UMLChildren children = (UMLChildren) getChildren();
338
    {
339
        UMLChildren children = (UMLChildren)getChildren();
340
        children.recalculateChildren();
297
        children.recalculateChildren();
341
    }
298
    }
342
299
343
    
344
    // implmentations of interface IDrawingAreaEventsSink
300
    // implmentations of interface IDrawingAreaEventsSink
345
    /////////////////////////////////////////////////////
301
    /////////////////////////////////////////////////////
346
    
347
//    public void onDrawingAreaTooltipPreDisplay(
302
//    public void onDrawingAreaTooltipPreDisplay(
348
//        IDiagram pParentDiagram, 
303
//        IDiagram pParentDiagram, 
349
//        IPresentationElement pPE, 
304
//        IPresentationElement pPE, 
350
//        IToolTipData pTooltip, 
305
//        IToolTipData pTooltip, 
351
//        IResultCell cell) 
306
//        IResultCell cell) 
352
//    {}
307
//    {}
353
354
    public void onDrawingAreaPreSave(
308
    public void onDrawingAreaPreSave(
355
        IProxyDiagram pParentDiagram, IResultCell cell)
309
            IProxyDiagram pParentDiagram, IResultCell cell) {
356
    {}
310
    }
357
311
358
    public void onDrawingAreaPrePropertyChange(
312
    public void onDrawingAreaPrePropertyChange(
359
        IProxyDiagram pProxyDiagram, int nPropertyKindChanged, IResultCell cell)
313
            IProxyDiagram pProxyDiagram, int nPropertyKindChanged, IResultCell cell) {
360
    {}
314
    }
361
315
362
    public void onDrawingAreaPreFileRemoved(String sFilename, IResultCell cell)
316
    public void onDrawingAreaPreFileRemoved(String sFilename, IResultCell cell) {
363
    {}
317
    }
364
318
365
//    public void onDrawingAreaPreDrop(
319
//    public void onDrawingAreaPreDrop(
366
//        IDiagram pParentDiagram, 
320
//        IDiagram pParentDiagram, 
Lines 371-384 Link Here
371
//    public void onDrawingAreaPreCreated(
325
//    public void onDrawingAreaPreCreated(
372
//        IDrawingAreaControl pDiagramControl, IResultCell cell)
326
//        IDrawingAreaControl pDiagramControl, IResultCell cell)
373
//    {}
327
//    {}
374
375
    public void onDrawingAreaPostSave(
328
    public void onDrawingAreaPostSave(
376
        IProxyDiagram pParentDiagram, IResultCell cell)
329
            IProxyDiagram pParentDiagram, IResultCell cell) {
377
    {}
330
    }
378
331
379
    public void onDrawingAreaPostPropertyChange(
332
    public void onDrawingAreaPostPropertyChange(
380
        IProxyDiagram pProxyDiagram, int nPropertyKindChanged, IResultCell cell)
333
            IProxyDiagram pProxyDiagram, int nPropertyKindChanged, IResultCell cell) {
381
    {}
334
    }
382
335
383
//    public void onDrawingAreaPostDrop(
336
//    public void onDrawingAreaPostDrop(
384
//        IDiagram pParentDiagram, 
337
//        IDiagram pParentDiagram, 
Lines 386-438 Link Here
386
//        IResultCell cell)
339
//        IResultCell cell)
387
//    {}
340
//    {}
388
//
341
//
389
    public void onDrawingAreaPostCreated(DataObject obj, IResultCell cell)
342
    public void onDrawingAreaPostCreated(DataObject obj, IResultCell cell) {
390
    {}
343
    }
391
344
392
    public void onDrawingAreaOpened(
345
    public void onDrawingAreaOpened(
393
        IDiagram pParentDiagram, IResultCell cell)
346
            IDiagram pParentDiagram, IResultCell cell) {
394
    {}
347
    }
395
348
396
    public void onDrawingAreaKeyDown(
349
    public void onDrawingAreaKeyDown(
397
        IDiagram pParentDiagram, 
350
            IDiagram pParentDiagram,
398
        int nKeyCode, 
351
            int nKeyCode,
399
        boolean bControlIsDown, 
352
            boolean bControlIsDown,
400
        boolean bShiftIsDown, 
353
            boolean bShiftIsDown,
401
        boolean bAltIsDown, IResultCell cell)
354
            boolean bAltIsDown, IResultCell cell) {
402
    {}
355
    }
403
356
404
    
405
    // cvc - CR 6302705
357
    // cvc - CR 6302705
406
    public void onDrawingAreaFileRemoved(String sFilename, IResultCell cell)
358
    public void onDrawingAreaFileRemoved(String sFilename, IResultCell cell) {
407
    {
408
        Enumeration<ITreeItem> nodeKids = getNodeChildren();
359
        Enumeration<ITreeItem> nodeKids = getNodeChildren();
409
360
410
        while (nodeKids.hasMoreElements())
361
        while (nodeKids.hasMoreElements()) //ITreeItem treeItem: nodeKids)
411
            //ITreeItem treeItem: nodeKids)
412
        {
362
        {
413
            ITreeItem treeItem = nodeKids.nextElement();
363
            ITreeItem treeItem = nodeKids.nextElement();
414
364
415
            if (treeItem != null &&
365
            if (treeItem != null
416
                treeItem.getData().getDiagram()
366
                    && treeItem.getData().getDiagram().getFilename().equals(sFilename)) {
417
                .getFilename().equals(sFilename))
418
            {
419
                removeChild(treeItem);
367
                removeChild(treeItem);
420
            }
368
            }
421
        }
369
        }
422
    }
370
    }
423
371
424
    public void onDrawingAreaClosed(
372
    public void onDrawingAreaClosed(
425
        IDiagram pParentDiagram, boolean bDiagramIsDirty, IResultCell cell)
373
            IDiagram pParentDiagram, boolean bDiagramIsDirty, IResultCell cell) {
426
    {}
374
    }
427
375
428
    public void onDrawingAreaActivated(
376
    public void onDrawingAreaActivated(
429
        IDiagram pParentDiagram, IResultCell cell)
377
            IDiagram pParentDiagram, IResultCell cell) {
430
    {}
378
    }
431
    
379
432
    
380
    public PasteType getDropType(Transferable t, int action, int index) {
433
    public PasteType getDropType(Transferable t, int action, int index)
434
    {
435
        return null;
381
        return null;
436
    }
382
    }
437
438
}
383
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLElementNode.java (-817 / +693 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
47
45
48
import org.netbeans.modules.uml.core.metamodel.structure.IProject;
46
import org.netbeans.modules.uml.core.metamodel.structure.IProject;
Lines 67-73 Link Here
67
import org.openide.nodes.CookieSet;
65
import org.openide.nodes.CookieSet;
68
import org.openide.util.ImageUtilities;
66
import org.openide.util.ImageUtilities;
69
import org.openide.util.Lookup;
67
import org.openide.util.Lookup;
70
import org.openide.util.Utilities;
71
import org.openide.util.actions.SystemAction;
68
import org.openide.util.actions.SystemAction;
72
69
73
import org.netbeans.modules.uml.core.eventframework.IEventPayload;
70
import org.netbeans.modules.uml.core.eventframework.IEventPayload;
Lines 90-226 Link Here
90
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeRelElement;
87
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeRelElement;
91
import org.netbeans.modules.uml.ui.support.projecttreesupport.ProjectTreeComparable;
88
import org.netbeans.modules.uml.ui.support.projecttreesupport.ProjectTreeComparable;
92
89
93
94
/**
90
/**
95
 *
91
 *
96
 * @author Trey Spiva
92
 * @author Trey Spiva
97
 */
93
 */
98
public class UMLElementNode extends AbstractModelElementNode
94
public class UMLElementNode extends AbstractModelElementNode
99
	implements ITreeItem, CookieSet.Factory, Comparable
95
        implements ITreeItem, CookieSet.Factory, Comparable {
100
{
96
101
	private IProjectTreeItem m_Data = null;
97
    private IProjectTreeItem m_Data = null;
102
	private String mPathAsString = ""; // NOI18N
98
    private String mPathAsString = ""; // NOI18N
103
	private Node.Cookie mOpenCookie = null;
99
    private Node.Cookie mOpenCookie = null;
104
	private Node.Cookie mModelElementCookie = null;
100
    private Node.Cookie mModelElementCookie = null;
105
	
101
    /** Determines if the node has been initialized with children yet. */
106
	/** Determines if the node has been initialized with children yet. */
102
    private boolean mIsInitialized = false;
107
	private boolean mIsInitialized = false;
103
    //Cache to speed up performance
108
	
104
    private Image icon = null;
109
	//Cache to speed up performance
110
	private Image icon=null;
111
//	private Action[] actions=null;
105
//	private Action[] actions=null;
112
	
106
113
	/**
107
    /**
114
	 * Create a new UMLElementNode
108
     * Create a new UMLElementNode
115
	 */
109
     */
116
	public UMLElementNode()
110
    public UMLElementNode() {
117
	{
111
        this(new ProjectTreeItemImpl());
118
		this(new ProjectTreeItemImpl());
112
        initCookies();
119
		initCookies();
113
    }
120
	}
114
121
	
115
    /**
122
	/**
116
     *
123
	 *
117
     */
124
	 */
118
    public UMLElementNode(Lookup lookup) {
125
	public UMLElementNode(Lookup lookup)
119
        this(lookup, new ProjectTreeItemImpl());
126
	{
120
    }
127
		this(lookup, new ProjectTreeItemImpl());
121
128
	}
122
    /**
129
	
123
     * Create a new UMLElementNode
130
	/**
124
     */
131
	 * Create a new UMLElementNode
125
    public UMLElementNode(Children ch, Lookup lookup) {
132
	 */
126
        this(ch, lookup, new ProjectTreeItemImpl());
133
	public UMLElementNode(Children ch, Lookup lookup)
127
    }
134
	{
128
135
		this(ch, lookup, new ProjectTreeItemImpl());
129
    /**
136
	}
130
     * Create a new UMLElementNode and initialize its data with the information
137
	
131
     * from an IProjectTreeItem.
138
	/**
132
     *
139
	 * Create a new UMLElementNode and initialize its data with the information
133
     * @param item The ITreeItem used to initialize the new node.
140
	 * from an IProjectTreeItem.
134
     * @see IProjectTreeItem
141
	 *
135
     */
142
	 * @param item The ITreeItem used to initialize the new node.
136
    public UMLElementNode(IProjectTreeItem data) {
143
	 * @see IProjectTreeItem
137
        super(new UMLChildren());
144
	 */
138
        setData(data);
145
	public UMLElementNode(IProjectTreeItem data)
139
        setUpChildren();
146
	{
140
        addProjectTreeItemCookie(data);
147
		super(new UMLChildren());
141
    }
148
		setData(data);
142
149
		setUpChildren();
143
    /**
150
		addProjectTreeItemCookie(data);
144
     * Create a new UMLElementNode and initialize its data with the information
151
	}
145
     * from an ITreeItem.
152
	
146
     *
153
	/**
147
     * @param item The ITreeItem used to initialize the new node.
154
	 * Create a new UMLElementNode and initialize its data with the information
148
     * @see ITreeItem
155
	 * from an ITreeItem.
149
     */
156
	 *
150
    public UMLElementNode(ITreeItem item) {
157
	 * @param item The ITreeItem used to initialize the new node.
151
        this(item.getData());
158
	 * @see ITreeItem
152
    }
159
	 */
153
160
	public UMLElementNode(ITreeItem item)
154
    /**
161
	{
155
     * Create a new UMLElementNode and initialize its data with the information
162
		this(item.getData());
156
     * from an IProjectTreeItem.
163
	}
157
     */
164
	
158
    public UMLElementNode(Lookup lookup, IProjectTreeItem data) {
165
	/**
159
        super(new UMLChildren(), lookup);
166
	 * Create a new UMLElementNode and initialize its data with the information
160
        setData(data);
167
	 * from an IProjectTreeItem.
161
        //addChild(this);
168
	 */
162
        setUpChildren();
169
	public UMLElementNode(Lookup lookup, IProjectTreeItem data)
163
    }
170
	{
164
171
		super(new UMLChildren(), lookup);
165
    public UMLElementNode(Children ch, Lookup lookup, IProjectTreeItem data) {
172
		setData(data);
166
        super(ch, lookup);
173
		//addChild(this);
167
        setData(data);
174
		setUpChildren();
168
        setUpChildren();
175
	}
169
        //addChild(this);
176
	
170
        //setChildren(new UMLChildren(this));
177
	public UMLElementNode(Children ch, Lookup lookup, IProjectTreeItem data)
171
    }
178
	{
172
179
		super(ch, lookup);
173
    protected void addProjectTreeItemCookie(IProjectTreeItem projectTreeItem) {
180
		setData(data);
174
        getCookieSet().add(projectTreeItem);
181
		setUpChildren();
175
    }
182
		//addChild(this);
176
183
		//setChildren(new UMLChildren(this));
177
    /**
184
	}
178
     * Gathers the nodes children.
185
	
179
     */
186
	
180
    public void setUpChildren() {
187
	
181
        Children ch = getChildren();
188
	protected void addProjectTreeItemCookie(IProjectTreeItem projectTreeItem)
182
        if (ch != null && ch instanceof UMLChildren) {
189
	{
183
            final UMLChildren children = (UMLChildren) ch;
190
		getCookieSet().add(projectTreeItem);
184
            children.setItem(this);
191
	}
185
        }
192
	
186
    }
193
	/**
187
194
	 * Gathers the nodes children.
195
	 */
196
	public void setUpChildren()
197
	{
198
		Children ch = getChildren();
199
		if (ch != null && ch instanceof UMLChildren)
200
		{
201
			final UMLChildren children = (UMLChildren)ch;
202
			children.setItem(this);
203
		}
204
	}
205
	
206
    //**************************************************
188
    //**************************************************
207
    // ITreeItem Implementation
189
    // ITreeItem Implementation
208
    //**************************************************
190
    //**************************************************
191
    public String getName() {
192
        IElement element = getModelElement();
209
193
210
   public String getName()
194
        if (element instanceof INamedElement) {
211
    {
212
        IElement element = getModelElement(); 
213
214
        if (element instanceof INamedElement)
215
        {
216
            // return unformatted name for attributes and operations, so that
195
            // return unformatted name for attributes and operations, so that
217
            // rename action on those nodes will display the bare name without
196
            // rename action on those nodes will display the bare name without
218
            // visibility modifier and type information, since we only support 
197
            // visibility modifier and type information, since we only support 
219
            // rename the name part of these two types of elements from project
198
            // rename the name part of these two types of elements from project
220
            // tree
199
            // tree
221
            if (element.getElementType().equals(ELEMENT_TYPE_ATTRIBUTE) ||
200
            if (element.getElementType().equals(ELEMENT_TYPE_ATTRIBUTE)
222
                    element.getElementType().equals(ELEMENT_TYPE_OPERATION))
201
                    || element.getElementType().equals(ELEMENT_TYPE_OPERATION)) {
223
            {
224
                return (((INamedElement) element).getName());
202
                return (((INamedElement) element).getName());
225
            }
203
            }
226
        }
204
        }
Lines 228-621 Link Here
228
        return super.getName();
206
        return super.getName();
229
    }
207
    }
230
208
231
    
209
    /* (non-Javadoc)
232
   /* (non-Javadoc)
210
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setDisplayedName(java.lang.String)
233
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setDisplayedName(java.lang.String)
211
     */
234
    */
212
    public void setDisplayedName(String name) {
235
        public void setDisplayedName(String name)
213
        setDisplayedName(name, true);
236
        {
214
    }
237
            setDisplayedName(name, true);
215
216
    /* (non-Javadoc)
217
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setDisplayedName(java.lang.String,V)
218
     */
219
    public void setDisplayedName(String name, boolean buildProperties) {
220
        setDisplayName(name, buildProperties);
221
        if (getData() != null) {
222
            getData().setItemText(name);
238
        }
223
        }
239
        
224
240
   /* (non-Javadoc)
225
        IElement element = getModelElement();
241
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setDisplayedName(java.lang.String,V)
226
242
    */
227
        if (element instanceof INamedElement) {
243
        public void setDisplayedName(String name, boolean buildProperties)
228
            // set the name of the node as well, so in edit mode, the new name
244
        {
229
            // of the element will be displayed
245
            setDisplayName(name, buildProperties);
230
            super.setName(((INamedElement) element).getName());
246
            if (getData() != null)
231
        }
247
                getData().setItemText(name);
232
248
            
249
            IElement element = getModelElement();
250
            
251
            if (element instanceof INamedElement)
252
            {
253
                // set the name of the node as well, so in edit mode, the new name
254
                // of the element will be displayed
255
                super.setName(((INamedElement)element).getName());
256
            }
257
            
258
//        else
233
//        else
259
//            setName(name);
234
//            setName(name);
235
    }
236
237
    public String getDisplayName() {
238
        String retVal = super.getDisplayName();
239
240
        if (retVal == null || retVal.length() <= 0) {
241
            if (getData() != null) {
242
                retVal = getData().getItemText();
243
            }
260
        }
244
        }
261
    
245
262
    
246
        if (retVal == null || retVal.length() <= 0) {
263
    public String getDisplayName()
247
            retVal = getName();
264
    {
265
        String retVal = super.getDisplayName();
266
        
267
        if (retVal == null || retVal.length() <= 0)
268
        {
269
            if (getData() != null)
270
                retVal = getData().getItemText();
271
        }
248
        }
272
        
249
273
        if (retVal == null || retVal.length() <= 0)
274
            retVal = getName();
275
        
276
        return retVal;
250
        return retVal;
277
    }
251
    }
278
    
252
279
    
253
    /* (non-Javadoc)
280
   /* (non-Javadoc)
254
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getDisplayedName()
281
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getDisplayedName()
255
     */
282
    */
256
    public String getDisplayedName() {
283
    public String getDisplayedName()
284
    {
285
        return getDisplayName();
257
        return getDisplayName();
286
	}
258
    }
287
	
288
	
289
	
290
   /* (non-Javadoc)
291
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getPath()
292
	*/
293
	public Object[] getPath()
294
	{
295
		ArrayList parents = new ArrayList();
296
		
297
		while (getParentNode() != null)
298
		{
299
			parents.add(0, getParentNode());
300
		}
301
		
302
		Object[] retVal = new Object[parents.size()];
303
		parents.toArray(retVal);
304
		return retVal;
305
	}
306
	
307
   /* (non-Javadoc)
308
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getPathAsString()
309
	*/
310
	public String getPathAsString()
311
	{
312
		//      StringBuffer retVal = new StringBuffer(getDisplayName());
313
		//
314
		////      ArrayList parents = new ArrayList();
315
		////
316
		////      while (getParentNode() != null)
317
		////      {
318
		////         retVal.insert(0, "|");
319
		////         retVal.insert(0, getParentNode().getDisplayName());
320
		////      }
321
		//
322
		//      Node parent = getParentNode();
323
		//      if(parent != null)
324
		//      {
325
		//
326
		//      }
327
		//
328
		//      return retVal.toString();
329
		
330
		return mPathAsString;
331
	}
332
	
333
   /* (non-Javadoc)
334
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setPathAsString(java.lang.String)
335
	*/
336
	public void setPathAsString(String str)
337
	{
338
		mPathAsString = str;
339
	}
340
	
341
   /* (non-Javadoc)
342
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#isSame(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
343
	*/
344
	public boolean isSame(ITreeItem queryItem)
345
	{
346
		return equals(queryItem);
347
	}
348
	
349
   /* (non-Javadoc)
350
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getParentItem()
351
	*/
352
	public ITreeItem getParentItem()
353
	{
354
		ITreeItem retVal = null;
355
		Node parentNode = getParentNode();
356
		
357
		if (parentNode instanceof ITreeItem)
358
			retVal = (ITreeItem)parentNode;
359
		
360
		return retVal;
361
	}
362
	
363
   /* (non-Javadoc)
364
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setParentItem(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
365
	*/
366
	public void setParentItem(ITreeItem parent)
367
	{
368
	}
369
	
370
   /* (non-Javadoc)
371
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getTopParentItem()
372
	*/
373
	public ITreeItem getTopParentItem()
374
	{
375
		ITreeItem pTop = null;
376
		ITreeItem pItem = getParentItem();
377
		
378
		while (pItem != null)
379
		{
380
			pTop = pItem;
381
			ITreeItem pTemp = pTop.getParentItem();
382
			pItem = pTemp;
383
		}
384
		
385
		return pTop;
386
	}
387
	
388
   /* (non-Javadoc)
389
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getOwningTreeElement()
390
	*/
391
	public ITreeElement getOwningTreeElement()
392
	{
393
		ITreeElement pOutEle = null;
394
		ITreeItem pLast = null;
395
		ITreeItem pItem = getParentItem();
396
		
397
		while (pItem != null)
398
		{
399
			pLast = pItem;
400
			
401
			if (pItem instanceof ITreeRelElement)
402
			{
403
				ITreeItem pTemp = pLast.getParentItem();
404
				pItem = pTemp;
405
			}
406
			
407
			else if (pItem instanceof ITreeElement)
408
				pItem = null;
409
			
410
			else
411
			{
412
				ITreeItem pTemp = pLast.getParentItem();
413
				pItem = pTemp;
414
			}
415
		}
416
259
417
		if (pLast != null)
260
    /* (non-Javadoc)
418
		{
261
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getPath()
419
			if (pLast instanceof ITreeElement)
262
     */
420
				pOutEle = (ITreeElement)pLast;
263
    public Object[] getPath() {
421
		}
264
        ArrayList parents = new ArrayList();
422
		
265
423
		return pOutEle;
266
        while (getParentNode() != null) {
424
	}
267
            parents.add(0, getParentNode());
425
	
268
        }
426
   /* (non-Javadoc)
269
427
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getType()
270
        Object[] retVal = new Object[parents.size()];
428
	*/
271
        parents.toArray(retVal);
429
	public String getType()
272
        return retVal;
430
	{
273
    }
431
		return null;
274
432
	}
275
    /* (non-Javadoc)
433
	
276
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getPathAsString()
434
   /* (non-Javadoc)
277
     */
435
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#addChild(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
278
    public String getPathAsString() {
436
	*/
279
        //      StringBuffer retVal = new StringBuffer(getDisplayName());
437
	public void addChild(ITreeItem item)
280
        //
438
	{
281
        ////      ArrayList parents = new ArrayList();
282
        ////
283
        ////      while (getParentNode() != null)
284
        ////      {
285
        ////         retVal.insert(0, "|");
286
        ////         retVal.insert(0, getParentNode().getDisplayName());
287
        ////      }
288
        //
289
        //      Node parent = getParentNode();
290
        //      if(parent != null)
291
        //      {
292
        //
293
        //      }
294
        //
295
        //      return retVal.toString();
296
297
        return mPathAsString;
298
    }
299
300
    /* (non-Javadoc)
301
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setPathAsString(java.lang.String)
302
     */
303
    public void setPathAsString(String str) {
304
        mPathAsString = str;
305
    }
306
307
    /* (non-Javadoc)
308
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#isSame(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
309
     */
310
    public boolean isSame(ITreeItem queryItem) {
311
        return equals(queryItem);
312
    }
313
314
    /* (non-Javadoc)
315
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getParentItem()
316
     */
317
    public ITreeItem getParentItem() {
318
        ITreeItem retVal = null;
319
        Node parentNode = getParentNode();
320
321
        if (parentNode instanceof ITreeItem) {
322
            retVal = (ITreeItem) parentNode;
323
        }
324
325
        return retVal;
326
    }
327
328
    /* (non-Javadoc)
329
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setParentItem(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
330
     */
331
    public void setParentItem(ITreeItem parent) {
332
    }
333
334
    /* (non-Javadoc)
335
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getTopParentItem()
336
     */
337
    public ITreeItem getTopParentItem() {
338
        ITreeItem pTop = null;
339
        ITreeItem pItem = getParentItem();
340
341
        while (pItem != null) {
342
            pTop = pItem;
343
            ITreeItem pTemp = pTop.getParentItem();
344
            pItem = pTemp;
345
        }
346
347
        return pTop;
348
    }
349
350
    /* (non-Javadoc)
351
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getOwningTreeElement()
352
     */
353
    public ITreeElement getOwningTreeElement() {
354
        ITreeElement pOutEle = null;
355
        ITreeItem pLast = null;
356
        ITreeItem pItem = getParentItem();
357
358
        while (pItem != null) {
359
            pLast = pItem;
360
361
            if (pItem instanceof ITreeRelElement) {
362
                ITreeItem pTemp = pLast.getParentItem();
363
                pItem = pTemp;
364
            } else if (pItem instanceof ITreeElement) {
365
                pItem = null;
366
            } else {
367
                ITreeItem pTemp = pLast.getParentItem();
368
                pItem = pTemp;
369
            }
370
        }
371
372
        if (pLast != null) {
373
            if (pLast instanceof ITreeElement) {
374
                pOutEle = (ITreeElement) pLast;
375
            }
376
        }
377
378
        return pOutEle;
379
    }
380
381
    /* (non-Javadoc)
382
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getType()
383
     */
384
    public String getType() {
385
        return null;
386
    }
387
388
    /* (non-Javadoc)
389
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#addChild(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
390
     */
391
    public void addChild(ITreeItem item) {
439
        boolean canAdd = true;
392
        boolean canAdd = true;
440
		// <Sheryl> Do we really need this condition check? In case like 'Relationships' 
393
        // <Sheryl> Do we really need this condition check? In case like 'Relationships'
441
		// -> 'Specializations', these two folders both refer to the same 
394
        // -> 'Specializations', these two folders both refer to the same
442
		// model element, the sub-folder will not be added as a result, #6320478
395
        // model element, the sub-folder will not be added as a result, #6320478
443
		// to filter out the relationship end which refers to itself, it's temporary
396
        // to filter out the relationship end which refers to itself, it's temporary
444
		// we need to go back to visit the root cause in project tree impl
397
        // we need to go back to visit the root cause in project tree impl
445
        ITreeItem parent = getParentItem();
398
        ITreeItem parent = getParentItem();
446
        if(parent != null)
399
        if (parent != null) {
447
        {
448
            String yourID = item.getData().getModelElementXMIID();
400
            String yourID = item.getData().getModelElementXMIID();
449
            String parentID = parent.getData().getModelElementXMIID();
401
            String parentID = parent.getData().getModelElementXMIID();
450
			if (item instanceof ITreeFolder == false)
402
            if (item instanceof ITreeFolder == false) {
451
				canAdd = !yourID.equals(parentID);
403
                canAdd = !yourID.equals(parentID);
404
            }
452
        }
405
        }
453
        if(canAdd == true)
406
        if (canAdd == true) {
454
        {            
407
            if (item instanceof Node) {
455
            if (item instanceof Node)
408
                Node[] node = {(Node) item};
456
            {
457
                Node[] node ={(Node)item};
458
                Children children = getChildren();
409
                Children children = getChildren();
459
410
460
                if (children != null)
411
                if (children != null) {
461
                    children.add(node);
412
                    children.add(node);
413
                }
462
            }
414
            }
463
        }
415
        }
464
	}
416
    }
465
	
417
466
   /* (non-Javadoc)
418
    /* (non-Javadoc)
467
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#insertAt(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem, int)
419
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#insertAt(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem, int)
468
	*/
420
     */
469
	public void insertAt(ITreeItem item, int index)
421
    public void insertAt(ITreeItem item, int index) {
470
	{
422
        // The NetBeans API does not allow you to add a child to a specific
471
		// The NetBeans API does not allow you to add a child to a specific
423
        // index.  The children are sorted so this is not neccessary.
472
		// index.  The children are sorted so this is not neccessary.
424
        addChild(item);
473
		addChild(item);
425
    }
474
	}
426
475
	
427
    /* (non-Javadoc)
476
   /* (non-Javadoc)
428
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#removeChild(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
477
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#removeChild(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
429
     */
478
	*/
430
    public void removeChild(ITreeItem item) {
479
	public void removeChild(ITreeItem item)
431
        if (item instanceof Node) {
480
	{
432
            Node[] node = {(Node) item};
481
		if (item instanceof Node)
433
            Children children = getChildren();
482
		{
434
483
			Node[] node = {(Node)item};
435
            if (children != null) {
484
			Children children = getChildren();
436
                children.remove(node);
485
			
437
            }
486
			if (children != null)
438
        }
487
				children.remove(node);
439
    }
488
		}
440
489
	}
441
    /* (non-Javadoc)
490
	
442
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#removeAllChildren()
491
   /* (non-Javadoc)
443
     */
492
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#removeAllChildren()
444
    public void removeAllChildren() {
493
	*/
445
        Children children = getChildren();
494
	public void removeAllChildren()
446
495
	{
447
        if ((children != null) && (children.getNodesCount() > 0)) {
496
		Children children = getChildren();
448
            children.remove(children.getNodes());
497
		
449
        }
498
		if ((children != null) && (children.getNodesCount() > 0))
450
    }
499
			children.remove(children.getNodes());
451
500
	}
452
    /* (non-Javadoc)
501
	
453
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getChild(int)
502
   /* (non-Javadoc)
454
     */
503
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getChild(int)
455
    public ITreeItem getChild(int index) {
504
	*/
456
        // TODO Auto-generated method stub
505
	public ITreeItem getChild(int index)
457
        return null;
506
	{
458
    }
507
		// TODO Auto-generated method stub
459
508
		return null;
460
    /* (non-Javadoc)
509
	}
461
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#sortChildren()
510
	
462
     */
511
   /* (non-Javadoc)
463
    public void sortChildren() {
512
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#sortChildren()
464
        ((UMLChildren) getChildren()).recalculateChildren();
513
	*/
465
    }
514
	public void sortChildren() 
466
515
	{
467
    /* (non-Javadoc)
516
		((UMLChildren)getChildren()).recalculateChildren();
468
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#sortChildren(java.util.Comparator)
517
	}
469
     */
518
	
470
    public void sortChildren(Comparator compare) {
519
   /* (non-Javadoc)
471
    }
520
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#sortChildren(java.util.Comparator)
472
521
	*/
473
    /* (non-Javadoc)
522
	public void sortChildren(Comparator compare) {}
474
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getData()
523
	
475
     */
524
   /* (non-Javadoc)
476
    public IProjectTreeItem getData() {
525
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getData()
477
        return m_Data;
526
	*/
478
    }
527
	public IProjectTreeItem getData()
479
528
	{
480
    protected void setData(IProjectTreeItem data) {
529
		return m_Data;
481
        m_Data = data;
530
	}
482
531
	
483
        if (data != null) {
532
	protected void setData(IProjectTreeItem data)
484
            m_Data.setProjectTreeSupportTreeItem(this);
533
	{
485
        }
534
		m_Data = data;
486
    }
535
		
487
536
		if (data != null)
488
    /* (non-Javadoc)
537
			m_Data.setProjectTreeSupportTreeItem(this);
489
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getChildCount()
538
	}
490
     */
539
	
491
    public int getChildCount() {
540
   /* (non-Javadoc)
492
        int retVal = 0;
541
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getChildCount()
493
        Children children = getChildren();
542
	*/
494
543
	public int getChildCount()
495
        if (children != null) {
544
	{
496
            retVal = children.getNodesCount();
545
		int retVal = 0;
497
        }
546
		Children children = getChildren();
498
547
		
499
        return retVal;
548
		if (children != null)
500
    }
549
			retVal = children.getNodesCount();
501
550
		
502
    /* (non-Javadoc)
551
		return retVal;
503
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#isInitalized()
552
	}
504
     */
553
	
505
    public boolean isInitalized() {
554
   /* (non-Javadoc)
506
        // TODO Auto-generated method stub
555
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#isInitalized()
507
        return mIsInitialized;
556
	*/
508
    }
557
	public boolean isInitalized()
509
558
	{
510
    /* (non-Javadoc)
559
		// TODO Auto-generated method stub
511
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setIsInitalized(boolean)
560
		return mIsInitialized;
512
     */
561
	}
513
    public void setIsInitalized(boolean value) {
562
	
514
        mIsInitialized = value;
563
   /* (non-Javadoc)
515
    }
564
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setIsInitalized(boolean)
516
565
	*/
517
    /* (non-Javadoc)
566
	public void setIsInitalized(boolean value)
518
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getSortPriority()
567
	{
519
     */
568
		mIsInitialized = value;
520
    public long getSortPriority() {
569
	}
521
        // TODO Auto-generated method stub
570
	
522
        return m_Data.getSortPriority();
571
   /* (non-Javadoc)
523
    }
572
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#getSortPriority()
524
573
	*/
525
    /* (non-Javadoc)
574
	public long getSortPriority()
526
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setSortPriority(long)
575
	{
527
     */
576
		// TODO Auto-generated method stub
528
    public void setSortPriority(long value) {
577
		return m_Data.getSortPriority();
529
        m_Data.setSortPriority(value);
578
	}
530
    }
579
	
531
580
   /* (non-Javadoc)
532
    /* (non-Javadoc)
581
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setSortPriority(long)
533
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setExpanded(boolean)
582
	*/
534
     */
583
	public void setSortPriority(long value)
535
    public void setExpanded(boolean value) {
584
	{
536
    }
585
		m_Data.setSortPriority(value);
537
586
	}
538
    /* (non-Javadoc)
587
	
539
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setSelected(boolean)
588
   /* (non-Javadoc)
540
     */
589
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setExpanded(boolean)
541
    public void setSelected(boolean value) {
590
	*/
542
    }
591
	public void setExpanded(boolean value){}
543
592
	
544
    /**
593
   /* (non-Javadoc)
545
     * Retrieve a collection that contains all of the children contained by the
594
	* @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#setSelected(boolean)
546
     * node.
595
	*/
547
     * <br>
596
	public void setSelected(boolean value) {}
548
     * <i>Note:</i> This collection should be treated as <b>read-only</b>.  If a
597
	
549
     * node is added to the returned collection any associated view will not be
598
	/**
550
     * updated until a refresh is performed.
599
	 * Retrieve a collection that contains all of the children contained by the
551
     *
600
	 * node.
552
     * @return The collection of children.
601
	 * <br>
553
     */
602
	 * <i>Note:</i> This collection should be treated as <b>read-only</b>.  If a
554
    public Enumeration<ITreeItem> getNodeChildren() {
603
	 * node is added to the returned collection any associated view will not be
555
        Children children = getChildren();
604
	 * updated until a refresh is performed.
556
605
	 *
557
        return new TreeItemEnumeration(children);
606
	 * @return The collection of children.
558
    }
607
	 */
559
608
	public Enumeration<ITreeItem> getNodeChildren()
560
    //**************************************************
609
	{
561
    // AbstractModelElement Implementation
610
		Children children = getChildren();
562
    //**************************************************
611
		
612
		return new TreeItemEnumeration(children);
613
	}
614
	
615
	//**************************************************
616
	// AbstractModelElement Implementation
617
	//**************************************************
618
	
619
    /**
563
    /**
620
     * Retrieves the actions for the node.  This method only returns
564
     * Retrieves the actions for the node.  This method only returns
621
     * the context sensitive actions.
565
     * the context sensitive actions.
Lines 624-1010 Link Here
624
     *                node itself
568
     *                node itself
625
     * @return A list of actions (you may include nulls for separators)
569
     * @return A list of actions (you may include nulls for separators)
626
     */
570
     */
627
    public Action[] getActions(boolean context)
571
    public Action[] getActions(boolean context) {
628
    {
629
572
630
// Source control Sub menu Actions are created based on the SCM status of the nodes (Class diagrams, classes) 
573
// Source control Sub menu Actions are created based on the SCM status of the nodes (Class diagrams, classes) 
631
// so every time we need to get the actions afresh.  
574
// so every time we need to get the actions afresh.  
632
		
575
633
//			if (actions == null)
576
//			if (actions == null)
634
		return super.getActions(context);
577
        return super.getActions(context);
635
		
578
636
	}
579
    }
637
	
580
638
	public Action getPreferredAction()
581
    public Action getPreferredAction() {
639
	{
582
        return SystemAction.get(OpenAction.class);
640
		return SystemAction.get(OpenAction.class);
583
    }
641
	}
584
642
	
643
    @Override
585
    @Override
644
    public Image getIcon(int type)
586
    public Image getIcon(int type) {
645
    {
646
        Image retVal = null;
587
        Image retVal = null;
647
        //	if(icon!=null) return icon;
588
        //	if(icon!=null) return icon;
648
589
649
        ITreeItem item = this;
590
        ITreeItem item = this;
650
        IProjectTreeItem data = item.getData();
591
        IProjectTreeItem data = item.getData();
651
592
652
        if (icon!=null)
593
        if (icon != null) {
653
        {
654
            retVal = icon;
594
            retVal = icon;
655
        }
595
        } else {
656
596
657
        else
597
            if (item instanceof ITreeFolder) {
658
        {
598
                CommonResourceManager resource =
599
                        CommonResourceManager.instance();
659
600
660
            if (item instanceof ITreeFolder)
601
                retVal = createImage(resource.getIconDetailsForElementType(item.getName()));
661
            {
602
            } else if (item instanceof ITreeDiagram) {
662
                CommonResourceManager resource =
603
                ITreeDiagram diagram = (ITreeDiagram) item;
663
                    CommonResourceManager.instance();
664
665
                retVal = createImage(resource
666
                    .getIconDetailsForElementType(item.getName()));
667
            }
668
669
            else if (item instanceof ITreeDiagram)
670
            {
671
                ITreeDiagram diagram = (ITreeDiagram)item;
672
604
673
                CommonResourceManager resource =
605
                CommonResourceManager resource =
674
                    CommonResourceManager.instance();
606
                        CommonResourceManager.instance();
675
607
676
                retVal = createImage(resource
608
                retVal = createImage(resource.getIconDetailsForElementType(diagram.getDiagramType()));
677
                    .getIconDetailsForElementType(diagram.getDiagramType()));
678
609
679
                if (diagram.getDiagram().getDiagramDetails() 
610
                if (diagram.getDiagram().getDiagramDetails() instanceof TSDiagramDetails) {
680
                    instanceof TSDiagramDetails)
681
                {
682
                    // this is an old TS diagram; when opened, it needs
611
                    // this is an old TS diagram; when opened, it needs
683
                    // to be converted to new Meteora diagram.
612
                    // to be converted to new Meteora diagram.
684
                    // this code will badge the diagram icon with a
613
                    // this code will badge the diagram icon with a
685
                    // yellow triangle with an exclamation point to 
614
                    // yellow triangle with an exclamation point to 
686
                    // visually indicate the diagram's state
615
                    // visually indicate the diagram's state
687
                    retVal = ImageUtilities.mergeImages(
616
                    retVal = ImageUtilities.mergeImages(
688
                        retVal, createImage(ICON_BADGE_EXCLAMATION), 0, 0);
617
                            retVal, createImage(ICON_BADGE_EXCLAMATION), 0, 0);
689
                }
618
                }
690
            }
619
            } else if (data.getModelElement() != null) {
620
                if (data.getModelElement() instanceof IProject) {
621
                    retVal = super.getIcon(type);
622
                } else {
623
                    CommonResourceManager resource =
624
                            CommonResourceManager.instance();
691
625
692
            else if (data.getModelElement() != null)
626
                    retVal = createImage(resource.getIconDetailsForDisp(data.getModelElement()));
693
            {
694
                if (data.getModelElement() instanceof IProject)
695
                    retVal = super.getIcon(type);
696
697
                else
698
                {
699
                    CommonResourceManager resource =
700
                        CommonResourceManager.instance();
701
702
                    retVal = createImage(resource
703
                        .getIconDetailsForDisp(data.getModelElement()));
704
                }
627
                }
705
            }
628
            } else if (data.isProject()) {
706
707
            else if (data.isProject())
708
            {
709
                // CommonResourceManager resource = 
629
                // CommonResourceManager resource = 
710
                //     CommonResourceManager.instance();
630
                //     CommonResourceManager.instance();
711
                // retVal = createImage(
631
                // retVal = createImage(
712
                //     resource.getIconDetailsForElementType("WSProject"));
632
                //     resource.getIconDetailsForElementType("WSProject"));
713
633
714
                retVal = super.getIcon(type);
634
                retVal = super.getIcon(type);
715
            }
635
            } else if (data.isWorkspace()) {
716
717
            else if (data.isWorkspace())
718
            {
719
                CommonResourceManager resource = CommonResourceManager.instance();
636
                CommonResourceManager resource = CommonResourceManager.instance();
720
                // special case for design pattern catalog
637
                // special case for design pattern catalog
721
638
722
                if (data.getItemText().equals("DesignPatternCatalog")) // NOI18N
639
                if (data.getItemText().equals("DesignPatternCatalog")) // NOI18N
723
                {
640
                {
724
                    retVal = createImage(
641
                    retVal = createImage(
725
                        resource.getIconDetailsForElementType(
642
                            resource.getIconDetailsForElementType(
726
                        "DesignPatternCatalog")); // NOI18N
643
                            "DesignPatternCatalog")); // NOI18N
644
                } else {
645
                    retVal = createImage(resource.getIconDetailsForElementType("Workspace")); // NOI18N
727
                }
646
                }
728
647
            } else {
729
                else
648
                CommonResourceManager resource =
730
                {
649
                        CommonResourceManager.instance();
731
                    retVal = createImage(resource
732
                        .getIconDetailsForElementType("Workspace")); // NOI18N
733
                }
734
            }
735
736
            else
737
            {
738
                CommonResourceManager resource = 
739
                    CommonResourceManager.instance();
740
650
741
                retVal = createImage(
651
                retVal = createImage(
742
                    resource.getIconDetailsForElementType(item.getName()));
652
                        resource.getIconDetailsForElementType(item.getName()));
743
            }
653
            }
744
        }
654
        }
745
655
746
        if (retVal == null)
656
        if (retVal == null) {
747
            retVal = super.getIcon(type);
657
            retVal = super.getIcon(type);
658
        }
748
659
749
        //return getIconWithOverlay(retVal, this);
660
        //return getIconWithOverlay(retVal, this);
750
        retVal=getIconWithOverlay(retVal, this);
661
        retVal = getIconWithOverlay(retVal, this);
751
662
752
        icon=retVal;
663
        icon = retVal;
753
        return icon;
664
        return icon;
754
    }
665
    }
755
    
666
    public final static String ICON_BADGE_EXCLAMATION =
756
    public final static String ICON_BADGE_EXCLAMATION = 
667
            ImageUtil.IMAGE_FOLDER + "broken-project-badge.gif";
757
        ImageUtil.IMAGE_FOLDER + "broken-project-badge.gif";
668
758
	
759
    @Override
669
    @Override
760
	public Image getOpenedIcon(int type)
670
    public Image getOpenedIcon(int type) {
761
	{
671
        return getIcon(type);
762
		return getIcon(type);
672
    }
763
	}
764
	
765
   /* (non-Javadoc)
766
	* @see org.netbeans.modules.uml.netbeans.umlproject.ui.AbstractModelElementNode#getModelElement()
767
	*/
768
	public IElement getModelElement()
769
	{
770
		IElement retVal = null;
771
		IProjectTreeItem item = getData();
772
		
773
		if (item != null)
774
			retVal = item.getModelElement();
775
673
776
		return retVal;
674
    /* (non-Javadoc)
777
	}
675
     * @see org.netbeans.modules.uml.netbeans.umlproject.ui.AbstractModelElementNode#getModelElement()
778
	
676
     */
779
	
677
    public IElement getModelElement() {
780
	//**************************************************
678
        IElement retVal = null;
781
	// CookieSet.Factory implementation
679
        IProjectTreeItem item = getData();
782
	//**************************************************
783
	
784
	public Node.Cookie createCookie(Class klass)
785
	{
786
		Node.Cookie retVal = null;
787
		
788
		if (OpenCookie.class.equals(klass) == true)
789
		{
790
			if (mOpenCookie == null)
791
				mOpenCookie = createOpenCookie();
792
			
793
			retVal = mOpenCookie;
794
		}
795
		
796
		return retVal;
797
	}
798
	
799
	
800
	//**************************************************
801
	// Helper Methods
802
	//**************************************************
803
	
804
	public String toString()
805
	{
806
		String retVal = getDisplayedName();
807
		
808
		if ((retVal == null) || (retVal.length() <= 0))
809
			retVal = getName();
810
		
811
		return retVal;
812
	}
813
	
814
   /* (non-Javadoc)
815
	* @see java.lang.Object#equals(java.lang.Object)
816
	*/
817
	public boolean equals(Object obj)
818
	{
819
		boolean retVal = false;
820
		
821
		if (obj != null && this.hashCode() == obj.hashCode())
822
		    return true;
823
        
824
		IProjectTreeItem myItem = getData();
825
		
826
		if (obj instanceof IElement)
827
		{
828
			IElement myElement = myItem.getModelElement();
829
			
830
			if (myElement != null)
831
				retVal = myElement.isSame((IElement)obj);
832
		}
833
680
834
		else if (obj instanceof UMLElementNode)
681
        if (item != null) {
835
		{
682
            retVal = item.getModelElement();
836
			UMLElementNode node = (UMLElementNode)obj;
683
        }
837
			IProjectTreeItem testItem = node.getData();
684
838
			String testText = node.getDisplayedName();
685
        return retVal;
839
			String myText   = getDisplayedName();
686
    }
840
			
687
841
			if ((testText != null) && (myText != null))
688
    //**************************************************
842
				retVal = testText.equals(myText);
689
    // CookieSet.Factory implementation
843
			
690
    //**************************************************
844
			else if ((testText == null) && (myText == null))
691
    public Node.Cookie createCookie(Class klass) {
845
				retVal =  super.equals(obj);
692
        Node.Cookie retVal = null;
846
			
693
847
			if (retVal == true)
694
        if (OpenCookie.class.equals(klass) == true) {
848
			{
695
            if (mOpenCookie == null) {
849
				String testXMIID = testItem.getModelElementXMIID();
696
                mOpenCookie = createOpenCookie();
850
				String myXMIID = myItem.getModelElementXMIID();
697
            }
851
				
698
852
				if ((testXMIID != null) && (myXMIID != null))
699
            retVal = mOpenCookie;
853
					retVal = testXMIID.equals(myXMIID);
700
        }
854
			}
701
855
		}
702
        return retVal;
856
		
703
    }
857
		else
704
858
		{  // Generic equals method.  This can be used to test
705
    //**************************************************
859
			// to ITreeItem(s).
706
    // Helper Methods
860
			retVal =  super.equals(obj);
707
    //**************************************************
861
		}
708
    public String toString() {
862
		
709
        String retVal = getDisplayedName();
863
		return retVal;
710
864
	}
711
        if ((retVal == null) || (retVal.length() <= 0)) {
865
	
712
            retVal = getName();
866
	/**
713
        }
867
	 * Initializes the node with the default cookies.  <b>Note:</b>  Do not
714
868
	 * call this method if a looup is added.  When a lookup is added then the
715
        return retVal;
869
	 * lookup is used to find the cookies.
716
    }
870
	 */
717
871
	protected void initCookies()
718
    /* (non-Javadoc)
872
	{
719
     * @see java.lang.Object#equals(java.lang.Object)
873
		Class[] cookies = {OpenCookie.class};
720
     */
874
		getCookieSet().add(cookies, this);
721
    public boolean equals(Object obj) {
875
	}
722
        boolean retVal = false;
876
	
723
877
	/**
724
        if (obj != null && this.hashCode() == obj.hashCode()) {
878
	 * Creates the open cookie to use when opening the node.
725
            return true;
879
	 */
726
        }
880
	protected Node.Cookie createOpenCookie()
727
881
	{
728
        IProjectTreeItem myItem = getData();
882
		return new ModelElementOpen();
729
883
	}
730
        if (obj instanceof IElement) {
884
	
731
            IElement myElement = myItem.getModelElement();
885
	
732
886
	
733
            if (myElement != null) {
887
	/**
734
                retVal = myElement.isSame((IElement) obj);
888
	 * @param string
735
            }
889
	 * @return
736
        } else if (obj instanceof UMLElementNode) {
890
	 */
737
            UMLElementNode node = (UMLElementNode) obj;
891
	protected Image createImage(String iconLocation)
738
            IProjectTreeItem testItem = node.getData();
892
	{
739
            String testText = node.getDisplayedName();
893
		return ImageUtilities.loadImage( iconLocation, true );
740
            String myText = getDisplayedName();
894
	}
741
895
	
742
            if ((testText != null) && (myText != null)) {
896
	/**
743
                retVal = testText.equals(myText);
897
	 * Implementation of method from Comparable interface.
744
            } else if ((testText == null) && (myText == null)) {
898
	 * @return
745
                retVal = super.equals(obj);
899
	 */
746
            }
900
	public int compareTo(Object o)
747
901
	{
748
            if (retVal == true) {
902
	    return ProjectTreeComparable.compareTo(this, o);
749
                String testXMIID = testItem.getModelElementXMIID();
903
	}
750
                String myXMIID = myItem.getModelElementXMIID();
904
	
751
905
	// to be overridden by subclasses as needed
752
                if ((testXMIID != null) && (myXMIID != null)) {
906
	public void registerListeners()
753
                    retVal = testXMIID.equals(myXMIID);
907
	{}
754
                }
908
	
755
            }
909
	
756
        } else {  // Generic equals method.  This can be used to test
910
	public class ModelElementOpen implements OpenCookie
757
            // to ITreeItem(s).
911
	{
758
            retVal = super.equals(obj);
912
		public void open()
759
        }
913
		{
760
914
			DispatchHelper helper = new DispatchHelper();
761
        return retVal;
915
			IProjectTreeEventDispatcher disp = helper.getProjectTreeDispatcher();
762
    }
916
			if (disp != null)
763
917
			{
764
    /**
918
				IEventPayload payload = 
765
     * Initializes the node with the default cookies.  <b>Note:</b>  Do not
919
					disp.createPayload("ProjectTreeDoubleClick"); // NOI18N
766
     * call this method if a looup is added.  When a lookup is added then the
920
				
767
     * lookup is used to find the cookies.
921
				helper.getProjectTreeDispatcher().fireDoubleClick(null,
768
     */
922
					getData(), false, false, false, false, payload);
769
    protected void initCookies() {
923
			}
770
        Class[] cookies = {OpenCookie.class};
924
			
771
        getCookieSet().add(cookies, this);
925
			registerListeners();
772
    }
926
		}
773
927
	}
774
    /**
928
	
775
     * Creates the open cookie to use when opening the node.
929
	public class TreeItemEnumeration implements Enumeration < ITreeItem >
776
     */
930
	{
777
    protected Node.Cookie createOpenCookie() {
931
		Enumeration m_ChildrenEnum = null;
778
        return new ModelElementOpen();
932
		
779
    }
933
		public TreeItemEnumeration(Children c)
780
934
		{
781
    /**
935
			m_ChildrenEnum = c.nodes();
782
     * @param string
936
		}
783
     * @return
937
		
784
     */
938
		public boolean hasMoreElements()
785
    protected Image createImage(String iconLocation) {
939
		{
786
        return ImageUtilities.loadImage(iconLocation, true);
940
			return m_ChildrenEnum.hasMoreElements();
787
    }
941
		}
788
942
		
789
    /**
943
		public ITreeItem nextElement()
790
     * Implementation of method from Comparable interface.
944
		{
791
     * @return
945
			return (ITreeItem)m_ChildrenEnum.nextElement();
792
     */
946
		}
793
    public int compareTo(Object o) {
947
	}
794
        return ProjectTreeComparable.compareTo(this, o);
948
	
795
    }
949
	
796
950
	
797
    // to be overridden by subclasses as needed
951
	public void vcsFeatureExecuted(/* SCMFeatureKind */ int kind)
798
    public void registerListeners() {
952
	{
799
    }
953
		if(kind == SCMFeatureKind.FK_CHECK_IN || 
800
954
			kind == SCMFeatureKind.FK_CHECK_OUT ||
801
    public class ModelElementOpen implements OpenCookie {
955
			kind == SCMFeatureKind.FK_ADD_TO_SOURCE_CONTROL || 
802
956
			kind == SCMFeatureKind.FK_REMOVE_FROM_SOURCE_CONTROL ||
803
        public void open() {
957
			kind == SCMFeatureKind.REFRESH_STATUS)
804
            DispatchHelper helper = new DispatchHelper();
958
		{
805
            IProjectTreeEventDispatcher disp = helper.getProjectTreeDispatcher();
959
			fireIconChange();
806
            if (disp != null) {
960
		}
807
                IEventPayload payload =
961
	}
808
                        disp.createPayload("ProjectTreeDoubleClick"); // NOI18N
962
	
809
963
	protected Image getIconWithOverlay(Image image, ITreeItem item)
810
                helper.getProjectTreeDispatcher().fireDoubleClick(null,
964
	{
811
                        getData(), false, false, false, false, payload);
965
		ImageIcon image1 = new ImageIcon(image);
812
            }
966
		
813
967
		
814
            registerListeners();
968
		if(!(item instanceof ITreeFolder))
815
        }
969
		{
816
    }
970
			Icon overlay = getOverlayIcon(item.getData());
817
971
			
818
    public class TreeItemEnumeration implements Enumeration<ITreeItem> {
972
			if((image1 != null) && (overlay != null))
819
973
			{
820
        Enumeration m_ChildrenEnum = null;
974
				GraphicsDevice[] gs = GraphicsEnvironment
821
975
					.getLocalGraphicsEnvironment().getScreenDevices();
822
        public TreeItemEnumeration(Children c) {
976
				
823
            m_ChildrenEnum = c.nodes();
977
				GraphicsConfiguration[] gc = gs[0].getConfigurations();
824
        }
978
				
825
979
				Image retImage = gc[0].createCompatibleVolatileImage(
826
        public boolean hasMoreElements() {
980
					image1.getIconWidth(), image1.getIconHeight());
827
            return m_ChildrenEnum.hasMoreElements();
981
				
828
        }
982
				Graphics g = retImage.getGraphics();
829
983
				
830
        public ITreeItem nextElement() {
984
				image1.paintIcon(null, g, 0, 0);
831
            return (ITreeItem) m_ChildrenEnum.nextElement();
985
				
832
        }
986
				int overlayY = image1.getIconHeight() - overlay.getIconHeight();
833
    }
987
				overlay.paintIcon(null, g, 0, overlayY);
834
988
				
835
    public void vcsFeatureExecuted(/* SCMFeatureKind */int kind) {
989
				
836
        if (kind == SCMFeatureKind.FK_CHECK_IN
990
				image1 = new ImageIcon(retImage);
837
                || kind == SCMFeatureKind.FK_CHECK_OUT
991
			}
838
                || kind == SCMFeatureKind.FK_ADD_TO_SOURCE_CONTROL
992
		}
839
                || kind == SCMFeatureKind.FK_REMOVE_FROM_SOURCE_CONTROL
993
		return image1.getImage();
840
                || kind == SCMFeatureKind.REFRESH_STATUS) {
994
	}
841
            fireIconChange();
995
	
842
        }
996
	protected Icon getOverlayIcon(IProjectTreeItem item)
843
    }
997
	{
844
998
		Icon retVal = null;
845
    protected Image getIconWithOverlay(Image image, ITreeItem item) {
999
		
846
        ImageIcon image1 = new ImageIcon(image);
1000
		
847
1001
		ISCMIntegrator gator = ProductHelper.getSCMIntegrator();
848
1002
		if(gator != null)
849
        if (!(item instanceof ITreeFolder)) {
1003
		{
850
            Icon overlay = getOverlayIcon(item.getData());
1004
			int kind = gator.getSCMMaskKind(item);
851
1005
			retVal = gator.getSCMMask(kind);
852
            if ((image1 != null) && (overlay != null)) {
1006
		}
853
                GraphicsDevice[] gs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
1007
		
854
1008
		return retVal;
855
                GraphicsConfiguration[] gc = gs[0].getConfigurations();
1009
	}
856
857
                Image retImage = gc[0].createCompatibleVolatileImage(
858
                        image1.getIconWidth(), image1.getIconHeight());
859
860
                Graphics g = retImage.getGraphics();
861
862
                image1.paintIcon(null, g, 0, 0);
863
864
                int overlayY = image1.getIconHeight() - overlay.getIconHeight();
865
                overlay.paintIcon(null, g, 0, overlayY);
866
867
868
                image1 = new ImageIcon(retImage);
869
            }
870
        }
871
        return image1.getImage();
872
    }
873
874
    protected Icon getOverlayIcon(IProjectTreeItem item) {
875
        Icon retVal = null;
876
877
878
        ISCMIntegrator gator = ProductHelper.getSCMIntegrator();
879
        if (gator != null) {
880
            int kind = gator.getSCMMaskKind(item);
881
            retVal = gator.getSCMMask(kind);
882
        }
883
884
        return retVal;
885
    }
1010
}
886
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLFolderNode.java (-182 / +125 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
47
45
48
import javax.swing.Action;
46
import javax.swing.Action;
Lines 67-127 Link Here
67
 *
65
 *
68
 * @author Trey Spiva
66
 * @author Trey Spiva
69
 */
67
 */
70
public class UMLFolderNode extends UMLElementNode implements ITreeFolder
68
public class UMLFolderNode extends UMLElementNode implements ITreeFolder {
71
{
69
72
    
70
    private String m_GetMethodName = ""; // NOI18N
73
    private String m_GetMethodName  = ""; // NOI18N
71
    private String m_Name = ""; // NOI18N
74
    private String m_Name           = ""; // NOI18N
72
    private String m_ID = ""; // NOI18N
75
    private String m_ID             = ""; // NOI18N
76
    
77
    public final static String METHOD_NAME_GET_ATTRIBUTES = "getAttributes"; // NOI18N
73
    public final static String METHOD_NAME_GET_ATTRIBUTES = "getAttributes"; // NOI18N
78
    public final static String METHOD_NAME_GET_OPERATIONS = "getOperations"; // NOI18N
74
    public final static String METHOD_NAME_GET_OPERATIONS = "getOperations"; // NOI18N
79
    
75
80
    
76
    public UMLFolderNode() {
81
    public UMLFolderNode()
82
    {
83
        this(new ProjectTreeItemImpl());
77
        this(new ProjectTreeItemImpl());
84
    }
78
    }
85
    
79
86
    public UMLFolderNode(Lookup lookup)
80
    public UMLFolderNode(Lookup lookup) {
87
    {
88
        this(lookup, new ProjectTreeItemImpl());
81
        this(lookup, new ProjectTreeItemImpl());
89
    }
82
    }
90
    
83
91
    public UMLFolderNode(Children ch, Lookup lookup)
84
    public UMLFolderNode(Children ch, Lookup lookup) {
92
    {
93
        this(ch, lookup, new ProjectTreeItemImpl());
85
        this(ch, lookup, new ProjectTreeItemImpl());
94
    }
86
    }
95
    
87
96
    /**
88
    /**
97
     * @param item
89
     * @param item
98
     */
90
     */
99
    public UMLFolderNode(IProjectTreeItem item)
91
    public UMLFolderNode(IProjectTreeItem item) {
100
    {
101
        super(item);
92
        super(item);
102
    }
93
    }
103
    
94
104
    /**
95
    /**
105
     * @param item
96
     * @param item
106
     */
97
     */
107
    public UMLFolderNode(Lookup lookup, IProjectTreeItem item)
98
    public UMLFolderNode(Lookup lookup, IProjectTreeItem item) {
108
    {
109
        super(lookup, item);
99
        super(lookup, item);
110
    }
100
    }
111
    
101
112
    /**
102
    /**
113
     * @param item
103
     * @param item
114
     */
104
     */
115
    public UMLFolderNode(Children ch, Lookup lookup, IProjectTreeItem item)
105
    public UMLFolderNode(Children ch, Lookup lookup, IProjectTreeItem item) {
116
    {
117
        super(ch, lookup, item);
106
        super(ch, lookup, item);
118
    }
107
    }
119
    
108
120
   /* (non-Javadoc)
109
    /* (non-Javadoc)
121
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#addChild(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
110
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#addChild(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
122
    */
111
     */
123
    public void addChild(ITreeItem item)
112
    public void addChild(ITreeItem item) {
124
    {
125
        //        String yourID = item.getData().getModelElementXMIID();
113
        //        String yourID = item.getData().getModelElementXMIID();
126
        //        String myID = getData().getModelElementXMIID();
114
        //        String myID = getData().getModelElementXMIID();
127
        //        if(yourID.equals(myID) == false)
115
        //        if(yourID.equals(myID) == false)
Lines 129-179 Link Here
129
        super.addChild(item);
117
        super.addChild(item);
130
        //        }
118
        //        }
131
    }
119
    }
132
    
120
133
    public void setID(String id)
121
    public void setID(String id) {
134
    {
135
        m_ID = id;
122
        m_ID = id;
136
    }
123
    }
137
    
124
138
   /* (non-Javadoc)
125
    /* (non-Javadoc)
139
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#getID()
126
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#getID()
140
    */
127
     */
141
    public String getID()
128
    public String getID() {
142
    {
143
        return m_ID;
129
        return m_ID;
144
    }
130
    }
145
    
131
146
   /* (non-Javadoc)
132
    /* (non-Javadoc)
147
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setGetMethod(java.lang.String)
133
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setGetMethod(java.lang.String)
148
    */
134
     */
149
    public void setGetMethod(String name)
135
    public void setGetMethod(String name) {
150
    {
151
        m_GetMethodName = name;
136
        m_GetMethodName = name;
152
    }
137
    }
153
    
138
154
   /* (non-Javadoc)
139
    /* (non-Javadoc)
155
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#getGetMethod()
140
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#getGetMethod()
156
    */
141
     */
157
    public String getGetMethod()
142
    public String getGetMethod() {
158
    {
159
        return m_GetMethodName;
143
        return m_GetMethodName;
160
    }
144
    }
161
    
145
162
    /**
146
    /**
163
     * Sets the element that this tree folder represents.
147
     * Sets the element that this tree folder represents.
164
     *
148
     *
165
     * @param newVal The element that this folder represents
149
     * @param newVal The element that this folder represents
166
     */
150
     */
167
    public void setElement(IElement newVal)
151
    public void setElement(IElement newVal) {
168
    {
169
        IProjectTreeItem data = getData();
152
        IProjectTreeItem data = getData();
170
        if(data != null)
153
        if (data != null) {
171
        {
172
            data.setModelElement(newVal);
154
            data.setModelElement(newVal);
173
        }
155
        }
174
    }
156
    }
175
    
157
176
    
177
    /**
158
    /**
178
     * Get the new types that can be created in this node. For example, a node
159
     * Get the new types that can be created in this node. For example, a node
179
     * representing a class will permit attributes, operations, classes,
160
     * representing a class will permit attributes, operations, classes,
Lines 181-297 Link Here
181
     *
162
     *
182
     * @return An array of new type operations that are allowed.
163
     * @return An array of new type operations that are allowed.
183
     */
164
     */
184
    public NewType[] getNewTypes()
165
    public NewType[] getNewTypes() {
185
    {
186
        String elType = getElementType();
166
        String elType = getElementType();
187
        
167
188
        NewType[] retVal = null;
168
        NewType[] retVal = null;
189
        
169
190
        if (getModelElement() instanceof INamespace)
170
        if (getModelElement() instanceof INamespace) {
191
        {
192
            // Class types: Java Class
171
            // Class types: Java Class
193
            if (elType.equals(ELEMENT_TYPE_CLASS))
172
            if (elType.equals(ELEMENT_TYPE_CLASS)) {
194
            {
173
                if (getGetMethod().equals(METHOD_NAME_GET_OPERATIONS)) {
195
                if (getGetMethod().equals(METHOD_NAME_GET_OPERATIONS))
174
                    return new NewType[]{
196
                {
175
                                new NewOperationType(this)
197
                    return new NewType[]
176
                            };
198
                    {
177
                } else if (getGetMethod().equals(METHOD_NAME_GET_ATTRIBUTES)) {
199
                        new NewOperationType(this)
178
                    return new NewType[]{
200
                    };
179
                                new NewAttributeType(this)
180
                            };
201
                }
181
                }
202
                
182
            } else if (elType.equals(ELEMENT_TYPE_OPERATION)) {
203
                else if(getGetMethod().equals(METHOD_NAME_GET_ATTRIBUTES))
183
                return new NewType[]{
204
                {
184
                            new NewDiagramType(this),
205
                    return new NewType[]
185
                            new NewPackageType(this),
206
                    {
186
                            new NewElementType(this)
207
                        new NewAttributeType(this)
187
                        };
208
                    };
209
                }
210
            }
211
            
212
            else if (elType.equals(ELEMENT_TYPE_OPERATION))
213
            {
214
                return new NewType[]
215
                {
216
                    new NewDiagramType(this),
217
                    new NewPackageType(this),
218
                    new NewElementType(this)
219
                };
220
            }
188
            }
221
        } // if getModelElement() instanceof INamespace
189
        } // if getModelElement() instanceof INamespace
222
        
190
223
        if (retVal == null)
191
        if (retVal == null) {
224
        {
225
            retVal = new NewType[0];
192
            retVal = new NewType[0];
226
        }
193
        }
227
        
194
228
        return retVal;
195
        return retVal;
229
    }
196
    }
230
    
197
231
    
198
    public Action[] getActions(boolean context) {
232
    public Action[] getActions(boolean context)
233
    {
234
        String elemType = getElementType();
199
        String elemType = getElementType();
235
        if (elemType.equals(ELEMENT_TYPE_OPERATION) ||
200
        if (elemType.equals(ELEMENT_TYPE_OPERATION)
236
            elemType.equals(ELEMENT_TYPE_ATTRIBUTE) ||
201
                || elemType.equals(ELEMENT_TYPE_ATTRIBUTE)
237
            getName().equals("Operations") || // NOI18N
202
                || getName().equals("Operations") || // NOI18N
238
            getName().equals("Attributes")) // NOI18N
203
                getName().equals("Attributes")) // NOI18N
239
        {
204
        {
240
            return super.getNewMenuAction();
205
            return super.getNewMenuAction();
241
            // return new Action[]
206
            // return new Action[]
242
            // {
207
            // {
243
            //         SystemAction.get(NewAction.class)
208
            //         SystemAction.get(NewAction.class)
244
            // };
209
            // };
210
        } else {
211
            return new Action[]{null};
245
        }
212
        }
246
        
247
        else return new Action[]{null};
248
    }
213
    }
249
    
214
250
    public boolean canDestroy()
215
    public boolean canDestroy() {
251
    {
252
        return false;
216
        return false;
253
    }
217
    }
254
    
218
255
    /**
219
    /**
256
     * Returns the element that this tree folder represents.
220
     * Returns the element that this tree folder represents.
257
     *
221
     *
258
     * @return The element that this folder represents, or NULL
222
     * @return The element that this folder represents, or NULL
259
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#getElement()
223
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#getElement()
260
     */
224
     */
261
    public IElement getElement()
225
    public IElement getElement() {
262
    {
263
        IElement retVal = null;
226
        IElement retVal = null;
264
        
227
265
        IProjectTreeItem data = getData();
228
        IProjectTreeItem data = getData();
266
        if(data != null)
229
        if (data != null) {
267
        {
268
            retVal = data.getModelElement();
230
            retVal = data.getModelElement();
269
        }
231
        }
270
        
232
271
        return retVal;
233
        return retVal;
272
    }
234
    }
273
    
235
274
   /* (non-Javadoc)
236
    /* (non-Javadoc)
275
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setPath(java.lang.String)
237
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setPath(java.lang.String)
276
    */
238
     */
277
    public void setPath(ITreeItem[] defPath)
239
    public void setPath(ITreeItem[] defPath) {
278
    {
279
        IProjectTreeItem data = getData();
240
        IProjectTreeItem data = getData();
280
        if(data != null)
241
        if (data != null) {
281
        {
282
            data.setPath(defPath);
242
            data.setPath(defPath);
283
        }
243
        }
284
    }
244
    }
285
    
245
286
   /* (non-Javadoc)
246
    /* (non-Javadoc)
287
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setIsGetMethodAnImport(boolean)
247
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setIsGetMethodAnImport(boolean)
288
    */
248
     */
289
    public void setIsGetMethodAnImport(boolean value)
249
    public void setIsGetMethodAnImport(boolean value) {
290
    {
291
        
292
        
293
    }
250
    }
294
    
251
295
    /**
252
    /**
296
     * Is the get method the one used to get imported packages or elements?
253
     * Is the get method the one used to get imported packages or elements?
297
     *
254
     *
Lines 299-398 Link Here
299
     *        imports.
256
     *        imports.
300
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#isGetMethodAnImport()
257
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#isGetMethodAnImport()
301
     */
258
     */
302
    public boolean isGetMethodAnImport()
259
    public boolean isGetMethodAnImport() {
303
    {
304
        boolean retVal = false;
260
        boolean retVal = false;
305
        if((getGetMethod().equals("ImportedElements") == true) || // NOI18N
261
        if ((getGetMethod().equals("ImportedElements") == true) || // NOI18N
306
            (getGetMethod().equals("ImportedPackages") == true))  // NOI18N
262
                (getGetMethod().equals("ImportedPackages") == true)) // NOI18N
307
        {
263
        {
308
            retVal = true;
264
            retVal = true;
309
        }
265
        }
310
        
266
311
        return retVal;
267
        return retVal;
312
    }
268
    }
313
    
269
314
    /**
270
    /**
315
     * Is the get method the one used to get imported elements?
271
     * Is the get method the one used to get imported elements?
316
     *
272
     *
317
     * @return <b>true</b> if the get method is an import, <b>false</b>
273
     * @return <b>true</b> if the get method is an import, <b>false</b>
318
     *         if the get method is not an import.
274
     *         if the get method is not an import.
319
     */
275
     */
320
    public boolean isGetMethodAnImportElement()
276
    public boolean isGetMethodAnImportElement() {
321
    {
322
        boolean retVal = false;
277
        boolean retVal = false;
323
        if(getGetMethod().equals("ImportedElements")) // NOI18N
278
        if (getGetMethod().equals("ImportedElements")) // NOI18N
324
        {
279
        {
325
            retVal = true;
280
            retVal = true;
326
        }
281
        }
327
        
282
328
        return retVal;
283
        return retVal;
329
    }
284
    }
330
    
285
331
    /**
286
    /**
332
     * Is the get method the one used to get imported packages?
287
     * Is the get method the one used to get imported packages?
333
     *
288
     *
334
     * @return <b>true</b> if the get method is an import, <b>false</b>
289
     * @return <b>true</b> if the get method is an import, <b>false</b>
335
     *         if the get method is not an import.
290
     *         if the get method is not an import.
336
     */
291
     */
337
    public boolean isGetMethodAnImportPackage()
292
    public boolean isGetMethodAnImportPackage() {
338
    {
339
        boolean retVal = false;
293
        boolean retVal = false;
340
        if(getGetMethod().equals("ImportedPackages")) // NOI18N
294
        if (getGetMethod().equals("ImportedPackages")) // NOI18N
341
        {
295
        {
342
            retVal = true;
296
            retVal = true;
343
        }
297
        }
344
        
298
345
        return retVal;
299
        return retVal;
346
    }
300
    }
347
    
301
348
    public String getType()
302
    public String getType() {
349
    {
350
        return getName();
303
        return getName();
351
    }
304
    }
352
   /* (non-Javadoc)
305
    /* (non-Javadoc)
353
    * @see java.lang.Object#equals(java.lang.Object)
306
     * @see java.lang.Object#equals(java.lang.Object)
354
    */
307
     */
355
    public boolean equals(Object obj)
308
356
    {
309
    public boolean equals(Object obj) {
357
        boolean retVal = false;
310
        boolean retVal = false;
358
        
311
359
        if (obj instanceof ITreeFolder)
312
        if (obj instanceof ITreeFolder) {
360
        {
313
            ITreeFolder folder = (ITreeFolder) obj;
361
            ITreeFolder folder = (ITreeFolder)obj;
314
362
            
315
            if ((getDisplayName() != null) && (folder.getDisplayName() != null)) {
363
            if((getDisplayName() != null) && (folder.getDisplayName() != null))
316
                if (getDisplayName().equals(folder.getDisplayName()) == true) {
364
            {
317
                    if ((getID() == null) && (folder.getID() == null)) {
365
                if(getDisplayName().equals(folder.getDisplayName()) == true)
366
                {
367
                    if((getID() == null) && (folder.getID() == null))
368
                    {
369
                        retVal = true;
318
                        retVal = true;
370
                    }
319
                    } else if ((getID() != null) && (folder.getID() != null)) {
371
                    else if((getID() != null) && (folder.getID() != null))
372
                    {
373
                        retVal = getID().equals(folder.getID());
320
                        retVal = getID().equals(folder.getID());
374
                    }
321
                    }
375
                }
322
                }
376
            }
323
            }
377
        }
324
        }
378
        
325
379
        return retVal;
326
        return retVal;
380
    }
327
    }
381
    
328
382
    public void setName(String val)
329
    public void setName(String val) {
383
    {
384
        m_Name = val;
330
        m_Name = val;
385
        super.setName(val);
331
        super.setName(val);
386
    }
332
    }
387
    
333
388
    public String getName()
334
    public String getName() {
389
    {
390
        return m_Name;
335
        return m_Name;
391
    }
336
    }
392
337
393
    
338
    public boolean canRename() {
394
    public boolean canRename()
395
    {
396
        return false;
339
        return false;
397
    }
340
    }
398
}
341
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLModelElementNode.java (-342 / +253 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
47
45
48
import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
46
import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
Lines 81-178 Link Here
81
import org.openide.util.NbBundle;
79
import org.openide.util.NbBundle;
82
import org.openide.util.datatransfer.NewType;
80
import org.openide.util.datatransfer.NewType;
83
81
84
85
86
/**
82
/**
87
 *
83
 *
88
 * @author Trey Spiva
84
 * @author Trey Spiva
89
 */
85
 */
90
public class UMLModelElementNode extends UMLElementNode
86
public class UMLModelElementNode extends UMLElementNode
91
    implements ITreeElement, INamedElementEventsSink, IElementLifeTimeEventsSink
87
        implements ITreeElement, INamedElementEventsSink, IElementLifeTimeEventsSink {
92
{
88
93
    
94
    private String m_ExpandedElementType = "";
89
    private String m_ExpandedElementType = "";
95
    private boolean m_bTranslateName = false;
90
    private boolean m_bTranslateName = false;
96
    private DocumentationCookie mDocCookie = null;
91
    private DocumentationCookie mDocCookie = null;
97
92
98
    
93
    public UMLModelElementNode() {
99
    public UMLModelElementNode()
100
    {
101
        super();
94
        super();
102
        initCookies();
95
        initCookies();
103
        initialize();
96
        initialize();
104
    }
97
    }
105
    
98
106
    public UMLModelElementNode(Lookup lookup)
99
    public UMLModelElementNode(Lookup lookup) {
107
    {
108
        super(lookup);
100
        super(lookup);
109
        initialize();
101
        initialize();
110
    }
102
    }
111
    
103
112
    public UMLModelElementNode(Children ch, Lookup lookup)
104
    public UMLModelElementNode(Children ch, Lookup lookup) {
113
    {
114
        super(ch, lookup);
105
        super(ch, lookup);
115
        initialize();
106
        initialize();
116
    }
107
    }
117
    
108
118
    
119
    /**
109
    /**
120
     * @param item
110
     * @param item
121
     * @throws NullPointerException
111
     * @throws NullPointerException
122
     */
112
     */
123
    public UMLModelElementNode(IProjectTreeItem item) throws NullPointerException
113
    public UMLModelElementNode(IProjectTreeItem item) throws NullPointerException {
124
    {
125
        super(item);
114
        super(item);
126
        initialize();
115
        initialize();
127
    }
116
    }
128
    
117
129
    /**
118
    /**
130
     * @param item
119
     * @param item
131
     * @throws NullPointerException
120
     * @throws NullPointerException
132
     */
121
     */
133
    public UMLModelElementNode(Lookup lookup, IProjectTreeItem item)
122
    public UMLModelElementNode(Lookup lookup, IProjectTreeItem item)
134
        throws NullPointerException
123
            throws NullPointerException {
135
    {
136
        super(lookup, item);
124
        super(lookup, item);
137
        initialize();
125
        initialize();
138
    }
126
    }
139
    
127
140
    private void initialize()
128
    private void initialize() {
141
    {
142
        DispatchHelper helper = new DispatchHelper();
129
        DispatchHelper helper = new DispatchHelper();
143
        helper.registerForNamedElementEvents(this);
130
        helper.registerForNamedElementEvents(this);
144
        helper.registerForLifeTimeEvents(this);
131
        helper.registerForLifeTimeEvents(this);
145
    }
132
    }
146
    
133
147
    /**
134
    /**
148
     * Initializes the node with the default cookies.  <b>Note:</b>  Do not
135
     * Initializes the node with the default cookies.  <b>Note:</b>  Do not
149
     * call this method if a looup is added.  When a lookup is added then the
136
     * call this method if a looup is added.  When a lookup is added then the
150
     * lookup is used to find the cookies.
137
     * lookup is used to find the cookies.
151
     */
138
     */
152
    protected void initCookies()
139
    protected void initCookies() {
153
    {
154
        super.initCookies();
140
        super.initCookies();
155
        
141
156
        Class[] cookies = {DocumentationCookie.class};
142
        Class[] cookies = {DocumentationCookie.class};
157
        getCookieSet().add(cookies, this);
143
        getCookieSet().add(cookies, this);
158
    }
144
    }
159
    
145
160
    public org.openide.nodes.Node.Cookie createCookie(Class klass)
146
    public org.openide.nodes.Node.Cookie createCookie(Class klass) {
161
    {
162
        org.openide.nodes.Node.Cookie retVal = super.createCookie(klass);
147
        org.openide.nodes.Node.Cookie retVal = super.createCookie(klass);
163
        
148
164
        if(DocumentationCookie.class.equals(klass) == true)
149
        if (DocumentationCookie.class.equals(klass) == true) {
165
        {
150
            if (mDocCookie == null) {
166
            if(mDocCookie  == null)
167
            {
168
                mDocCookie = new ElementDocumentationCookie();
151
                mDocCookie = new ElementDocumentationCookie();
169
            }
152
            }
170
            retVal = mDocCookie;
153
            retVal = mDocCookie;
171
        }
154
        }
172
        return retVal;
155
        return retVal;
173
    }
156
    }
174
    
157
175
    
176
    /**
158
    /**
177
     * Get the new types that can be created in this node. For example, a node
159
     * Get the new types that can be created in this node. For example, a node
178
     * representing a class will permit attributes, operations, classes,
160
     * representing a class will permit attributes, operations, classes,
Lines 180-474 Link Here
180
     *
162
     *
181
     * @return An array of new type operations that are allowed.
163
     * @return An array of new type operations that are allowed.
182
     */
164
     */
183
    public NewType[] getNewTypes()
165
    public NewType[] getNewTypes() {
184
    {
185
        String elType = getElementType();
166
        String elType = getElementType();
186
        NewType[] retVal = null;
167
        NewType[] retVal = null;
187
        
168
188
        if (getModelElement() instanceof INamespace)
169
        if (getModelElement() instanceof INamespace) {
189
        {
170
            if (elType.equals(ELEMENT_TYPE_CLASS)
190
            if (elType.equals(ELEMENT_TYPE_CLASS) ||
171
                    || elType.equals(ELEMENT_TYPE_INTERFACE)
191
                elType.equals(ELEMENT_TYPE_INTERFACE) ||
172
                    || elType.equals(ELEMENT_TYPE_DATA_TYPE)
192
                elType.equals(ELEMENT_TYPE_DATA_TYPE)||
173
                    || elType.equals(ELEMENT_TYPE_PART_FACADE)) {
193
                elType.equals(ELEMENT_TYPE_PART_FACADE))
174
                return new NewType[]{
194
            {
175
                            new NewDiagramType(this),
195
                return new NewType[]
176
                            new NewPackageType(this),
196
                {
177
                            new NewElementType(this),
197
                    new NewDiagramType(this),
178
                            new NewAttributeType(this),
198
                    new NewPackageType(this),
179
                            new NewOperationType(this)
199
                    new NewElementType(this),
180
                        };
200
                    new NewAttributeType(this),
181
            } else if (elType.equals(ELEMENT_TYPE_ENUMERATION)) {
201
                    new NewOperationType(this)
182
                return new NewType[]{
202
                };
183
                            new NewDiagramType(this),
203
            }
184
                            new NewPackageType(this),
204
            else if(elType.equals(ELEMENT_TYPE_ENUMERATION))
185
                            new NewElementType(this),
205
            {
186
                            new NewLiteralType((this)),
206
                return new NewType[]
187
                            new NewAttributeType(this),
207
                {
188
                            new NewOperationType(this)
208
                    new NewDiagramType(this),
189
                        };
209
                    new NewPackageType(this),
190
            } else if (elType.equals(ELEMENT_TYPE_ACTIVITY)
210
                    new NewElementType(this),
191
                    || elType.equals(ELEMENT_TYPE_INTERACTION)
211
                    new NewLiteralType((this)),
192
                    || elType.equals(ELEMENT_TYPE_STATE_MACHINE)
212
                    new NewAttributeType(this),
193
                    || elType.equals(ELEMENT_TYPE_PACKAGE)
213
                    new NewOperationType(this)
194
                    || elType.equals(ELEMENT_TYPE_OPERATION)
214
                };
195
                    || //		elType.equals(ELEMENT_TYPE_PART_FACADE) ||
215
            }
196
                    elType.equals(ELEMENT_TYPE_ARTIFACT)
216
            else if (elType.equals(ELEMENT_TYPE_ACTIVITY) ||
197
                    || elType.equals(ELEMENT_TYPE_NODE)
217
                elType.equals(ELEMENT_TYPE_INTERACTION) ||
198
                    || elType.equals(ELEMENT_TYPE_DERIVATION_CLASSIFIER)
218
                elType.equals(ELEMENT_TYPE_STATE_MACHINE) ||
199
                    || elType.equals(ELEMENT_TYPE_COLLABORATION)) {
219
                elType.equals(ELEMENT_TYPE_PACKAGE) ||
200
                return new NewType[]{
220
                elType.equals(ELEMENT_TYPE_OPERATION) ||
201
                            new NewDiagramType(this),
221
//		elType.equals(ELEMENT_TYPE_PART_FACADE) ||
202
                            new NewPackageType(this),
222
                elType.equals(ELEMENT_TYPE_ARTIFACT) ||
203
                            new NewElementType(this)
223
                elType.equals(ELEMENT_TYPE_NODE) ||
204
                        };
224
                elType.equals(ELEMENT_TYPE_DERIVATION_CLASSIFIER) ||
225
                elType.equals(ELEMENT_TYPE_COLLABORATION))
226
            {
227
                return new NewType[]
228
                {
229
                    new NewDiagramType(this),
230
                    new NewPackageType(this),
231
                    new NewElementType(this)
232
                };
233
            }
205
            }
234
        } // if getModelElement() instanceof INamespace
206
        } // if getModelElement() instanceof INamespace
235
        
207
236
        // The NewAction code does not check for null.  Therefore, we have
208
        // The NewAction code does not check for null.  Therefore, we have
237
        // to create a new object just to keep them from throwing.
209
        // to create a new object just to keep them from throwing.
238
        if (retVal == null)
210
        if (retVal == null) {
239
            retVal = new NewType[0];
211
            retVal = new NewType[0];
240
        
212
        }
213
241
        return retVal;
214
        return retVal;
242
    }
215
    }
243
    
216
244
    
217
    public boolean canRename() {
245
    public boolean canRename()
246
    {
247
        String eleType = getElementType();
218
        String eleType = getElementType();
248
        
219
249
        // these element type nodes cannot be renamed
220
        // these element type nodes cannot be renamed
250
        if (eleType.equals(ELEMENT_TYPE_SOURCE_FILE_ARTIFACT) ||
221
        if (eleType.equals(ELEMENT_TYPE_SOURCE_FILE_ARTIFACT)
251
            eleType.equals(ELEMENT_TYPE_DEPENDENCY) ||
222
                || eleType.equals(ELEMENT_TYPE_DEPENDENCY)
252
            eleType.equals(ELEMENT_TYPE_REALIZATION) ||
223
                || eleType.equals(ELEMENT_TYPE_REALIZATION)
253
            eleType.equals(ELEMENT_TYPE_USAGE) ||
224
                || eleType.equals(ELEMENT_TYPE_USAGE)
254
            eleType.equals(ELEMENT_TYPE_PERMISSION) ||
225
                || eleType.equals(ELEMENT_TYPE_PERMISSION)
255
            eleType.equals(ELEMENT_TYPE_ABSTRACTION) ||
226
                || eleType.equals(ELEMENT_TYPE_ABSTRACTION)
256
            eleType.equals(ELEMENT_TYPE_GENERALIZATION) ||
227
                || eleType.equals(ELEMENT_TYPE_GENERALIZATION)
257
            eleType.equals(ELEMENT_TYPE_ASSOCIATION) ||
228
                || eleType.equals(ELEMENT_TYPE_ASSOCIATION)
258
            eleType.equals(ELEMENT_TYPE_AGGREGATION))
229
                || eleType.equals(ELEMENT_TYPE_AGGREGATION)) {
259
        {
260
            return false;
230
            return false;
261
        }
231
        }
262
        
232
263
        // all other element type nodes can be renamed
233
        // all other element type nodes can be renamed
264
        return true;
234
        return true;
265
    }
235
    }
266
    
236
267
    
237
    public void setName(String val) {
268
    public void setName(String val)
269
    {
270
        IElement element = getElement();
238
        IElement element = getElement();
271
        
239
272
        if (element==null)
240
        if (element == null) {
273
        {
274
            super.setName(val);
241
            super.setName(val);
275
            return;
242
            return;
276
        }
243
        }
277
        
244
278
        if (element instanceof ILifeline)
245
        if (element instanceof ILifeline) {
279
        {
280
            ILifeline lifeline = (ILifeline) element;
246
            ILifeline lifeline = (ILifeline) element;
281
            String name = lifeline.getName();
247
            String name = lifeline.getName();
282
            IClassifier classifier = lifeline.getRepresentingClassifier();
248
            IClassifier classifier = lifeline.getRepresentingClassifier();
283
            
249
284
            String rcName = classifier == null 
250
            String rcName = classifier == null
285
                ? "" // NOI18N
251
                    ? "" // NOI18N
286
                : classifier.getFullyQualifiedName(true);
252
                    : classifier.getFullyQualifiedName(true);
287
            
253
288
            String oldName = name + " : " + rcName;
254
            String oldName = name + " : " + rcName;
289
            
255
290
            if (oldName.equals(val))
256
            if (oldName.equals(val)) {
291
                return;
257
                return;
292
            
258
            }
259
293
            String newName = null;
260
            String newName = null;
294
            String newRCName = null;
261
            String newRCName = null;
295
            int index = val.indexOf(" : ");
262
            int index = val.indexOf(" : ");
296
263
297
            if (index > -1)
264
            if (index > -1) {
298
            {
299
                newName = val.substring(0, index).trim();
265
                newName = val.substring(0, index).trim();
300
                newRCName = val.substring(index + 3, val.length()).trim();
266
                newRCName = val.substring(index + 3, val.length()).trim();
267
            } else {
268
                newName = val;
301
            }
269
            }
302
            
303
            else
304
                newName = val;
305
270
306
            lifeline.setName(newName);
271
            lifeline.setName(newName);
307
            
272
308
            if (newRCName != null)
273
            if (newRCName != null) {
309
                lifeline.setRepresentingClassifier2(newRCName);
274
                lifeline.setRepresentingClassifier2(newRCName);
275
            } else {
276
                newRCName = rcName;
277
            }
310
278
311
            else
312
                newRCName = rcName;
313
            
314
            lifeline.setDirty(true);
279
            lifeline.setDirty(true);
315
            String n = newName + " : " + newRCName;
280
            String n = newName + " : " + newRCName;
316
            
281
317
            super.setName(n);
282
            super.setName(n);
318
            
283
319
            if (getData() != null)
284
            if (getData() != null) {
320
                getData().setItemText(n);
285
                getData().setItemText(n);
321
            
286
            }
287
322
            setDisplayName(n);
288
            setDisplayName(n);
323
        }
289
        } else if (element instanceof INamedElement) {
290
            String oldName = ((INamedElement) element).getName();
324
291
325
        else if (element instanceof INamedElement)
292
            if (oldName.equals(val)) {
326
        {   
327
            String oldName = ((INamedElement)element).getName();
328
            
329
            if (oldName.equals(val))
330
                return;
293
                return;
331
            
294
            }
332
			if (Util.hasNameCollision(getModelElement().getOwningPackage(), 
295
333
					val, getModelElement().getElementType(), (INamedElement)getModelElement()))
296
            if (Util.hasNameCollision(getModelElement().getOwningPackage(),
334
			{
297
                    val, getModelElement().getElementType(), (INamedElement) getModelElement())) {
335
				DialogDisplayer.getDefault().notify(
298
                DialogDisplayer.getDefault().notify(
336
						new NotifyDescriptor.Message(NbBundle.getMessage(
299
                        new NotifyDescriptor.Message(NbBundle.getMessage(
337
						NewElementUI.class, "IDS_NAMESPACECOLLISION")));
300
                        NewElementUI.class, "IDS_NAMESPACECOLLISION")));
338
				return;
301
                return;
339
			}
302
            }
340
			
303
341
            JavaRequestProcessor p = new JavaRequestProcessor();
304
            JavaRequestProcessor p = new JavaRequestProcessor();
342
        
305
343
            if (p.isNewNameValid(((INamedElement)element), val))
306
            if (p.isNewNameValid(((INamedElement) element), val)) {
344
            {
307
                ((INamedElement) element).setName(val);
345
                ((INamedElement)element).setName(val);
308
346
                
347
                // if (the name wasn't allowed to be changed for the element,
309
                // if (the name wasn't allowed to be changed for the element,
348
                // then abort the name change for the node
310
                // then abort the name change for the node
349
                if (!((INamedElement)element).getName().equals(val))
311
                if (!((INamedElement) element).getName().equals(val)) {
350
                    return;
312
                    return;
313
                }
351
314
352
                // element name was changed successfully, 
315
                // element name was changed successfully, 
353
                // continue with node name change
316
                // continue with node name change
354
                element.setDirty(true);
317
                element.setDirty(true);
355
                super.setName(val);
318
                super.setName(val);
356
            
319
357
                if (getData() != null)
320
                if (getData() != null) {
358
                    getData().setItemText(val);
321
                    getData().setItemText(val);
359
        
322
                }
323
360
                // setDisplayName(val);
324
                // setDisplayName(val);
361
            }
325
            }
362
        }
326
        }
363
        
327
364
        firePropertySetsChange(null, retreiveProperties());
328
        firePropertySetsChange(null, retreiveProperties());
365
    }
329
    }
366
    
330
367
    
331
    public void setElement(IElement element) {
368
    public void setElement(IElement element)
369
    {
370
        //m_ExpandedElementType = "";
332
        //m_ExpandedElementType = "";
371
        if (element != null)
333
        if (element != null) {
372
        {
373
            m_ExpandedElementType = element.getExpandedElementType();
334
            m_ExpandedElementType = element.getExpandedElementType();
374
            addElementCookie(element);
335
            addElementCookie(element);
375
        }
336
        }
376
        
337
377
        if (getData() != null)
338
        if (getData() != null) {
378
            getData().setModelElement(element);
339
            getData().setModelElement(element);
340
        }
379
    }
341
    }
380
    
342
381
    protected void addElementCookie(IElement element)
343
    protected void addElementCookie(IElement element) {
382
    {
383
        getCookieSet().add(element);
344
        getCookieSet().add(element);
384
    }
345
    }
385
    
346
386
    
347
    /* (non-Javadoc)
387
    
348
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeElement#getElement()
388
   /* (non-Javadoc)
349
     */
389
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeElement#getElement()
350
    public IElement getElement() {
390
    */
391
    public IElement getElement()
392
    {
393
        //System.out.print("Retrieving Element: ");
351
        //System.out.print("Retrieving Element: ");
394
        IElement retVal = null;
352
        IElement retVal = null;
395
        
353
396
        if (getData() != null)
354
        if (getData() != null) {
397
        {
398
            retVal = getData().getModelElement();
355
            retVal = getData().getModelElement();
399
        }
356
        }
400
        
357
401
        //System.out.println(retVal.toString());
358
        //System.out.println(retVal.toString());
402
        return retVal;
359
        return retVal;
403
    }
360
    }
404
    
361
405
   /* (non-Javadoc)
362
    /* (non-Javadoc)
406
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeElement#getXMIID()
363
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeElement#getXMIID()
407
    */
364
     */
408
    public String getXMIID()
365
    public String getXMIID() {
409
    {
410
        String retVal = null;
366
        String retVal = null;
411
        
367
412
        if (getData() != null)
368
        if (getData() != null) {
413
        {
414
            retVal = getData().getModelElementXMIID();
369
            retVal = getData().getModelElementXMIID();
415
        }
370
        }
416
        return retVal;
371
        return retVal;
417
    }
372
    }
418
    
373
419
   /* (non-Javadoc)
374
    /* (non-Javadoc)
420
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeElement#getElementType()
375
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeElement#getElementType()
421
    */
376
     */
422
    public String getElementType()
377
    public String getElementType() {
423
    {
424
        String retVal = null;
378
        String retVal = null;
425
        
379
426
        if (getData() != null)
380
        if (getData() != null) {
427
        {
428
            retVal = getData().getModelElementMetaType();
381
            retVal = getData().getModelElementMetaType();
429
        }
382
        }
430
        return retVal;
383
        return retVal;
431
    }
384
    }
432
    
385
433
   /* (non-Javadoc)
386
    /* (non-Javadoc)
434
    * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeElement#getExpandedElementType()
387
     * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeElement#getExpandedElementType()
435
    */
388
     */
436
    public String getExpandedElementType()
389
    public String getExpandedElementType() {
437
    {
438
        return m_ExpandedElementType;
390
        return m_ExpandedElementType;
439
    }
391
    }
440
    
392
441
   /* (non-Javadoc)
393
    /* (non-Javadoc)
442
    * @see java.lang.Object#equals(java.lang.Object)
394
     * @see java.lang.Object#equals(java.lang.Object)
443
    */
395
     */
444
    public boolean equals(Object obj)
396
    public boolean equals(Object obj) {
445
    {
446
        boolean retVal = false;
397
        boolean retVal = false;
447
398
448
        if (this.hashCode() == obj.hashCode())
399
        if (this.hashCode() == obj.hashCode()) {
449
            return true;
400
            return true;
450
		
401
        }
451
        if (obj instanceof ITreeElement)
402
452
        {
403
        if (obj instanceof ITreeElement) {
453
            IElement myElement = getData().getModelElement();
404
            IElement myElement = getData().getModelElement();
454
            ITreeElement objElement = (ITreeElement)obj;
405
            ITreeElement objElement = (ITreeElement) obj;
455
            
406
456
            if ((myElement != null) && (objElement.getElement() != null))
407
            if ((myElement != null) && (objElement.getElement() != null)) {
457
            {
458
                retVal = myElement.isSame(objElement.getElement());
408
                retVal = myElement.isSame(objElement.getElement());
459
                if (retVal == false && getData().getModelElementMetaType()
409
                if (retVal == false && getData().getModelElementMetaType().equals("DerivationClassifier")) {
460
                    .equals("DerivationClassifier"))
461
                {
462
                    retVal = getDisplayedName().equals(objElement.getDisplayedName());
410
                    retVal = getDisplayedName().equals(objElement.getDisplayedName());
463
                }
411
                }
464
            }
412
            } else if ((myElement == null) && (objElement.getElement() == null)) {
465
            
466
            else if ((myElement == null) && (objElement.getElement() == null))
467
            {
468
                retVal = super.equals(obj);
413
                retVal = super.equals(obj);
469
                
414
470
                if (retVal == false)
415
                if (retVal == false) {
471
                {
472
                    // getDisplayedName sometimes null for DiagramTopComponent's
416
                    // getDisplayedName sometimes null for DiagramTopComponent's
473
                    // local node, and all DTC local nodes have an empty string
417
                    // local node, and all DTC local nodes have an empty string
474
                    // name, so we must do a obj ref equality
418
                    // name, so we must do a obj ref equality
Lines 477-526 Link Here
477
                    retVal = this == objElement;
421
                    retVal = this == objElement;
478
                }
422
                }
479
            }
423
            }
480
            
424
481
        }
425
        } else {
482
        
483
        else
484
        { 
485
            // Generic equals method. This can be used to test to ITreeItem(s).
426
            // Generic equals method. This can be used to test to ITreeItem(s).
486
            retVal = super.equals(obj);
427
            retVal = super.equals(obj);
487
        }
428
        }
488
        
429
489
        return retVal;
430
        return retVal;
490
    }
431
    }
491
    
432
492
    /**
433
    /**
493
     * Retrieves the meta-data type name.
434
     * Retrieves the meta-data type name.
494
     *
435
     *
495
     * @return The type name.
436
     * @return The type name.
496
     */
437
     */
497
    public String getType()
438
    public String getType() {
498
    {
499
        String retVal = null;
439
        String retVal = null;
500
        
440
501
        if (getData() != null)
441
        if (getData() != null) {
502
        {
503
            retVal = getData().getModelElementMetaType();
442
            retVal = getData().getModelElementMetaType();
504
        }
443
        }
505
        return retVal;
444
        return retVal;
506
    }
445
    }
507
    
446
508
    /**
447
    /**
509
     * Retrieves the XML nodes associated to the UML model element.
448
     * Retrieves the XML nodes associated to the UML model element.
510
     *
449
     *
511
     * @return The XML node.
450
     * @return The XML node.
512
     */
451
     */
513
    public Node getXMLNode()
452
    public Node getXMLNode() {
514
    {
515
        Node pVal = null;
453
        Node pVal = null;
516
        IElement pElement = getElement();
454
        IElement pElement = getElement();
517
        if (pElement != null)
455
        if (pElement != null) {
518
        {
519
            pVal = pElement.getNode();
456
            pVal = pElement.getNode();
520
        }
457
        }
521
        return pVal;
458
        return pVal;
522
    }
459
    }
523
    
460
524
    /**
461
    /**
525
     * Determines if the ConfigStringTranslator should be used to translate the
462
     * Determines if the ConfigStringTranslator should be used to translate the
526
     * name of the node.  The ConfigStringTranslator is used to translate
463
     * name of the node.  The ConfigStringTranslator is used to translate
Lines 528-538 Link Here
528
     *
465
     *
529
     * @return <b>true</b> if the name is to be translated.
466
     * @return <b>true</b> if the name is to be translated.
530
     */
467
     */
531
    public boolean getTranslateName()
468
    public boolean getTranslateName() {
532
    {
533
        return m_bTranslateName;
469
        return m_bTranslateName;
534
    }
470
    }
535
    
471
536
    /**
472
    /**
537
     * Determines if the ConfigStringTranslator should be used to translate the
473
     * Determines if the ConfigStringTranslator should be used to translate the
538
     * name of the node.  The ConfigStringTranslator is used to translate
474
     * name of the node.  The ConfigStringTranslator is used to translate
Lines 540-560 Link Here
540
     *
476
     *
541
     * @param val <b>true</b> if the name is to be translated.
477
     * @param val <b>true</b> if the name is to be translated.
542
     */
478
     */
543
    public void setTranslateName(boolean val)
479
    public void setTranslateName(boolean val) {
544
    {
545
        m_bTranslateName = val;
480
        m_bTranslateName = val;
546
    }
481
    }
547
    
482
548
    /**
483
    /**
549
     * Retrieves the user friendly name for the model element.
484
     * Retrieves the user friendly name for the model element.
550
     *
485
     *
551
     * @return The display namne.
486
     * @return The display namne.
552
     */
487
     */
553
    public String getDisplayedName()
488
    public String getDisplayedName() {
554
    {
555
        return getDisplayName();
489
        return getDisplayName();
556
    }
490
    }
557
    
491
558
    /**
492
    /**
559
     * Retrieves the user friendly name for the model element.  The name is
493
     * Retrieves the user friendly name for the model element.  The name is
560
     * translated if required.
494
     * translated if required.
Lines 562-709 Link Here
562
     * @return The display namne.
496
     * @return The display namne.
563
     * @see #getTranslateName()
497
     * @see #getTranslateName()
564
     */
498
     */
565
    public String getDisplayName()
499
    public String getDisplayName() {
566
    {
567
        String pVal = "";
500
        String pVal = "";
568
        if (!getTranslateName())
501
        if (!getTranslateName()) {
569
        {
570
            pVal = super.getDisplayName();
502
            pVal = super.getDisplayName();
571
        }
503
        } else {
572
        else
573
        {
574
            // Try translating the name first
504
            // Try translating the name first
575
            IConfigStringTranslator pTranslator = new ConfigStringTranslator();
505
            IConfigStringTranslator pTranslator = new ConfigStringTranslator();
576
            if (pTranslator != null)
506
            if (pTranslator != null) {
577
            {
578
                String displayName = super.getDisplayName();
507
                String displayName = super.getDisplayName();
579
                pVal = pTranslator.translateWord(displayName);
508
                pVal = pTranslator.translateWord(displayName);
580
                if((pVal == null) || (pVal.length() <= 0))
509
                if ((pVal == null) || (pVal.length() <= 0)) {
581
                {
582
                    pVal = displayName;
510
                    pVal = displayName;
583
                }
511
                }
584
            }
512
            }
585
        }
513
        }
586
        return pVal;
514
        return pVal;
587
    }
515
    }
588
    
516
589
    ////////////////////////////////////////////////
517
    ////////////////////////////////////////////////
590
    // Implementations of INamedElementEventsSink
518
    // Implementations of INamedElementEventsSink
591
    
519
    public void onVisibilityModified(INamedElement element, IResultCell cell) {
592
    public void onVisibilityModified(INamedElement element, IResultCell cell)
593
    {
594
    }
520
    }
595
    
521
596
    public void onPreVisibilityModified(
522
    public void onPreVisibilityModified(
597
        INamedElement element, int proposedValue, IResultCell cell)
523
            INamedElement element, int proposedValue, IResultCell cell) {
598
    {
599
    }
524
    }
600
    
525
601
    public void onPreNameModified(
526
    public void onPreNameModified(
602
        INamedElement element, String proposedName, IResultCell cell)
527
            INamedElement element, String proposedName, IResultCell cell) {
603
    {
604
    }
528
    }
605
    
529
606
    public void onPreNameCollision(
530
    public void onPreNameCollision(
607
        INamedElement element, 
531
            INamedElement element,
608
        String proposedName, 
532
            String proposedName,
609
        ETList<INamedElement> collidingElements, 
533
            ETList<INamedElement> collidingElements,
610
        IResultCell cell)
534
            IResultCell cell) {
611
    {
612
    }
535
    }
613
    
536
614
    public void onPreAliasNameModified(
537
    public void onPreAliasNameModified(
615
        INamedElement element, 
538
            INamedElement element,
616
        String proposedName, 
539
            String proposedName,
617
        IResultCell cell)
540
            IResultCell cell) {
618
    {
619
    }
541
    }
620
    
542
621
    public void onNameModified(INamedElement element, IResultCell cell)
543
    public void onNameModified(INamedElement element, IResultCell cell) {
622
    {
544
        if (element.isSame(this.getElement())) {
623
         if (element.isSame(this.getElement()))
545
            if (!getName().equals(element.getName())) {
624
        {
625
            if (!getName().equals(element.getName()))
626
                setName(element.getName());
546
                setName(element.getName());
547
            }
627
        }
548
        }
628
    }
549
    }
629
    
550
630
    public void onNameCollision(
551
    public void onNameCollision(
631
        INamedElement element, 
552
            INamedElement element,
632
        ETList<INamedElement> collidingElements, 
553
            ETList<INamedElement> collidingElements,
633
        IResultCell cell)
554
            IResultCell cell) {
634
    {
635
    }
555
    }
636
    
556
637
    public void onAliasNameModified(INamedElement element, IResultCell cell)
557
    public void onAliasNameModified(INamedElement element, IResultCell cell) {
638
    {
639
    }
558
    }
640
    
559
641
    
560
    public class ElementDocumentationCookie implements DocumentationCookie {
642
    
561
643
    public class ElementDocumentationCookie implements DocumentationCookie
644
    {
645
        /**
562
        /**
646
         * Retreive the documentation from the node.
563
         * Retreive the documentation from the node.
647
         */
564
         */
648
        public String getDocumentation()
565
        public String getDocumentation() {
649
        {
650
            String retVal = "";
566
            String retVal = "";
651
            
567
652
            IElement element = getModelElement();
568
            IElement element = getModelElement();
653
            if (element != null)
569
            if (element != null) {
654
            {
655
                retVal = element.getDocumentation();
570
                retVal = element.getDocumentation();
656
            }
571
            }
657
            return retVal;
572
            return retVal;
658
        }
573
        }
659
        
574
660
        /**
575
        /**
661
         * Sets the documentation for the node.
576
         * Sets the documentation for the node.
662
         */
577
         */
663
        public void setDocumentation(String retVal)
578
        public void setDocumentation(String retVal) {
664
        {
665
            IElement element = getModelElement();
579
            IElement element = getModelElement();
666
            if (element != null)
580
            if (element != null) {
667
            {
668
                element.setDocumentation(retVal);
581
                element.setDocumentation(retVal);
669
            }
582
            }
670
        }
583
        }
671
    }
584
    }
672
    
585
673
    
674
    // Implementation of Interface IElementLifeTimeEventsSink
586
    // Implementation of Interface IElementLifeTimeEventsSink
675
    /////////////////////////////////////////////////////////
587
    /////////////////////////////////////////////////////////
676
    
677
    public void onElementDeleted(
588
    public void onElementDeleted(
678
        IVersionableElement element, IResultCell cell) 
589
            IVersionableElement element, IResultCell cell) {
679
    {
680
        // cvc - 6317505
590
        // cvc - 6317505
681
        // defensive null checks; getParentItem was returning null for sure
591
        // defensive null checks; getParentItem was returning null for sure
682
        // causing NPEs and InvocationTargetExceptions
592
        // causing NPEs and InvocationTargetExceptions
683
        if (element != null && element.isSame(getModelElement()))
593
        if (element != null && element.isSame(getModelElement())) {
684
        {   
685
            ITreeItem parentItem = getParentItem();
594
            ITreeItem parentItem = getParentItem();
686
            if (parentItem != null)
595
            if (parentItem != null) {
687
            {
688
                parentItem.removeChild(this);
596
                parentItem.removeChild(this);
689
            }
597
            }
690
        }
598
        }
691
   }
599
    }
692
    
600
693
    public void onElementCreated(
601
    public void onElementCreated(
694
        IVersionableElement element, IResultCell cell) {}
602
            IVersionableElement element, IResultCell cell) {
603
    }
695
604
696
    public void onElementDuplicated(
605
    public void onElementDuplicated(
697
        IVersionableElement element, IResultCell cell) {}
606
            IVersionableElement element, IResultCell cell) {
607
    }
698
608
699
    public void onElementPreCreate(
609
    public void onElementPreCreate(
700
        String ElementType, IResultCell cell) {}
610
            String ElementType, IResultCell cell) {
611
    }
701
612
702
    public void onElementPreDelete(
613
    public void onElementPreDelete(
703
        IVersionableElement element, IResultCell cell) {}
614
            IVersionableElement element, IResultCell cell) {
615
    }
704
616
705
    public void onElementPreDuplicated(
617
    public void onElementPreDuplicated(
706
        IVersionableElement element, IResultCell cell) {}
618
            IVersionableElement element, IResultCell cell) {
707
619
    }
708
    
709
}
620
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLModelRootNode.java (-221 / +163 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on March 1, 2005, 6:26 PM
48
 * Created on March 1, 2005, 6:26 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.nodes;
50
package org.netbeans.modules.uml.project.ui.nodes;
52
51
53
import java.util.ArrayList;
52
import java.util.ArrayList;
Lines 74-80 Link Here
74
import org.netbeans.modules.uml.project.ui.nodes.actions.NewElementType;
73
import org.netbeans.modules.uml.project.ui.nodes.actions.NewElementType;
75
import org.netbeans.modules.uml.project.UMLProjectModule;
74
import org.netbeans.modules.uml.project.UMLProjectModule;
76
import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeControl;
75
import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeControl;
77
import org.netbeans.modules.uml.ui.support.projecttreesupport.ProjectTreeComparable;
78
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
76
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
79
import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
77
import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
80
import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
78
import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
Lines 84-89 Link Here
84
import org.netbeans.modules.uml.ui.swing.projecttree.JFilterDialog;
82
import org.netbeans.modules.uml.ui.swing.projecttree.JFilterDialog;
85
import org.netbeans.modules.uml.project.ui.nodes.actions.FilterAction;
83
import org.netbeans.modules.uml.project.ui.nodes.actions.FilterAction;
86
import javax.swing.tree.DefaultTreeModel;
84
import javax.swing.tree.DefaultTreeModel;
85
import org.netbeans.modules.uml.core.metamodel.structure.IProject;
87
import org.netbeans.modules.uml.resources.images.ImageUtil;
86
import org.netbeans.modules.uml.resources.images.ImageUtil;
88
import org.openide.actions.PropertiesAction;
87
import org.openide.actions.PropertiesAction;
89
import org.openide.actions.SaveAction;
88
import org.openide.actions.SaveAction;
Lines 97-117 Link Here
97
 * @author Mike
96
 * @author Mike
98
 */
97
 */
99
public class UMLModelRootNode extends UMLModelElementNode
98
public class UMLModelRootNode extends UMLModelElementNode
100
        implements ModelRootNodeCookie, IProjectTreeFilterDialogEventsSink
99
        implements ModelRootNodeCookie, IProjectTreeFilterDialogEventsSink {
101
{
100
102
    private Image mIcon = null;
101
    private Image mIcon = null;
103
    private UMLProjectHelper mHelper = null;
102
    private UMLProjectHelper mHelper = null;
104
    
105
    private final String displayName;
103
    private final String displayName;
106
    private IFilterDialog filterDialog = null;
104
    private IFilterDialog filterDialog = null;
107
    private DefaultTreeModel treeModelFilter = null;
105
    private DefaultTreeModel treeModelFilter = null;
108
    
106
109
    
107
    /* TODO - remove the 3 second sleep and fix this
110
        /* TODO - remove the 3 second sleep and fix this
108
    See HACK in static related to race condition
111
         See HACK in static related to race condition
109
    private static ADProjectTreeEngine mEngine = new ADProjectTreeEngine();
112
        private static ADProjectTreeEngine mEngine = new ADProjectTreeEngine();
110
    private static NetBeansUMLProjectTreeModel mModel = new NetBeansUMLProjectTreeModel();
113
        private static NetBeansUMLProjectTreeModel mModel = new NetBeansUMLProjectTreeModel();
111
     */
114
         */
115
    //	private static ADProjectTreeEngine mEngine = null;
112
    //	private static ADProjectTreeEngine mEngine = null;
116
    //	private static NetBeansUMLProjectTreeModel mModel = null;
113
    //	private static NetBeansUMLProjectTreeModel mModel = null;
117
    //
114
    //
Lines 133-217 Link Here
133
    //
130
    //
134
    //		mEngine.initialize(mModel);
131
    //		mEngine.initialize(mModel);
135
    //	}
132
    //	}
136
    
137
    public UMLModelRootNode(UMLProject project, UMLProjectHelper helper,
133
    public UMLModelRootNode(UMLProject project, UMLProjectHelper helper,
138
            PropertyEvaluator eval)
134
            PropertyEvaluator eval) {
139
    {
140
        super();
135
        super();
141
//            super(obj, new UMLChildren(), new ProjectTreeItemImpl());
136
//            super(obj, new UMLChildren(), new ProjectTreeItemImpl());
142
        UMLProjectModule.addModelNode(this, project);
137
        UMLProjectModule.addModelNode(this, project);
143
        mHelper = helper;
138
        mHelper = helper;
144
        
139
145
        setElement(mHelper.getProject());
140
        setElement(mHelper.getProject());
146
        getData().setSortPriority(1);
141
        getData().setSortPriority(1);
147
        getData().setDescription(IProjectTreeControl.PROJECT_DESCRIPTION);
142
        getData().setDescription(IProjectTreeControl.PROJECT_DESCRIPTION);
148
        
143
149
        //mEngine.initialize(mModel);
144
        //mEngine.initialize(mModel);
150
        Children ch = getChildren();
145
        Children ch = getChildren();
151
        if (ch != null && ch instanceof UMLChildren)
146
        if (ch != null && ch instanceof UMLChildren) {
152
        {
147
            final UMLChildren children = (UMLChildren) ch;
153
            final UMLChildren children = (UMLChildren)ch;
148
            ((UMLChildren) ch).setItem(this);
154
            ((UMLChildren)ch).setItem(this);
155
        }
149
        }
156
        
150
157
        this.displayName = NbBundle.getMessage(
151
        this.displayName = NbBundle.getMessage(
158
                UMLModelRootNode.class, "CTL_UMLModelRootNode"); //NOI18N
152
                UMLModelRootNode.class, "CTL_UMLModelRootNode"); //NOI18N
159
        
153
160
        setIconBaseWithExtension(ImageUtil.IMAGE_FOLDER + "model-root-node.png"); // NOI18N
154
        setIconBaseWithExtension(ImageUtil.IMAGE_FOLDER + "model-root-node.png"); // NOI18N
161
        
155
162
        try
156
        try {
163
        {
157
            File f = new File(new File(mHelper.getProject().getFileName()).getCanonicalPath());
164
	    File f = new File(new File(mHelper.getProject().getFileName()).getCanonicalPath());
158
            final DataObject dobj = DataObject.find(FileUtil.toFileObject(f));
165
	    final DataObject dobj = DataObject.find(FileUtil.toFileObject(f));
159
166
            
160
            if (dobj != null) {
167
            if (dobj!=null)
161
                if (mHelper.getProject().getDirty()) {
168
            {
169
                if (mHelper.getProject().getDirty())
170
                {
171
                    Cookie cookie = dobj.getCookie(SaveCookie.class);
162
                    Cookie cookie = dobj.getCookie(SaveCookie.class);
172
                    if (cookie != null)
163
                    if (cookie != null) {
173
                        getCookieSet().add(cookie);
164
                        getCookieSet().add(cookie);
165
                    }
174
                }
166
                }
175
                    
167
176
                dobj.addPropertyChangeListener(new PropertyChangeListener()
168
                dobj.addPropertyChangeListener(new PropertyChangeListener() {
177
                {
169
178
                    public void propertyChange(PropertyChangeEvent evt)
170
                    public void propertyChange(PropertyChangeEvent evt) {
179
                    {
171
                        if (evt.getPropertyName().equals(DataObject.PROP_MODIFIED)) {
180
                        if (evt.getPropertyName().equals(DataObject.PROP_MODIFIED))
172
                            if (((Boolean) evt.getNewValue()).booleanValue()) {
181
                        {
173
                                if (getCookie(SaveCookie.class) == null) {
182
                            if (((Boolean)evt.getNewValue()).booleanValue())
183
                            {
184
                                if (getCookie(SaveCookie.class) == null)
185
                                    getCookieSet().add(dobj.getCookie(SaveCookie.class));
174
                                    getCookieSet().add(dobj.getCookie(SaveCookie.class));
186
                            }
175
                                }
187
                            else
176
                            } else {
188
                            {
189
                                Cookie cookie = getCookie(SaveCookie.class);
177
                                Cookie cookie = getCookie(SaveCookie.class);
190
                                if (cookie!=null)
178
                                if (cookie != null) {
191
                                    getCookieSet().remove(cookie);
179
                                    getCookieSet().remove(cookie);
180
                                }
192
                            }
181
                            }
193
                        }
182
                        }
194
                    }
183
                    }
195
                });
184
                });
196
            }
185
            }
197
        }
186
        } catch (Exception e) {
198
        catch (Exception e)
199
        {
200
            // project file object not found, 
187
            // project file object not found, 
201
        }
188
        }
202
    }
189
    }
203
    
190
204
    public String getDisplayName()
191
    public String getDisplayName() {
205
    {
206
        return this.displayName;
192
        return this.displayName;
207
    }
193
    }
208
    
194
209
    public String getName()
195
    public String getName() {
210
    {
211
        return this.getDisplayName();
196
        return this.getDisplayName();
212
    }
197
    }
213
    
198
214
    
215
    /**
199
    /**
216
     * Get the new types that can be created in this node. For example, a node
200
     * Get the new types that can be created in this node. For example, a node
217
     * representing a class will permit attributes, operations, classes,
201
     * representing a class will permit attributes, operations, classes,
Lines 219-276 Link Here
219
     *
203
     *
220
     * @return An array of new type operations that are allowed.
204
     * @return An array of new type operations that are allowed.
221
     */
205
     */
222
    public NewType[] getNewTypes()
206
    public NewType[] getNewTypes() {
223
    {
224
        String elType = getElementType();
207
        String elType = getElementType();
225
        NewType[] retVal = null;
208
        NewType[] retVal = null;
226
        
209
227
        if (getModelElement() instanceof INamespace)
210
        if (getModelElement() instanceof INamespace) {
228
        {
229
            // Package types: Java Package (or an organizing folder)
211
            // Package types: Java Package (or an organizing folder)
230
            // Project types: UML Modeling Project
212
            // Project types: UML Modeling Project
231
            if (elType.equals(ELEMENT_TYPE_PROJECT))
213
            if (elType.equals(ELEMENT_TYPE_PROJECT)) {
232
            {
214
                return new NewType[]{
233
                return new NewType[]
215
                            new NewDiagramType(this),
234
                {
216
                            new NewPackageType(this),
235
                    new NewDiagramType(this),
217
                            new NewElementType(this)
236
                    new NewPackageType(this),
218
                        };
237
                    new NewElementType(this)
238
                };
239
            }
219
            }
240
        } // if getModelElement() instanceof INamespace
220
        } // if getModelElement() instanceof INamespace
241
        
221
242
        // The NewAction code does not check for null.  Therefore, we have
222
        // The NewAction code does not check for null.  Therefore, we have
243
        // to create a new object just to keep them from throwing.
223
        // to create a new object just to keep them from throwing.
244
        if (retVal == null)
224
        if (retVal == null) {
245
        {
246
            retVal = new NewType[0];
225
            retVal = new NewType[0];
247
        }
226
        }
248
        
227
249
        return retVal;
228
        return retVal;
250
    }
229
    }
251
    
230
252
    public Action[] getActions( boolean context )
231
    public Action[] getActions(boolean context) {
253
    {
254
        ArrayList<Action> actions = new ArrayList<Action>();
232
        ArrayList<Action> actions = new ArrayList<Action>();
255
        
233
256
        // actions.add(CommonProjectActions.openSubprojectsAction());
234
        // actions.add(CommonProjectActions.openSubprojectsAction());
257
        // actions.add(CommonProjectActions.closeProjectAction());
235
        // actions.add(CommonProjectActions.closeProjectAction());
258
        
236
259
        //actions.add(SystemAction.get(NewAction.class));
237
        //actions.add(SystemAction.get(NewAction.class));
260
        super.getNewMenuAction(actions);
238
        super.getNewMenuAction(actions);
261
        actions.add(SystemAction.get(FilterAction.class));
239
        actions.add(SystemAction.get(FilterAction.class));
262
        addContextMenu(actions);
240
        addContextMenu(actions);
263
        
241
264
        actions.add(null);
242
        actions.add(null);
265
        actions.add(SystemAction.get(SaveAction.class));
243
        actions.add(SystemAction.get(SaveAction.class));
266
        actions.add(null);
244
        actions.add(null);
267
        actions.add(SystemAction.get(PropertiesAction.class));
245
        actions.add(SystemAction.get(PropertiesAction.class));
268
        
246
269
        Action[] retVal = new Action[actions.size()];
247
        Action[] retVal = new Action[actions.size()];
270
        actions.toArray(retVal);
248
        actions.toArray(retVal);
271
        return retVal;
249
        return retVal;
272
    }
250
    }
273
    
251
274
    /**
252
    /**
275
     * Retrieves the associated model element.  The model element will be the
253
     * Retrieves the associated model element.  The model element will be the
276
     * IProject that represent the project.
254
     * IProject that represent the project.
Lines 278-513 Link Here
278
     * @return The IProject instance.
256
     * @return The IProject instance.
279
     * @see IProject
257
     * @see IProject
280
     */
258
     */
281
    public IElement getModelElement()
259
    public IElement getModelElement() {
282
    {
260
        if (mHelper == null) {
283
        if (mHelper==null)
284
            return null;
261
            return null;
285
        
262
        }
263
286
        return mHelper.getProject();
264
        return mHelper.getProject();
287
    }
265
    }
288
    
266
289
    /**
267
    /**
290
     * Adds the model element to the lookup.
268
     * Adds the model element to the lookup.
291
     *
269
     *
292
     * @param element The Model element that represents the project.
270
     * @param element The Model element that represents the project.
293
     */
271
     */
294
    protected void addElementCookie(IElement element)
272
    protected void addElementCookie(IElement element) {
295
    {
296
    }
273
    }
297
    
274
298
    public Node.Cookie getCookie(Class type)
275
    public Node.Cookie getCookie(Class type) {
299
    {
300
        Node.Cookie cookie = super.getCookie(type);
276
        Node.Cookie cookie = super.getCookie(type);
301
        if(cookie == null)
277
        if (cookie == null) {
302
        {
303
            IElement element = getModelElement();
278
            IElement element = getModelElement();
304
            if(element instanceof Node.Cookie)
279
            if (element instanceof Node.Cookie) {
305
            {
280
                if (type.isAssignableFrom(element.getClass()) == true) {
306
                if(type.isAssignableFrom(element.getClass()) == true)
281
                    cookie = (Node.Cookie) element;
307
                {
308
                    cookie = (Node.Cookie)element;
309
                }
282
                }
310
            }
283
            }
311
        }
284
        }
312
        // MCF experiment
285
        // MCF experiment
313
        if(cookie == null)
286
        if (cookie == null) {
314
        {
287
            if (type.isAssignableFrom(ModelRootNodeCookie.class) == true) {
315
            if(type.isAssignableFrom(ModelRootNodeCookie.class) == true)
316
                return this;
288
                return this;
317
            
289
            }
290
318
        }
291
        }
319
        return cookie;
292
        return cookie;
320
    }
293
    }
321
    
294
322
    
323
    //////////////////////////////////////
295
    //////////////////////////////////////
324
    
325
    //    public String getDisplayName()
296
    //    public String getDisplayName()
326
    //    {
297
    //    {
327
    //       return mHelper.getDisplayName();
298
    //       return mHelper.getDisplayName();
328
    //    }
299
    //    }
329
    
300
    public Image getIcon(int type) {
330
    
301
        Image original = super.getIcon(type);
331
    public Image getIcon( int type )
332
    {
333
        Image original = super.getIcon( type );
334
        //return broken ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
302
        //return broken ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
335
        return original;
303
        return original;
336
    }
304
    }
337
    
305
338
    public Image getOpenedIcon( int type )
306
    public Image getOpenedIcon(int type) {
339
    {
340
        Image original = super.getOpenedIcon(type);
307
        Image original = super.getOpenedIcon(type);
341
        //return broken ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
308
        //return broken ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
342
        return original;
309
        return original;
343
    }
310
    }
344
    
311
345
    public static NetBeansUMLProjectTreeModel getProjectTreeModel()
312
    public static NetBeansUMLProjectTreeModel getProjectTreeModel() {
346
    {
347
        return UMLProjectModule.getProjectTreeModel();
313
        return UMLProjectModule.getProjectTreeModel();
348
    }
314
    }
349
    
315
350
    
316
    public void recalculateChildren() {
351
    
317
        UMLChildren children = (UMLChildren) getChildren();
352
    public void recalculateChildren()
353
    {
354
        UMLChildren children = (UMLChildren)getChildren();
355
        children.recalculateChildren();
318
        children.recalculateChildren();
356
        // a not so perfect approach to notify listeners to recalculate their imported list #130727
319
        // a not so perfect approach to notify listeners to recalculate their imported list #130727
357
        fireNodeDestroyed();
320
        fireNodeDestroyed();
358
    }
321
    }
359
    
322
360
    ///////////////////////////////////////////////////////////////////////////
323
    ///////////////////////////////////////////////////////////////////////////
361
    // Helper Methods
324
    // Helper Methods
362
    
363
    /**
325
    /**
364
     * Initializes the node with the default cookies.  <b>Note:</b>  Do not
326
     * Initializes the node with the default cookies.  <b>Note:</b>  Do not
365
     * call this method if a looup is added.  When a lookup is added then the
327
     * call this method if a looup is added.  When a lookup is added then the
366
     * lookup is used to find the cookies.
328
     * lookup is used to find the cookies.
367
     */
329
     */
368
    protected void initCookies()
330
    protected void initCookies() {
369
    {
370
        
371
    }
331
    }
372
    
332
373
    // Implementations for interface IProjectTreeFilterDialogEventsSink
333
    // Implementations for interface IProjectTreeFilterDialogEventsSink
374
    //////////////////////////////////////////////////////////////////
334
    //////////////////////////////////////////////////////////////////
375
    
335
    /* (non-Javadoc)
376
   /* (non-Javadoc)
336
     * @see org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventsSink#onProjectTreeFilterDialogInit(org.netbeans.modules.uml.ui.controls.filter.IFilterDialog, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
377
    * @see org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventsSink#onProjectTreeFilterDialogInit(org.netbeans.modules.uml.ui.controls.filter.IFilterDialog, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
337
     */
378
    */
379
    public void onProjectTreeFilterDialogInit(
338
    public void onProjectTreeFilterDialogInit(
380
            IFilterDialog dialog,IResultCell cell)
339
            IFilterDialog dialog, IResultCell cell) {
381
    {}
340
    }
382
    
341
383
   /* (non-Javadoc)
342
    /* (non-Javadoc)
384
    * @see org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventsSink#onProjectTreeFilterDialogOKActivated(org.netbeans.modules.uml.ui.controls.filter.IFilterDialog, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
343
     * @see org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventsSink#onProjectTreeFilterDialogOKActivated(org.netbeans.modules.uml.ui.controls.filter.IFilterDialog, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
385
    */
344
     */
386
    public void onProjectTreeFilterDialogOKActivated(
345
    public void onProjectTreeFilterDialogOKActivated(
387
            IFilterDialog dialog, IResultCell cell)
346
            IFilterDialog dialog, IResultCell cell) {
388
    {
347
        if (dialog != null && dialog instanceof JFilterDialog) {
389
        if (dialog != null && dialog instanceof JFilterDialog)
348
            JFilterDialog filterDialog = (JFilterDialog) dialog;
390
        {
349
391
            JFilterDialog filterDialog = (JFilterDialog)dialog;
392
            
393
            // setFilterDialog(dialog);
350
            // setFilterDialog(dialog);
394
            setTreeModelFilter(filterDialog.getTreeModel());
351
            setTreeModelFilter(filterDialog.getTreeModel());
395
            
352
396
            // Model root node children are refresh with filter applied
353
            // Model root node children are refresh with filter applied
397
            // TODO - unfortunately, this "flattens" any expanded nodes
354
            // TODO - unfortunately, this "flattens" any expanded nodes
398
            // instead of leaving them in their current expanded state
355
            // instead of leaving them in their current expanded state
399
	    SwingUtilities.invokeLater(new Runnable() 
356
            SwingUtilities.invokeLater(new Runnable() {
400
	    {
357
401
		public void run() 
358
                public void run() {
402
		{
359
                    recalculateChildren();
403
		    recalculateChildren();
360
                }
404
		}
361
            });
405
	    });
406
        }
362
        }
407
    }
363
    }
408
    
364
409
    public void filterListenerRegistered(boolean register)
365
    public void filterListenerRegistered(boolean register) {
410
    {
411
        DispatchHelper dispatchHelper = new DispatchHelper();
366
        DispatchHelper dispatchHelper = new DispatchHelper();
412
        
367
413
        if (register)
368
        if (register) // cvc - CR#6271053
414
            // cvc - CR#6271053
369
        // listen for Filter dialog OK action
415
            // listen for Filter dialog OK action
370
        {
416
            dispatchHelper.registerProjectTreeFilterDialogEvents(this);
371
            dispatchHelper.registerProjectTreeFilterDialogEvents(this);
417
        
372
        } else // cvc - CR 6271328
418
        else
373
        // only listen while Filter dialog is "alive" otherwise, all
419
            // cvc - CR 6271328
374
        // projects will listen to each others' filter dialogs
420
            // only listen while Filter dialog is "alive" otherwise, all
375
        {
421
            // projects will listen to each others' filter dialogs
422
            dispatchHelper.revokeProjectTreeFilterDialogSink(this);
376
            dispatchHelper.revokeProjectTreeFilterDialogSink(this);
377
        }
423
    }
378
    }
424
    
379
425
    
380
    public DefaultTreeModel getTreeModelFilter() {
426
    public DefaultTreeModel getTreeModelFilter()
427
    {
428
        return treeModelFilter;
381
        return treeModelFilter;
429
    }
382
    }
430
    
383
431
    public void setTreeModelFilter(DefaultTreeModel val)
384
    public void setTreeModelFilter(DefaultTreeModel val) {
432
    {
433
        this.treeModelFilter = val;
385
        this.treeModelFilter = val;
434
    }
386
    }
435
    
387
436
    // Gets the Context menu for the Model node from layer.xml
388
    // Gets the Context menu for the Model node from layer.xml
437
    protected void addContextMenu(List actions)
389
    protected void addContextMenu(List actions) {
438
    {
439
        Action[] nodeActions = null;
390
        Action[] nodeActions = null;
440
//        UMLElementNode node = new UMLElementNode();
391
//        UMLElementNode node = new UMLElementNode();
441
        nodeActions = getActionsFromRegistry(
392
        nodeActions = getActionsFromRegistry(
442
              "contextmenu/uml/designpatternformodel");
393
                "contextmenu/uml/designpatternformodel");
443
//                node.getActionsFromRegistry("contextmenu/uml/designpatternformodel");
394
//                node.getActionsFromRegistry("contextmenu/uml/designpatternformodel");
444
        
395
445
        for(Action curAction : nodeActions)
396
        for (Action curAction : nodeActions) {
446
        {
397
            if (curAction == null) {
447
            if (curAction == null)
448
                actions.add(null);
398
                actions.add(null);
449
            
399
            } else if (curAction.isEnabled()) {
450
            else if (curAction.isEnabled())
451
                actions.add(curAction);
400
                actions.add(curAction);
401
            }
452
        }
402
        }
453
        actions.add(null);
403
        actions.add(null);
454
        
404
455
        nodeActions =
405
        nodeActions =
456
                getActionsFromRegistry("Actions/UML/Search");
406
                getActionsFromRegistry("Actions/UML/Search");
457
        for(Action curAction : nodeActions)
407
        for (Action curAction : nodeActions) {
458
        {
408
            if (curAction == null) {
459
            if (curAction == null)
460
                actions.add(null);
409
                actions.add(null);
461
            
410
            } else if (curAction.isEnabled()) {
462
            else if (curAction.isEnabled())
463
                actions.add(curAction);
411
                actions.add(curAction);
412
            }
464
        }
413
        }
465
        
414
466
        actions.add(null);
415
        actions.add(null);
467
        
416
468
        nodeActions =
417
        nodeActions =
469
                getActionsFromRegistry("contextmenu/uml/report");
418
                getActionsFromRegistry("contextmenu/uml/report");
470
        for(Action curAction : nodeActions)
419
        for (Action curAction : nodeActions) {
471
        {
420
            if (curAction == null) {
472
            if (curAction == null)
473
                actions.add(null);
421
                actions.add(null);
474
            
422
            } else if (curAction.isEnabled()) {
475
            else if (curAction.isEnabled())
476
                actions.add(curAction);
423
                actions.add(curAction);
424
            }
477
        }
425
        }
478
    }
426
    }
479
    
427
480
    public boolean canCopy()
428
    public boolean canCopy() {
481
    {
482
        return false;
429
        return false;
483
    }
430
    }
484
    
431
485
    public boolean canCut()
432
    public boolean canCut() {
486
    {
487
        return false;
433
        return false;
488
    }
434
    }
489
    
435
490
    public boolean canRename()
436
    public boolean canRename() {
491
    {
492
        return false;
437
        return false;
493
    }
438
    }
494
    
439
495
    public boolean canDestroy()
440
    public boolean canDestroy() {
496
    {
497
        return false;
441
        return false;
498
    }
442
    }
499
    
500
443
501
   /* (non-Javadoc)
444
502
    * @see java.lang.Object#equals(java.lang.Object)
445
    /* (non-Javadoc)
503
    */
446
     * @see java.lang.Object#equals(java.lang.Object)
504
    public boolean equals(Object obj)
447
     */
505
    {
448
    public boolean equals(Object obj) {
506
	// NB60TBD special case for diagrams root node to make it work with NB60
449
        // NB60TBD special case for diagrams root node to make it work with NB60
507
	if (obj instanceof UMLDiagramsRootNode) {
450
        if (obj instanceof UMLDiagramsRootNode) {
508
	    return  false;
451
            return false;
509
	}
452
        }
510
	return super.equals(obj);
453
        return super.equals(obj);
511
    }
454
    }
512
513
}
455
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLPhysicalViewProvider.java (-341 / +238 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
46
45
47
import java.awt.Dialog;
46
import java.awt.Dialog;
Lines 113-127 Link Here
113
import org.openide.util.Mutex;
112
import org.openide.util.Mutex;
114
import org.openide.util.datatransfer.NewType;
113
import org.openide.util.datatransfer.NewType;
115
114
115
public class UMLPhysicalViewProvider implements LogicalViewProvider {
116
116
117
public class UMLPhysicalViewProvider implements LogicalViewProvider
118
{
119
    
120
    private static final RequestProcessor BROKEN_LINKS_RP =
117
    private static final RequestProcessor BROKEN_LINKS_RP =
121
            new RequestProcessor("UMLPhysicalViewProvider.BROKEN_LINKS_RP"); // NOI18N
118
            new RequestProcessor("UMLPhysicalViewProvider.BROKEN_LINKS_RP"); // NOI18N
122
    
123
    private static final RequestProcessor rp = new RequestProcessor();
119
    private static final RequestProcessor rp = new RequestProcessor();
124
    
125
    private final UMLProject mProject;
120
    private final UMLProject mProject;
126
    private final UMLProjectHelper mHelper;
121
    private final UMLProjectHelper mHelper;
127
    private final SubprojectProvider mSubProjetProvider;
122
    private final SubprojectProvider mSubProjetProvider;
Lines 130-198 Link Here
130
    private UMLLogicalViewRootNode node;
125
    private UMLLogicalViewRootNode node;
131
    private java.lang.ref.WeakReference<UMLLogicalViewRootNode> nodeWeakRef;
126
    private java.lang.ref.WeakReference<UMLLogicalViewRootNode> nodeWeakRef;
132
    private ReferenceHelper mResolver = null;
127
    private ReferenceHelper mResolver = null;
133
    
128
134
    
135
    public UMLPhysicalViewProvider(UMLProject project,
129
    public UMLPhysicalViewProvider(UMLProject project,
136
            UMLProjectHelper helper,
130
            UMLProjectHelper helper,
137
            PropertyEvaluator evaluator,
131
            PropertyEvaluator evaluator,
138
            SubprojectProvider spp,
132
            SubprojectProvider spp,
139
            UMLImportsUiSupport importSupport,
133
            UMLImportsUiSupport importSupport,
140
            ReferenceHelper resolver)
134
            ReferenceHelper resolver) {
141
    {
135
142
        
143
        this.mProject = project;
136
        this.mProject = project;
144
        assert mProject != null : "Project can not be NULL"; // NOI18N
137
        assert mProject != null : "Project can not be NULL"; // NOI18N
145
        
138
146
        this.mHelper = helper;
139
        this.mHelper = helper;
147
        assert mHelper != null : "Helper can not be NULL"; // NOI18N
140
        assert mHelper != null : "Helper can not be NULL"; // NOI18N
148
        
141
149
        this.evaluator = evaluator;
142
        this.evaluator = evaluator;
150
        assert evaluator != null;
143
        assert evaluator != null;
151
        
144
152
        this.mSubProjetProvider = spp;
145
        this.mSubProjetProvider = spp;
153
        assert spp != null : "SubprojectProvider can not be NULL";// NOI18N
146
        assert spp != null : "SubprojectProvider can not be NULL";// NOI18N
154
        
147
155
        this.mImportSupport = importSupport;
148
        this.mImportSupport = importSupport;
156
        assert importSupport != null : "UMLImportsUiSupport can not be NULL";// NOI18N
149
        assert importSupport != null : "UMLImportsUiSupport can not be NULL";// NOI18N
157
        
150
158
        mResolver = resolver;
151
        mResolver = resolver;
159
        assert resolver != null : "ReferenceHelper can not be NULL";// NOI18N
152
        assert resolver != null : "ReferenceHelper can not be NULL";// NOI18N
160
        
153
161
    }
154
    }
162
    
155
163
    public Node createLogicalView()
156
    public Node createLogicalView() {
164
    {
157
        if (this.node == null) {
165
        if (this.node == null)
158
            if (nodeWeakRef != null) {
166
        {
159
                UMLLogicalViewRootNode n = nodeWeakRef.get();
167
	    if (nodeWeakRef != null) 
160
                if (n != null) {
168
	    {
161
                    this.node = n;
169
		UMLLogicalViewRootNode n = nodeWeakRef.get();
162
                }
170
		if (n != null) 
163
            }
171
		{
164
            if (this.node == null) {
172
		    this.node = n;	  
165
                this.node = new UMLLogicalViewRootNode();
173
		}
166
            }
174
	    }
175
	    if (this.node == null) 
176
	    {
177
		this.node = new UMLLogicalViewRootNode();
178
	    }
179
        }
167
        }
180
	nodeWeakRef = null;
168
        nodeWeakRef = null;
181
       
169
182
        return this.node;
170
        return this.node;
183
    }
171
    }
184
    
172
185
    public void detachLogicalView()
173
    public void detachLogicalView() {
186
    {
174
        if (this.node != null) {
187
	if (this.node != null) 
175
            this.nodeWeakRef = new WeakReference(this.node);
188
	{
176
        }
189
	    this.nodeWeakRef = new WeakReference(this.node);
190
	}
191
        this.node = null;
177
        this.node = null;
192
    }
178
    }
193
    
179
194
    public org.openide.nodes.Node findPath( Node root, Object target )
180
    public org.openide.nodes.Node findPath(Node root, Object target) {
195
    {
196
        // TODO: Figure out how to retrieve a node
181
        // TODO: Figure out how to retrieve a node
197
        //       Project project = (Project)root.getLookup().lookup( Project.class );
182
        //       Project project = (Project)root.getLookup().lookup( Project.class );
198
        //       if ( project == null )
183
        //       if ( project == null )
Lines 219-242 Link Here
219
        //             }
204
        //             }
220
        //          }
205
        //          }
221
        //       }
206
        //       }
222
        
207
223
        return null;
208
        return null;
224
    }
209
    }
225
    
210
226
    /**
211
    /**
227
     * Used by UMLProjectCustomizer to mark the project as broken when it warns user
212
     * Used by UMLProjectCustomizer to mark the project as broken when it warns user
228
     * about project's broken references and advices him to use BrokenLinksAction to correct it.
213
     * about project's broken references and advices him to use BrokenLinksAction to correct it.
229
     *
214
     *
230
     */
215
     */
231
    public void testBroken()
216
    public void testBroken() {
232
    {
233
        /*
217
        /*
234
        UMLLogicalViewRootNode rootNode = (UMLLogicalViewRootNode) this.createLogicalView();
218
        UMLLogicalViewRootNode rootNode = (UMLLogicalViewRootNode) this.createLogicalView();
235
        rootNode.setBroken(hasBrokenLinks());
219
        rootNode.setBroken(hasBrokenLinks());
236
         */
220
         */
237
    }
221
    }
238
    
239
    
240
    //    private static Lookup createLookup(IProject project)
222
    //    private static Lookup createLookup(IProject project)
241
    //    {
223
    //    {
242
    //        DataFolder rootFolder =
224
    //        DataFolder rootFolder =
Lines 245-284 Link Here
245
    //        // XXX Remove root folder after FindAction rewrite
227
    //        // XXX Remove root folder after FindAction rewrite
246
    //        return Lookups.fixed( new Object[] { project, rootFolder } );
228
    //        return Lookups.fixed( new Object[] { project, rootFolder } );
247
    //    }
229
    //    }
248
    
249
    
250
    // MCF - this breakable infrastructure is copied from JESE project.
230
    // MCF - this breakable infrastructure is copied from JESE project.
251
    // maybe we need something like this, maybe not.
231
    // maybe we need something like this, maybe not.
252
    // can remove it eventually if we don't need it. I suspect we will need
232
    // can remove it eventually if we don't need it. I suspect we will need
253
    // some "isBroken" facility though
233
    // some "isBroken" facility though
254
    //
234
    //
255
    /////// beging isBroken stuff
235
    /////// beging isBroken stuff
256
    
236
    private static final String[] BREAKABLE_PROPERTIES = new String[]{
257
    
258
    private static final String[] BREAKABLE_PROPERTIES = new String[]
259
    {
260
        UMLProjectProperties.REFERENCED_JAVA_PROJECT,
237
        UMLProjectProperties.REFERENCED_JAVA_PROJECT,
261
        UMLProjectProperties.REFERENCED_JAVA_PROJECT_ARTIFACTS,
238
        UMLProjectProperties.REFERENCED_JAVA_PROJECT_ARTIFACTS,
262
        UMLProjectProperties.REFERENCED_JAVA_PROJECT_SRC,
239
        UMLProjectProperties.REFERENCED_JAVA_PROJECT_SRC,};
263
    };
240
264
    
241
    public boolean hasBrokenLinks() {
265
    public boolean hasBrokenLinks()
266
    {
267
        boolean retVal = false;
242
        boolean retVal = false;
268
        
243
269
        retVal =
244
        retVal =
270
                BrokenReferencesSupport.isBroken(mHelper.getAntProjectHelper(),
245
                BrokenReferencesSupport.isBroken(mHelper.getAntProjectHelper(),
271
                mResolver,
246
                mResolver,
272
                getBreakableProperties(),
247
                getBreakableProperties(),
273
                new String[]{});
248
                new String[]{});
274
        
249
275
        return retVal;
250
        return retVal;
276
    }
251
    }
277
    
252
278
    
253
    private String[] getBreakableProperties() {
279
    
280
    private String[] getBreakableProperties()
281
    {
282
        /*
254
        /*
283
        SourceRoots roots = this.project.getSourceRoots();
255
        SourceRoots roots = this.project.getSourceRoots();
284
        String[] srcRootProps = roots.getRootProperties();
256
        String[] srcRootProps = roots.getRootProperties();
Lines 292-450 Link Here
292
         */
264
         */
293
        return BREAKABLE_PROPERTIES; // mcf hack
265
        return BREAKABLE_PROPERTIES; // mcf hack
294
    }
266
    }
295
    
267
296
    
268
    public ModelRootNodeCookie getModelRootNodeCookie() {
297
    public ModelRootNodeCookie getModelRootNodeCookie()
269
        return ((UMLLogicalViewRootNode) createLogicalView()).getModelRootNodeCookie();
298
    {
299
        return ((UMLLogicalViewRootNode)createLogicalView()).getModelRootNodeCookie();
300
    }
270
    }
301
    
271
302
    
272
    public UMLModelRootNode getModelRootNode() {
303
    public UMLModelRootNode getModelRootNode()
273
        return ((UMLLogicalViewRootNode) createLogicalView()).getModelRootNode();
304
    {
305
        return ((UMLLogicalViewRootNode)createLogicalView()).getModelRootNode();
306
    }
274
    }
307
    
308
    private static Image brokenProjectBadge = ImageUtilities.loadImage(
275
    private static Image brokenProjectBadge = ImageUtilities.loadImage(
309
        ImageUtil.IMAGE_FOLDER + "broken-project-badge.gif"); // NOI18N
276
            ImageUtil.IMAGE_FOLDER + "broken-project-badge.gif"); // NOI18N
310
    /////// end isBroken stuff
277
    /////// end isBroken stuff
311
    
278
312
    // Private innerclasses ----------------------------------------------------
279
    // Private innerclasses ----------------------------------------------------
313
    
314
    /** Filter node containin additional features for the UML physical
280
    /** Filter node containin additional features for the UML physical
315
     */
281
     */
316
    private final class UMLLogicalViewRootNode extends AbstractNode
282
    private final class UMLLogicalViewRootNode extends AbstractNode
317
            implements UMLLogicalViewCookie
283
            implements UMLLogicalViewCookie {
318
    {
284
319
        
320
        private Image icon;
285
        private Image icon;
321
        private Lookup lookup;
286
        private Lookup lookup;
322
        private Action brokenLinksAction;
287
        private Action brokenLinksAction;
323
        private boolean broken;
288
        private boolean broken;
324
        
289
325
        public UMLLogicalViewRootNode()
290
        public UMLLogicalViewRootNode() {
326
        {
327
            super(
291
            super(
328
                    new LogicalViewChildren(
292
                    new LogicalViewChildren(
329
                    mProject, mHelper, evaluator, mImportSupport),
293
                    mProject, mHelper, evaluator, mImportSupport),
330
                    Lookups.singleton(mProject));
294
                    Lookups.singleton(mProject));
331
            
295
332
            setIconBaseWithExtension(ImageUtil.IMAGE_FOLDER + "uml-project.png"); // NOI18N
296
            setIconBaseWithExtension(ImageUtil.IMAGE_FOLDER + "uml-project.png"); // NOI18N
333
            
297
334
            setName(ProjectUtils.getInformation( mProject ).getDisplayName());
298
            setName(ProjectUtils.getInformation(mProject).getDisplayName());
335
            
299
336
            if (hasBrokenLinks())
300
            if (hasBrokenLinks()) {
337
                broken = true;
301
                broken = true;
338
            
302
            }
303
339
            brokenLinksAction = new BrokenLinksAction();
304
            brokenLinksAction = new BrokenLinksAction();
340
        }
305
        }
341
        
306
342
        @Override
307
        @Override
343
        public Image getIcon(int type)
308
        public Image getIcon(int type) {
344
        {
345
            Image original = super.getIcon(type);
309
            Image original = super.getIcon(type);
346
            
310
347
            return broken
311
            return broken
348
                    ? ImageUtilities.mergeImages(original, brokenProjectBadge, 8, 0)
312
                    ? ImageUtilities.mergeImages(original, brokenProjectBadge, 8, 0)
349
                    : original;
313
                    : original;
350
        }
314
        }
351
        
315
352
        @Override
316
        @Override
353
        public Image getOpenedIcon(int type)
317
        public Image getOpenedIcon(int type) {
354
        {
355
            Image original = super.getOpenedIcon(type);
318
            Image original = super.getOpenedIcon(type);
356
            
319
357
            return broken
320
            return broken
358
                    ? ImageUtilities.mergeImages(original, brokenProjectBadge, 8, 0)
321
                    ? ImageUtilities.mergeImages(original, brokenProjectBadge, 8, 0)
359
                    : original;
322
                    : original;
360
        }
323
        }
361
        
324
362
        @Override
325
        @Override
363
        public String getHtmlDisplayName()
326
        public String getHtmlDisplayName() {
364
        {
365
            String dispName = super.getDisplayName();
327
            String dispName = super.getDisplayName();
366
            
328
367
            try
329
            try {
368
            {
369
                dispName = XMLUtil.toElementContent(dispName);
330
                dispName = XMLUtil.toElementContent(dispName);
370
            }
331
            } catch (CharConversionException ex) {
371
            
372
            catch (CharConversionException ex)
373
            {
374
                // OK, no annotation in this case
332
                // OK, no annotation in this case
375
                return null;
333
                return null;
376
            }
334
            }
377
            
335
378
            return broken
336
            return broken
379
                    ? "<font color=\"#A40000\">" + dispName + "</font>" //NOI18N
337
                    ? "<font color=\"#A40000\">" + dispName + "</font>" //NOI18N
380
                    : null;
338
                    : null;
381
        }
339
        }
382
        
340
383
        @Override
341
        @Override
384
        public Action[] getActions(boolean context)
342
        public Action[] getActions(boolean context) {
385
        {
386
            return getAdditionalActions();
343
            return getAdditionalActions();
387
        }
344
        }
388
        
345
389
        @Override
346
        @Override
390
        public boolean canRename()
347
        public boolean canRename() {
391
        {
392
            return false;
348
            return false;
393
        }
349
        }
394
        
350
395
        @Override
351
        @Override
396
        public boolean canCopy()
352
        public boolean canCopy() {
397
        {
398
            return false;
353
            return false;
399
        }
354
        }
400
        
355
401
        @Override
356
        @Override
402
        public boolean canCut()
357
        public boolean canCut() {
403
        {
404
            return true;
358
            return true;
405
        }
359
        }
406
        
360
407
        @Override
361
        @Override
408
        public boolean canDestroy()
362
        public boolean canDestroy() {
409
        {
410
            return true;
363
            return true;
411
        }
364
        }
412
        
365
413
        @Override
366
        @Override
414
        public void destroy() throws IOException
367
        public void destroy() throws IOException {
415
        {
416
            //
368
            //
417
            final UMLProjectDeletePanel delPanel=new UMLProjectDeletePanel(mProject.getName(), mProject.getProjectDirectory().getPath());
369
            final UMLProjectDeletePanel delPanel = new UMLProjectDeletePanel(mProject.getName(), mProject.getProjectDirectory().getPath());
418
            String title = NbBundle.getMessage(UMLPhysicalViewProvider.class,"LBL_ConfirmDeleteTitle");
370
            String title = NbBundle.getMessage(UMLPhysicalViewProvider.class, "LBL_ConfirmDeleteTitle");
419
            String adesc = NbBundle.getMessage(UMLPhysicalViewProvider.class,"ADS_ConfirmDeleteProject");
371
            String adesc = NbBundle.getMessage(UMLPhysicalViewProvider.class, "ADS_ConfirmDeleteProject");
420
            final JButton confirm = new JButton();
372
            final JButton confirm = new JButton();
421
            Mnemonics.setLocalizedText(confirm, NbBundle.getMessage(UMLPhysicalViewProvider.class, "LBL_Yes_Button"));
373
            Mnemonics.setLocalizedText(confirm, NbBundle.getMessage(UMLPhysicalViewProvider.class, "LBL_Yes_Button"));
422
            final JButton cancel  = new JButton(NbBundle.getMessage(UMLPhysicalViewProvider.class, "LBL_No_Button"));
374
            final JButton cancel = new JButton(NbBundle.getMessage(UMLPhysicalViewProvider.class, "LBL_No_Button"));
423
375
424
            confirm.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(UMLPhysicalViewProvider.class, "ACSD_Yes_Button"));
376
            confirm.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(UMLPhysicalViewProvider.class, "ACSD_Yes_Button"));
425
            cancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(UMLPhysicalViewProvider.class, "ACSD_No_Button"));
377
            cancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(UMLPhysicalViewProvider.class, "ACSD_No_Button"));
426
378
427
            DialogDescriptor dialogDescriptor = new DialogDescriptor(delPanel, title,
379
            DialogDescriptor dialogDescriptor = new DialogDescriptor(delPanel, title,
428
                true,new Object[] {confirm, cancel}, cancel,
380
                    true, new Object[]{confirm, cancel}, cancel,
429
                DialogDescriptor.DEFAULT_ALIGN, null,null);
381
                    DialogDescriptor.DEFAULT_ALIGN, null, null);
430
            dialogDescriptor.setMessageType(NotifyDescriptor.QUESTION_MESSAGE);
382
            dialogDescriptor.setMessageType(NotifyDescriptor.QUESTION_MESSAGE);
431
383
432
            Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
384
            Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
433
            dialog.getAccessibleContext().setAccessibleDescription(adesc);
385
            dialog.getAccessibleContext().setAccessibleDescription(adesc);
434
            dialog.getAccessibleContext().setAccessibleName(title);
386
            dialog.getAccessibleContext().setAccessibleName(title);
435
            try
387
            try {
436
            {
437
                dialog.setVisible(true);
388
                dialog.setVisible(true);
438
                if (dialogDescriptor.getValue() == confirm)
389
                if (dialogDescriptor.getValue() == confirm) {
439
                {
440
                    mProject.removeUMLProjectMetaListener();
390
                    mProject.removeUMLProjectMetaListener();
441
391
442
                    closeDiagramsWithoutSave();
392
                    closeDiagramsWithoutSave();
443
                    Mutex.EVENT.readAccess(new Mutex.Action<Void>()
393
                    Mutex.EVENT.readAccess(new Mutex.Action<Void>() {
444
                    {
394
445
                        public Void run()
395
                        public Void run() {
446
                        {
396
                            OpenProjects.getDefault().close(new Project[]{mProject});
447
                            OpenProjects.getDefault().close(new Project[] {mProject});
448
                            return null;
397
                            return null;
449
398
450
                        }
399
                        }
Lines 452-486 Link Here
452
401
453
                    mHelper.getProjectDirectory().delete();
402
                    mHelper.getProjectDirectory().delete();
454
                }
403
                }
455
            } catch (Exception e)
404
            } catch (Exception e) {
456
            {
457
                Logger.getLogger(UMLPhysicalViewProvider.class.getName()).log(Level.SEVERE,
405
                Logger.getLogger(UMLPhysicalViewProvider.class.getName()).log(Level.SEVERE,
458
                        e.getLocalizedMessage());
406
                        e.getLocalizedMessage());
459
            } finally
407
            } finally {
460
            {
461
                dialog.dispose();
408
                dialog.dispose();
462
            }
409
            }
463
        }
410
        }
464
        
411
465
        private void closeDiagramsWithoutSave()
412
        private void closeDiagramsWithoutSave() {
466
        {
467
            ICoreProduct coreProduct = ProductRetriever.retrieveProduct();
413
            ICoreProduct coreProduct = ProductRetriever.retrieveProduct();
468
            if (coreProduct instanceof IProduct)
414
            if (coreProduct instanceof IProduct) {
469
            {
415
                IProduct product = (IProduct) coreProduct;
470
                IProduct product = (IProduct)coreProduct;
471
                List<IProxyDiagram> diagrams = product.getDiagramManager().getOpenDiagrams();
416
                List<IProxyDiagram> diagrams = product.getDiagramManager().getOpenDiagrams();
472
                for (IProxyDiagram diagram: diagrams)
417
                for (IProxyDiagram diagram : diagrams) {
473
                {
474
                    File f = new File(diagram.getFilename());
418
                    File f = new File(diagram.getFilename());
475
                    FileObject fobj = FileUtil.toFileObject(f);
419
                    FileObject fobj = FileUtil.toFileObject(f);
476
                    if (fobj != null)
420
                    if (fobj != null) {
477
                    {
478
                        Project owner = FileOwnerQuery.getOwner(fobj);
421
                        Project owner = FileOwnerQuery.getOwner(fobj);
479
                        if (mProject.equals(owner))
422
                        if (mProject.equals(owner)) {
480
                        {
481
                            IDiagram diag = diagram.getDiagram();
423
                            IDiagram diag = diagram.getDiagram();
482
                            if (diag != null)
424
                            if (diag != null) {
483
                            {
484
                                diag.setDirty(false);
425
                                diag.setDirty(false);
485
                                product.getDiagramManager().closeDiagram2(diag);
426
                                product.getDiagramManager().closeDiagram2(diag);
486
                            }
427
                            }
Lines 489-549 Link Here
489
                }
430
                }
490
            }
431
            }
491
        }
432
        }
492
        
433
493
        @Override
434
        @Override
494
        public Node.Cookie getCookie(Class type)
435
        public Node.Cookie getCookie(Class type) {
495
        {
496
            Node.Cookie cookie = super.getCookie(type);
436
            Node.Cookie cookie = super.getCookie(type);
497
            
437
498
            if (cookie == null)
438
            if (cookie == null) {
499
            {
439
                if (type.isAssignableFrom(UMLLogicalViewCookie.class)) {
500
                if (type.isAssignableFrom(UMLLogicalViewCookie.class))
501
                    return this;
440
                    return this;
441
                }
502
            }
442
            }
503
            
443
504
            return cookie;
444
            return cookie;
505
        }
445
        }
506
        
446
507
        
508
        // this is the UMLLogicalViewCookie method(s)
447
        // this is the UMLLogicalViewCookie method(s)
509
        public ModelRootNodeCookie getModelRootNodeCookie()
448
        public ModelRootNodeCookie getModelRootNodeCookie() {
510
        {
511
            // find the ModelRootNode and tell it to get its diagrams
449
            // find the ModelRootNode and tell it to get its diagrams
512
            Children kids = this.getChildren();
450
            Children kids = this.getChildren();
513
            
451
514
            ModelRootNodeCookie dHelper = null;
452
            ModelRootNodeCookie dHelper = null;
515
            
453
516
            for (int i = 0; i < kids.getNodes().length; i++)
454
            for (int i = 0; i < kids.getNodes().length; i++) {
517
            {
455
                dHelper = (ModelRootNodeCookie) kids.getNodes()[i].getCookie(ModelRootNodeCookie.class);
518
                dHelper = (ModelRootNodeCookie)
456
519
                        kids.getNodes()[i].getCookie(ModelRootNodeCookie.class);
457
                if (dHelper != null) {
520
                
521
                if (dHelper != null)
522
                    return dHelper;
458
                    return dHelper;
459
                }
523
            }
460
            }
524
            
461
525
            return null;
462
            return null;
526
            
463
527
        }
464
        }
528
        
465
529
        public UMLModelRootNode getModelRootNode()
466
        public UMLModelRootNode getModelRootNode() {
530
        {
531
            Children kids = this.getChildren();
467
            Children kids = this.getChildren();
532
            ModelRootNodeCookie dHelper = null;
468
            ModelRootNodeCookie dHelper = null;
533
            
469
534
            for (int i = 0; i < kids.getNodes().length; i++)
470
            for (int i = 0; i < kids.getNodes().length; i++) {
535
            {
471
                dHelper = (ModelRootNodeCookie) kids.getNodes()[i].getCookie(ModelRootNodeCookie.class);
536
                dHelper = (ModelRootNodeCookie)
472
537
                        kids.getNodes()[i].getCookie(ModelRootNodeCookie.class);
473
                if (dHelper != null) {
538
                
474
                    return (UMLModelRootNode) (kids.getNodes()[i]);
539
                if (dHelper != null)
475
                }
540
                    return (UMLModelRootNode)(kids.getNodes()[i]);
541
            }
476
            }
542
            return null;
477
            return null;
543
        }
478
        }
544
        
479
545
        
546
        
547
        /**
480
        /**
548
         * Get the new types that can be created in this node. For example, a node
481
         * Get the new types that can be created in this node. For example, a node
549
         * representing a class will permit attributes, operations, classes,
482
         * representing a class will permit attributes, operations, classes,
Lines 552-580 Link Here
552
         * @return An array of new type operations that are allowed.
485
         * @return An array of new type operations that are allowed.
553
         */
486
         */
554
        @Override
487
        @Override
555
        public NewType[] getNewTypes()
488
        public NewType[] getNewTypes() {
556
        {
489
            return new NewType[]{
557
            return new NewType[]
490
                        new NewDiagramType(mHelper.getProject()),
558
            {
491
                        new NewPackageType(mHelper.getProject()),
559
                new NewDiagramType(mHelper.getProject()),
492
                        new NewElementType(mHelper.getProject())
560
                new NewPackageType(mHelper.getProject()),
493
                    };
561
                new NewElementType(mHelper.getProject())
562
            };
563
        }
494
        }
564
        
495
565
        
566
        // Private methods -------------------------------------------------
496
        // Private methods -------------------------------------------------
567
        
497
        private Action[] getAdditionalActions() {
568
        private Action[] getAdditionalActions()
498
569
        {
499
            ResourceBundle bundle = NbBundle.getBundle(UMLPhysicalViewProvider.class);
570
            
500
571
            ResourceBundle bundle = NbBundle.getBundle( UMLPhysicalViewProvider.class );
572
            
573
            List actions = new ArrayList();
501
            List actions = new ArrayList();
574
            // cvc - CR 6316000
502
            // cvc - CR 6316000
575
            // Set As Main Project not beneficial for UML Project types
503
            // Set As Main Project not beneficial for UML Project types
576
            // actions.add(CommonProjectActions.setAsMainProjectAction());
504
            // actions.add(CommonProjectActions.setAsMainProjectAction());
577
            
505
578
            //actions.add(SystemAction.get(NewAction.class));  // remove 'Add' menu item and
506
            //actions.add(SystemAction.get(NewAction.class));  // remove 'Add' menu item and
579
            actions.add(CommonProjectActions.newFileAction()); // replace with 'New' menu item.
507
            actions.add(CommonProjectActions.newFileAction()); // replace with 'New' menu item.
580
            actions.add(null);
508
            actions.add(null);
Lines 586-655 Link Here
586
            actions.addAll(Utilities.actionsForPath("UMLProjects/Actions")); // NOI18N
514
            actions.addAll(Utilities.actionsForPath("UMLProjects/Actions")); // NOI18N
587
            addContextMenus(actions);
515
            addContextMenus(actions);
588
            actions.add(null);
516
            actions.add(null);
589
            
517
590
            if (broken == true)
518
            if (broken == true) {
591
                actions.add(brokenLinksAction);
519
                actions.add(brokenLinksAction);
592
            
520
            }
521
593
            actions.add(CommonProjectActions.customizeProjectAction());
522
            actions.add(CommonProjectActions.customizeProjectAction());
594
            return (Action[]) actions.toArray(new Action[actions.size()]);
523
            return (Action[]) actions.toArray(new Action[actions.size()]);
595
        }
524
        }
596
        
525
597
        
526
        private boolean isBroken() {
598
        private boolean isBroken()
599
        {
600
            //return this.broken;
527
            //return this.broken;
601
            return false; // mcf hack
528
            return false; // mcf hack
602
        }
529
        }
603
        
530
604
        
531
        private void setBroken(boolean broken) {
605
        private void setBroken(boolean broken)
606
        {
607
            this.broken = broken;
532
            this.broken = broken;
608
            brokenLinksAction.setEnabled(broken);
533
            brokenLinksAction.setEnabled(broken);
609
            fireIconChange();
534
            fireIconChange();
610
            fireOpenedIconChange();
535
            fireOpenedIconChange();
611
            fireDisplayNameChange(null, null);
536
            fireDisplayNameChange(null, null);
612
        }
537
        }
613
        
538
614
        
615
        /** This action is created only when project has broken references.
539
        /** This action is created only when project has broken references.
616
         * Once these are resolved the action is disabled.
540
         * Once these are resolved the action is disabled.
617
         */
541
         */
618
        private class BrokenLinksAction extends AbstractAction
542
        private class BrokenLinksAction extends AbstractAction
619
                implements PropertyChangeListener, Runnable
543
                implements PropertyChangeListener, Runnable {
620
        {
544
621
            private RequestProcessor.Task task = null;
545
            private RequestProcessor.Task task = null;
622
            private PropertyChangeListener weakPCL;
546
            private PropertyChangeListener weakPCL;
623
            
547
624
            public BrokenLinksAction()
548
            public BrokenLinksAction() {
625
            {
626
                putValue(Action.NAME, NbBundle.getMessage(
549
                putValue(Action.NAME, NbBundle.getMessage(
627
                        UMLPhysicalViewProvider.class,
550
                        UMLPhysicalViewProvider.class,
628
                        "LBL_Fix_Broken_Links_Action")); // NOI18N
551
                        "LBL_Fix_Broken_Links_Action")); // NOI18N
629
                
552
630
                setEnabled(broken);
553
                setEnabled(broken);
631
                evaluator.addPropertyChangeListener( this );
554
                evaluator.addPropertyChangeListener(this);
632
                
555
633
                // When evaluator fires changes that platform properties were
556
                // When evaluator fires changes that platform properties were
634
                // removed the platform still exists in JavaPlatformManager.
557
                // removed the platform still exists in JavaPlatformManager.
635
                // That's why I have to listen here also on JPM:
558
                // That's why I have to listen here also on JPM:
636
                
559
637
                // MCF - do we care about platform?
560
                // MCF - do we care about platform?
638
                /*
561
                /*
639
                weakPCL = WeakListeners.propertyChange( this, JavaPlatformManager.getDefault() );
562
                weakPCL = WeakListeners.propertyChange( this, JavaPlatformManager.getDefault() );
640
                JavaPlatformManager.getDefault().addPropertyChangeListener( weakPCL );
563
                JavaPlatformManager.getDefault().addPropertyChangeListener( weakPCL );
641
                 */
564
                 */
642
            }
565
            }
643
            
566
644
            public void actionPerformed(ActionEvent e)
567
            public void actionPerformed(ActionEvent e) {
645
            {
646
                // We are not worrying about updating the project version.
568
                // We are not worrying about updating the project version.
647
                //mHelper.requestSave();
569
                //mHelper.requestSave();
648
                BrokenReferencesSupport.showCustomizer(
570
                BrokenReferencesSupport.showCustomizer(
649
                        mHelper.getAntProjectHelper(),
571
                        mHelper.getAntProjectHelper(),
650
                        mResolver, getBreakableProperties(),
572
                        mResolver, getBreakableProperties(),
651
                        new String[]{});
573
                        new String[]{});
652
                
574
653
                mHelper.scanSourceGroups();
575
                mHelper.scanSourceGroups();
654
                run();
576
                run();
655
577
Lines 660-788 Link Here
660
//                String refJavaPrj = edProps.getProperty(
582
//                String refJavaPrj = edProps.getProperty(
661
//                    UMLProjectProperties.REFERENCED_JAVA_PROJECT) ;
583
//                    UMLProjectProperties.REFERENCED_JAVA_PROJECT) ;
662
            }
584
            }
663
            
585
664
            public void propertyChange(PropertyChangeEvent evt)
586
            public void propertyChange(PropertyChangeEvent evt) {
665
            {
666
                // check project state whenever there was a property change
587
                // check project state whenever there was a property change
667
                // or change in list of platforms.
588
                // or change in list of platforms.
668
                // Coalesce changes since they can come quickly:
589
                // Coalesce changes since they can come quickly:
669
                if (task == null)
590
                if (task == null) {
670
                    task = BROKEN_LINKS_RP.create(this);
591
                    task = BROKEN_LINKS_RP.create(this);
671
                
592
                }
593
672
                task.schedule(100);
594
                task.schedule(100);
673
            }
595
            }
674
            
596
675
            public synchronized void run()
597
            public synchronized void run() {
676
            {
677
                boolean old = broken;
598
                boolean old = broken;
678
                broken = hasBrokenLinks();
599
                broken = hasBrokenLinks();
679
                
600
680
                if (old != broken)
601
                if (old != broken) {
681
                    setBroken(broken);
602
                    setBroken(broken);
603
                }
682
            }
604
            }
683
        }
605
        }
684
    }
606
    }
685
    
607
686
    private static final class LogicalViewChildren extends Children.Keys/*<SourceGroup>*/
608
    private static final class LogicalViewChildren extends Children.Keys/*<SourceGroup>*/
687
            implements ChangeListener
609
            implements ChangeListener {
688
    {
610
689
        private static final Object UML_MODEL = "Model"; //NOI18N
611
        private static final Object UML_MODEL = "Model"; //NOI18N
690
        private static final Object UML_DIAGRAMS = "Diagrams"; //NOI18N
612
        private static final Object UML_DIAGRAMS = "Diagrams"; //NOI18N
691
        private static final Object UML_IMPORTED_PROJECTS = "Imported Projects"; //NOI18N
613
        private static final Object UML_IMPORTED_PROJECTS = "Imported Projects"; //NOI18N
692
        
693
        private final UMLProject project;
614
        private final UMLProject project;
694
        private final PropertyEvaluator evaluator;
615
        private final PropertyEvaluator evaluator;
695
        private final UMLProjectHelper helper;
616
        private final UMLProjectHelper helper;
696
        private final UMLImportsUiSupport mImportSupport;
617
        private final UMLImportsUiSupport mImportSupport;
697
        
698
        private Node mModelNode = null;
618
        private Node mModelNode = null;
699
        private Node mDiagramNode = null;
619
        private Node mDiagramNode = null;
700
        private ImportProjectRootNode mImportedNode = null;
620
        private ImportProjectRootNode mImportedNode = null;
701
        
621
702
        
703
        public LogicalViewChildren(
622
        public LogicalViewChildren(
704
                UMLProject project,
623
                UMLProject project,
705
                UMLProjectHelper helper,
624
                UMLProjectHelper helper,
706
                PropertyEvaluator evaluator,
625
                PropertyEvaluator evaluator,
707
                UMLImportsUiSupport importSupport)
626
                UMLImportsUiSupport importSupport) {
708
        {
709
            this.project = project;
627
            this.project = project;
710
            this.evaluator = evaluator;
628
            this.evaluator = evaluator;
711
            this.helper = helper;
629
            this.helper = helper;
712
            mImportSupport = importSupport;
630
            mImportSupport = importSupport;
713
        }
631
        }
714
        
632
715
        @Override
633
        @Override
716
        protected void addNotify()
634
        protected void addNotify() {
717
        {
718
            super.addNotify();
635
            super.addNotify();
719
            getSources().addChangeListener(this);
636
            getSources().addChangeListener(this);
720
            setKeys( getKeys() );
637
            setKeys(getKeys());
721
        }
638
        }
722
        
639
723
        @Override
640
        @Override
724
        protected void removeNotify()
641
        protected void removeNotify() {
725
        {
726
            setKeys(Collections.EMPTY_SET);
642
            setKeys(Collections.EMPTY_SET);
727
            getSources().removeChangeListener(this);
643
            getSources().removeChangeListener(this);
728
            super.removeNotify();
644
            super.removeNotify();
729
        }
645
        }
730
        
646
731
        protected synchronized Node getModelRootNode()
647
        protected synchronized Node getModelRootNode() {
732
        {
648
            if (mModelNode == null) {
733
            if (mModelNode == null)
734
                mModelNode = new UMLModelRootNode(project, helper, evaluator);
649
                mModelNode = new UMLModelRootNode(project, helper, evaluator);
735
            
650
            }
651
736
            return mModelNode;
652
            return mModelNode;
737
        }
653
        }
738
        
654
739
        protected synchronized Node getDiagramRootNode()
655
        protected synchronized Node getDiagramRootNode() {
740
        {
656
            if (mDiagramNode == null) {
741
            if (mDiagramNode == null)
742
            {
743
                mDiagramNode =
657
                mDiagramNode =
744
                        new UMLDiagramsRootNode(project, helper, evaluator);
658
                        new UMLDiagramsRootNode(project, helper, evaluator);
745
            }
659
            }
746
            
660
747
            return mDiagramNode;
661
            return mDiagramNode;
748
        }
662
        }
749
        
663
750
        protected synchronized ImportProjectRootNode getImportsRootNode()
664
        protected synchronized ImportProjectRootNode getImportsRootNode() {
751
        {
665
            if (mImportedNode == null) {
752
            if (mImportedNode == null)
753
                mImportedNode = new ImportProjectRootNode(helper);
666
                mImportedNode = new ImportProjectRootNode(helper);
754
            
667
            }
668
755
            return mImportedNode;
669
            return mImportedNode;
756
        }
670
        }
757
        
671
758
        protected Node[] createNodes( Object key )
672
        protected Node[] createNodes(Object key) {
759
        {
760
            Node[] result;
673
            Node[] result;
761
            
674
762
            if (key == UML_MODEL)
675
            if (key == UML_MODEL) {
763
                result = new Node[] {getModelRootNode()};
676
                result = new Node[]{getModelRootNode()};
764
            
677
            } else if (key == UML_DIAGRAMS) {
765
            else if (key == UML_DIAGRAMS)
678
                result = new Node[]{getDiagramRootNode()};
766
                result = new Node[] {getDiagramRootNode()};
679
            } else if (key == UML_IMPORTED_PROJECTS) {
767
            
768
            else if(key ==  UML_IMPORTED_PROJECTS)
769
            {
770
                ImportProjectRootNode node = getImportsRootNode();
680
                ImportProjectRootNode node = getImportsRootNode();
771
                mImportSupport.addImportElementListener(node);
681
                mImportSupport.addImportElementListener(node);
772
                result = new Node[] { node };
682
                result = new Node[]{node};
773
            }
683
            } else {
774
            
775
            else
776
            {
777
                assert false : "Unknown key type";  //NOI18N
684
                assert false : "Unknown key type";  //NOI18N
778
                result = new Node[0];
685
                result = new Node[0];
779
            }
686
            }
780
            
687
781
            return result;
688
            return result;
782
        }
689
        }
783
        
690
784
        public void stateChanged(ChangeEvent e)
691
        public void stateChanged(ChangeEvent e) {
785
        {
786
            ////            setKeys( getKeys() );
692
            ////            setKeys( getKeys() );
787
            //            //The caller holds ProjectManager.mutex() read lock
693
            //            //The caller holds ProjectManager.mutex() read lock
788
            //            rp.post (new Runnable () {
694
            //            rp.post (new Runnable () {
Lines 790-853 Link Here
790
            //                    setKeys( getKeys() );
696
            //                    setKeys( getKeys() );
791
            //                }
697
            //                }
792
            //            });
698
            //            });
793
            
794
        }
699
        }
795
        
700
796
        ////////////////////////////////////////////////////////////////////////
701
        ////////////////////////////////////////////////////////////////////////
797
        // Private methods -----------------------------------------------------
702
        // Private methods -----------------------------------------------------
798
        
703
        private Collection getKeys() {
799
        private Collection getKeys()
704
            List result = new ArrayList();
800
        {
801
            List result =  new ArrayList();
802
            result.add(UML_MODEL);
705
            result.add(UML_MODEL);
803
            result.add(UML_DIAGRAMS);
706
            result.add(UML_DIAGRAMS);
804
            result.add(UML_IMPORTED_PROJECTS);
707
            result.add(UML_IMPORTED_PROJECTS);
805
            return result;
708
            return result;
806
        }
709
        }
807
        
710
808
        private Sources getSources()
711
        private Sources getSources() {
809
        {
712
            return ProjectUtils.getSources(project);
810
            return ProjectUtils.getSources( project );
811
        }
713
        }
812
    }
714
    }
813
    
814
    
815
715
816
    /**
716
    /**
817
     * Retrieve the context actions added by other modules.
717
     * Retrieve the context actions added by other modules.
818
     *
718
     *
819
     * @param actions The action collection to add the actions to.
719
     * @param actions The action collection to add the actions to.
820
     */
720
     */
821
    protected void addContextMenus(List actions)
721
    protected void addContextMenus(List actions) {
822
    {
823
        UMLElementNode umlElNode = new UMLElementNode();
722
        UMLElementNode umlElNode = new UMLElementNode();
824
        
723
825
        Action[] nodeActions =
724
        Action[] nodeActions =
826
            umlElNode.getActionsFromRegistry("Actions/UML/Search"); // NOI18N
725
                umlElNode.getActionsFromRegistry("Actions/UML/Search"); // NOI18N
827
        
726
828
        for (Action curAction : nodeActions)
727
        for (Action curAction : nodeActions) {
829
        {
728
            if (curAction == null) // Make Sure the Seperators are kept.
830
            if (curAction == null)
729
            {
831
                // Make Sure the Seperators are kept.
832
                actions.add(null);
730
                actions.add(null);
833
            
731
            } else if (curAction.isEnabled()) {
834
            else if (curAction.isEnabled())
835
                actions.add(curAction);
732
                actions.add(curAction);
733
            }
836
        }
734
        }
837
        
735
838
        actions.add(null);
736
        actions.add(null);
839
        
737
840
        nodeActions =
738
        nodeActions =
841
            umlElNode.getActionsFromRegistry("contextmenu/uml/generate"); // NOI18N
739
                umlElNode.getActionsFromRegistry("contextmenu/uml/generate"); // NOI18N
842
        
740
843
        for (Action curAction : nodeActions)
741
        for (Action curAction : nodeActions) {
844
        {
742
            if (curAction == null) // Make Sure the Seperators are kept.
845
            if (curAction == null)
743
            {
846
                // Make Sure the Seperators are kept.
847
                actions.add(null);
744
                actions.add(null);
848
            
745
            } else if (curAction.isEnabled()) {
849
            else if (curAction.isEnabled())
850
                actions.add(curAction);
746
                actions.add(curAction);
747
            }
851
        }
748
        }
852
    }
749
    }
853
}
750
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLRelationshipNode.java (-37 / +28 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
47
45
48
import org.netbeans.modules.uml.common.RelationshipCookie;
46
import org.netbeans.modules.uml.common.RelationshipCookie;
Lines 51-97 Link Here
51
import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeItem;
49
import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeItem;
52
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeRelElement;
50
import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeRelElement;
53
51
54
55
/**
52
/**
56
 *
53
 *
57
 * @author Trey Spiva
54
 * @author Trey Spiva
58
 */
55
 */
59
public class UMLRelationshipNode extends UMLModelElementNode implements ITreeRelElement
56
public class UMLRelationshipNode extends UMLModelElementNode implements ITreeRelElement {
60
{
61
57
62
   /**
58
    /**
63
    *
59
     *
64
    */
60
     */
65
   public UMLRelationshipNode()
61
    public UMLRelationshipNode() {
66
   {
62
        super();
67
      super();
63
        getCookieSet().add(new RelationshipCookie());
68
	  getCookieSet().add(new RelationshipCookie());
64
    }
69
   }
70
65
66
    /**
67
     *
68
     */
69
    public UMLRelationshipNode(Lookup lookup) {
70
        super(lookup);
71
    }
71
72
72
   /**
73
    /**
73
    * 
74
     * @param item
74
    */
75
     * @throws NullPointerException
75
   public UMLRelationshipNode(Lookup lookup)
76
     */
76
   {
77
    public UMLRelationshipNode(IProjectTreeItem item) throws NullPointerException {
77
      super(lookup);
78
        super(item);
78
   }
79
    }
79
80
80
   /**
81
    /**
81
    * @param item
82
     * @param item
82
    * @throws NullPointerException
83
     * @throws NullPointerException
83
    */
84
     */
84
   public UMLRelationshipNode(IProjectTreeItem item) throws NullPointerException
85
    public UMLRelationshipNode(Lookup lookup, IProjectTreeItem item) throws NullPointerException {
85
   {
86
        super(lookup, item);
86
      super(item);
87
    }
87
   }
88
89
   /**
90
    * @param item
91
    * @throws NullPointerException
92
    */
93
   public UMLRelationshipNode(Lookup lookup, IProjectTreeItem item) throws NullPointerException
94
   {
95
      super(lookup, item);
96
   }
97
}
88
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLRequirementNode.java (-12 / +5 lines)
Lines 41-54 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
47
45
48
import org.openide.nodes.AbstractNode;
46
import org.openide.nodes.AbstractNode;
49
import org.openide.nodes.Children;
47
import org.openide.nodes.Children;
50
import org.openide.nodes.CookieSet;
51
import org.openide.nodes.Node;
52
48
53
import org.netbeans.modules.uml.core.requirementsframework.IRequirement;
49
import org.netbeans.modules.uml.core.requirementsframework.IRequirement;
54
import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeItem;
50
import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeItem;
Lines 58-74 Link Here
58
 *   for Netbeans cookies and actions machinery to work
54
 *   for Netbeans cookies and actions machinery to work
59
 * 
55
 * 
60
 */
56
 */
61
public class UMLRequirementNode extends AbstractNode 
57
public class UMLRequirementNode extends AbstractNode {
62
{
63
58
64
    public UMLRequirementNode(IProjectTreeItem item) {
59
    public UMLRequirementNode(IProjectTreeItem item) {
65
	super(new Children.Array());
60
        super(new Children.Array());
66
	getCookieSet().add(item);
61
        getCookieSet().add(item);
67
    }
62
    }
68
	
63
69
    public void setRequirement(IRequirement requirement)
64
    public void setRequirement(IRequirement requirement) {
70
    {
71
        getCookieSet().add(requirement);
65
        getCookieSet().add(requirement);
72
    }
66
    }
73
74
}
67
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/UMLWorkspaceNode.java (-50 / +39 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes;
44
package org.netbeans.modules.uml.project.ui.nodes;
47
45
48
import org.openide.util.Lookup;
46
import org.openide.util.Lookup;
Lines 55-112 Link Here
55
 *
53
 *
56
 * @author Trey Spiva
54
 * @author Trey Spiva
57
 */
55
 */
58
public class UMLWorkspaceNode extends UMLElementNode implements ITreeWorkspace
56
public class UMLWorkspaceNode extends UMLElementNode implements ITreeWorkspace {
59
{
60
   private IWorkspace m_Workspace = null;
61
57
62
   /**
58
    private IWorkspace m_Workspace = null;
63
    *
64
    */
65
   public UMLWorkspaceNode()
66
   {
67
      super();
68
   }
69
59
70
   /**
60
    /**
71
    * 
61
     *
72
    */
62
     */
73
   public UMLWorkspaceNode(Lookup l)
63
    public UMLWorkspaceNode() {
74
   {
64
        super();
75
      super(l);
65
    }
76
   }
77
66
78
   /**
67
    /**
79
    * @param item
68
     *
80
    * @throws NullPointerException
69
     */
81
    */
70
    public UMLWorkspaceNode(Lookup l) {
82
   public UMLWorkspaceNode(IProjectTreeItem item) throws NullPointerException
71
        super(l);
83
   {
72
    }
84
      super(item);
85
   }
86
73
87
   /**
74
    /**
88
    * @param item
75
     * @param item
89
    * @throws NullPointerException
76
     * @throws NullPointerException
90
    */
77
     */
91
   public UMLWorkspaceNode(Lookup l, IProjectTreeItem item) throws NullPointerException
78
    public UMLWorkspaceNode(IProjectTreeItem item) throws NullPointerException {
92
   {
79
        super(item);
93
      super(l, item);
80
    }
94
   }
95
81
96
   
82
    /**
97
   public IWorkspace getWorkspace()
83
     * @param item
98
   {
84
     * @throws NullPointerException
99
      return m_Workspace;
85
     */
100
   }
86
    public UMLWorkspaceNode(Lookup l, IProjectTreeItem item) throws NullPointerException {
101
   
87
        super(l, item);
102
   public void setWorkspace(IWorkspace pVal)
88
    }
103
   {
104
      m_Workspace = pVal;
105
   }
106
   
107
   public String getType()
108
   {
109
      return "Workspace";
110
   }
111
89
90
    public IWorkspace getWorkspace() {
91
        return m_Workspace;
92
    }
93
94
    public void setWorkspace(IWorkspace pVal) {
95
        m_Workspace = pVal;
96
    }
97
98
    public String getType() {
99
        return "Workspace";
100
    }
112
}
101
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/CloseDiagramAction.java (-53 / +40 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on January 25, 2005, 2:30 PM
48
 * Created on January 25, 2005, 2:30 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.nodes.actions;
50
package org.netbeans.modules.uml.project.ui.nodes.actions;
52
51
53
import javax.swing.SwingUtilities;
52
import javax.swing.SwingUtilities;
Lines 61-117 Link Here
61
 *
60
 *
62
 * @author  Craig Conover
61
 * @author  Craig Conover
63
 */
62
 */
64
public class CloseDiagramAction extends CookieAction
63
public class CloseDiagramAction extends CookieAction {
65
{
66
	
67
	/**
68
	 * Creates a new instance of CloseDiagramAction
69
	 */
70
	public CloseDiagramAction()
71
	{
72
	}
73
	
74
	protected Class[] cookieClasses()
75
	{
76
		return new Class[] {CloseCookie.class};
77
	}
78
	
79
	public HelpCtx getHelpCtx()
80
	{
81
		return null;
82
	}
83
	
84
	public String getName()
85
	{
86
		return (String)NbBundle.getBundle(CloseDiagramAction.class)
87
		.getString("CloseDiagramAction_Name");
88
	}
89
	
90
	protected int mode()
91
	{
92
		return CookieAction.MODE_ANY;
93
	}
94
	
95
	protected void performAction(Node[] nodes)
96
	{
97
		for (Node curNode : nodes)
98
		{
99
			final CloseCookie cookie = 
100
					(CloseCookie)curNode.getCookie(CloseCookie.class);
101
			
102
			if (cookie != null)
103
			{
104
				Runnable runnable = new Runnable() 
105
				{
106
					public void run() 
107
					{
108
						cookie.close();
109
					}
110
				};
111
64
112
				SwingUtilities.invokeLater(runnable);
65
    /**
113
			}
66
     * Creates a new instance of CloseDiagramAction
114
		}
67
     */
115
	}
68
    public CloseDiagramAction() {
116
	
69
    }
70
71
    protected Class[] cookieClasses() {
72
        return new Class[]{CloseCookie.class};
73
    }
74
75
    public HelpCtx getHelpCtx() {
76
        return null;
77
    }
78
79
    public String getName() {
80
        return (String) NbBundle.getBundle(CloseDiagramAction.class).getString("CloseDiagramAction_Name");
81
    }
82
83
    protected int mode() {
84
        return CookieAction.MODE_ANY;
85
    }
86
87
    protected void performAction(Node[] nodes) {
88
        for (Node curNode : nodes) {
89
            final CloseCookie cookie =
90
                    (CloseCookie) curNode.getCookie(CloseCookie.class);
91
92
            if (cookie != null) {
93
                Runnable runnable = new Runnable() {
94
95
                    public void run() {
96
                        cookie.close();
97
                    }
98
                };
99
100
                SwingUtilities.invokeLater(runnable);
101
            }
102
        }
103
    }
117
}
104
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/CopyDiagramAction.java (-90 / +53 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.nodes.actions;
44
package org.netbeans.modules.uml.project.ui.nodes.actions;
46
45
47
import java.io.File;
46
import java.io.File;
Lines 71-174 Link Here
71
 *
70
 *
72
 * @author Sheryl
71
 * @author Sheryl
73
 */
72
 */
74
public class CopyDiagramAction extends NodeAction
73
public class CopyDiagramAction extends NodeAction {
75
{
74
76
    private IProxyDiagram original;
75
    private IProxyDiagram original;
77
    
76
78
    /** Creates a new instance of CopyDiagramAction */
77
    /** Creates a new instance of CopyDiagramAction */
79
    public CopyDiagramAction()
78
    public CopyDiagramAction() {
80
    {
81
    }
79
    }
82
    
80
83
    public boolean enable(Node[] nodes)
81
    public boolean enable(Node[] nodes) {
84
    {
82
        if (nodes.length == 1) {
85
        if (nodes.length == 1)
86
            return true;
83
            return true;
84
        }
87
        return false;
85
        return false;
88
    }
86
    }
89
    
87
90
    public void performAction(Node[] nodes)
88
    public void performAction(Node[] nodes) {
91
    {
92
        Node diagramNode = nodes[0];
89
        Node diagramNode = nodes[0];
93
        ITreeDiagram cookie = diagramNode.getCookie(ITreeDiagram.class);
90
        ITreeDiagram cookie = diagramNode.getCookie(ITreeDiagram.class);
94
        if ( cookie != null)
91
        if (cookie != null) {
95
        {
96
92
97
            IProxyDiagram diagram = cookie.getDiagram();
93
            IProxyDiagram diagram = cookie.getDiagram();
98
            original = diagram;
94
            original = diagram;
99
            
95
100
            String label = NbBundle.getMessage(CopyDiagramAction.class,
96
            String label = NbBundle.getMessage(CopyDiagramAction.class,
101
                    "LBL_CopyDiagramAction_Diagram_Name");
97
                    "LBL_CopyDiagramAction_Diagram_Name");
102
            String title = NbBundle.getMessage(CopyDiagramAction.class,
98
            String title = NbBundle.getMessage(CopyDiagramAction.class,
103
                    "TLTEL_CopyDiagramAction_Save_Diagram_As");
99
                    "TLTEL_CopyDiagramAction_Save_Diagram_As");
104
            
100
105
            NotifyDescriptor.InputLine d = new NotifyDescriptor.InputLine(label, title);
101
            NotifyDescriptor.InputLine d = new NotifyDescriptor.InputLine(label, title);
106
            if (DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.OK_OPTION)
102
            if (DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.OK_OPTION) {
107
            {
108
                String name = d.getInputText();
103
                String name = d.getInputText();
109
                if (Util.isDiagramNameValid(name))
104
                if (Util.isDiagramNameValid(name)) {
110
                {
111
                    createDiagram(DiagramTypesManager.instance().
105
                    createDiagram(DiagramTypesManager.instance().
112
                        getUMLType(diagram.getDiagramKindName()),
106
                            getUMLType(diagram.getDiagramKindName()),
113
                        diagram.getNamespace(), name);
107
                            diagram.getNamespace(), name);
114
                }
108
                } else {
115
                else
116
                {
117
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(
109
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(
118
                            AddPackageVisualPanel1.class,  
110
                            AddPackageVisualPanel1.class,
119
                            "MSG_Invalid_Diagram_Name", name)); // NOI18N
111
                            "MSG_Invalid_Diagram_Name", name)); // NOI18N
120
                    DialogDisplayer.getDefault().notify(msg);
112
                    DialogDisplayer.getDefault().notify(msg);
121
                    
113
122
                }
114
                }
123
            }
115
            }
124
        }
116
        }
125
    }
117
    }
126
    
118
127
    private boolean saveFiles(String fileName, String newName)
119
    private boolean saveFiles(String fileName, String newName) {
128
    {
129
        String originalFile = original.getFilename();
120
        String originalFile = original.getFilename();
130
        String original_l = originalFile;
121
        String original_l = originalFile;
131
        
122
132
        int index = originalFile.lastIndexOf(".");
123
        int index = originalFile.lastIndexOf(".");
133
        if (index > -1)
124
        if (index > -1) {
134
        {
125
            original_l = originalFile.substring(0, index)
135
            original_l = originalFile.substring(0, index) +
126
                    + FileExtensions.DIAGRAM_LAYOUT_EXT;
136
                    FileExtensions.DIAGRAM_LAYOUT_EXT;
137
        }
127
        }
138
        String clone_l = fileName + FileExtensions.DIAGRAM_LAYOUT_EXT;
128
        String clone_l = fileName + FileExtensions.DIAGRAM_LAYOUT_EXT;
139
        
129
140
        // persist presentation file
130
        // persist presentation file
141
        ProductArchiveImpl archive = new ProductArchiveImpl(original_l);
131
        ProductArchiveImpl archive = new ProductArchiveImpl(original_l);
142
        IProductArchiveElement ele = archive.getDiagramElement(IProductArchiveDefinitions.UML_DIAGRAM_STRING);
132
        IProductArchiveElement ele = archive.getDiagramElement(IProductArchiveDefinitions.UML_DIAGRAM_STRING);
143
        if (ele != null)
133
        if (ele != null) {
144
        {
145
            ele.addAttributeString(IProductArchiveDefinitions.DIAGRAMNAME_STRING, newName);
134
            ele.addAttributeString(IProductArchiveDefinitions.DIAGRAMNAME_STRING, newName);
146
            ele.addAttributeString(IProductArchiveDefinitions.DIAGRAM_XMIID, UMLXMLManip.generateId(true));
135
            ele.addAttributeString(IProductArchiveDefinitions.DIAGRAM_XMIID, UMLXMLManip.generateId(true));
147
            archive.save(clone_l);
136
            archive.save(clone_l);
148
            return true;
137
            return true;
149
        }
138
        } else {
150
        else 
139
            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CopyDiagramAction.class,
151
        {
152
             NotifyDescriptor.Message msg 
153
                = new NotifyDescriptor.Message
154
                (NbBundle.getMessage(CopyDiagramAction.class,
155
                    "MSG_Cant_Copy_Diagram")); // NOI18N
140
                    "MSG_Cant_Copy_Diagram")); // NOI18N
156
            DialogDisplayer.getDefault().notify(msg);
141
            DialogDisplayer.getDefault().notify(msg);
157
            return false;
142
            return false;
158
        }
143
        }
159
    }
144
    }
160
    
145
161
    
146
    private void createDiagram(String type, INamespace nameSpace, String name) {
162
    private void createDiagram(String type, INamespace nameSpace, String name)
163
    {
164
        // 119568, save current working diagram before save as
147
        // 119568, save current working diagram before save as
165
        IDiagram diagram = original.getDiagram();
148
        IDiagram diagram = original.getDiagram();
166
        if (diagram != null)
149
        if (diagram != null) {
167
        {
168
            try {
150
            try {
169
                diagram.save();
151
                diagram.save();
170
            }catch (IOException e)
152
            } catch (IOException e) {
171
            {
172
                e.printStackTrace();
153
                e.printStackTrace();
173
            }
154
            }
174
        }
155
        }
Lines 180-252 Link Here
180
                    filename + FileExtensions.DIAGRAM_PRESENTATION_EXT);
161
                    filename + FileExtensions.DIAGRAM_PRESENTATION_EXT);
181
        }
162
        }
182
    }
163
    }
183
    
164
184
    
165
    public HelpCtx getHelpCtx() {
185
    public HelpCtx getHelpCtx()
186
    {
187
        return null;
166
        return null;
188
    }
167
    }
189
    
168
190
    public String getName()
169
    public String getName() {
191
    {
170
        return (String) NbBundle.getBundle(CopyDiagramAction.class).getString("CopyDiagramAction_Name");
192
        return (String)NbBundle.getBundle(CopyDiagramAction.class)
193
        .getString("CopyDiagramAction_Name");
194
    }
171
    }
195
    
172
196
    
197
    // generate unique file name for diagram
173
    // generate unique file name for diagram
198
    // this logic was copied from ADDrawingAreaControl.getFullFileName()
174
    // this logic was copied from ADDrawingAreaControl.getFullFileName()
199
    private String getFullFileName(String name, INamespace m_Namespace)
175
    private String getFullFileName(String name, INamespace m_Namespace) {
200
    {
201
        String retFileName = null;
176
        String retFileName = null;
202
        // If the user enters a filename then use that as the proposed filename.
177
        // If the user enters a filename then use that as the proposed filename.
203
        // If the filename is not absolute then we use the project directory
178
        // If the filename is not absolute then we use the project directory
204
        // as the location of the file.  If, for some reason, the filename argument
179
        // as the location of the file.  If, for some reason, the filename argument
205
        // is 0 then we use the name of the diagram as the name of the file and the
180
        // is 0 then we use the name of the diagram as the name of the file and the
206
        // workspace location for the directory.
181
        // workspace location for the directory.
207
        if (name != null && name.length() > 0)
182
        if (name != null && name.length() > 0) {
208
        {
209
            String formatStr = null;
183
            String formatStr = null;
210
            long timeInMillis = System.currentTimeMillis();
184
            long timeInMillis = System.currentTimeMillis();
211
            
185
212
            // To avoid conflicts between filenames, esp for large groups that are
186
            // To avoid conflicts between filenames, esp for large groups that are
213
            // using an SCC to manage their model we append a timestamp to the
187
            // using an SCC to manage their model we append a timestamp to the
214
            // file name.
188
            // file name.
215
            retFileName = name + "_" + timeInMillis;
189
            retFileName = name + "_" + timeInMillis;
216
        }
190
        }
217
        
191
218
        // Make sure we have a legal file.  If it is just a name then add the
192
        // Make sure we have a legal file.  If it is just a name then add the
219
        // .etld extension and put it in the same spot as the workspace.
193
        // .etld extension and put it in the same spot as the workspace.
220
        String buffer = retFileName;
194
        String buffer = retFileName;
221
        String drive = null;
195
        String drive = null;
222
        int pos = buffer.indexOf(":");
196
        int pos = buffer.indexOf(":");
223
        if (pos >= 0)
197
        if (pos >= 0) {
224
        {
225
            drive = buffer.substring(0, pos);
198
            drive = buffer.substring(0, pos);
226
        }
199
        }
227
        
200
228
        if (drive == null && m_Namespace != null)
201
        if (drive == null && m_Namespace != null) {
229
        {
230
            // Assume we don't have a path and create one from the project directory
202
            // Assume we don't have a path and create one from the project directory
231
            IProject proj = m_Namespace.getProject();
203
            IProject proj = m_Namespace.getProject();
232
            if (proj != null)
204
            if (proj != null) {
233
            {
234
                String fileName = proj.getFileName();
205
                String fileName = proj.getFileName();
235
                if (fileName != null && fileName.length() > 0)
206
                if (fileName != null && fileName.length() > 0) {
236
                {
207
                    try {
237
                    try
238
                    {
239
                        fileName = (new File(fileName)).getCanonicalPath();
208
                        fileName = (new File(fileName)).getCanonicalPath();
240
                        int posSlash = fileName.lastIndexOf(File.separator);
209
                        int posSlash = fileName.lastIndexOf(File.separator);
241
                        if (posSlash >= 0)
210
                        if (posSlash >= 0) {
242
                        {
243
                            fileName = fileName.substring(0, posSlash + 1);
211
                            fileName = fileName.substring(0, posSlash + 1);
244
                            fileName += buffer;
212
                            fileName += buffer;
245
                            buffer = fileName;
213
                            buffer = fileName;
246
                        }
214
                        }
247
                    }
215
                    } catch (Exception e) {
248
                    catch (Exception e)
249
                    {
250
                    }
216
                    }
251
                }
217
                }
252
            }
218
            }
Lines 255-264 Link Here
255
    }
221
    }
256
222
257
    @Override
223
    @Override
258
    protected boolean asynchronous()
224
    protected boolean asynchronous() {
259
    {
260
        return false;
225
        return false;
261
    }
226
    }
262
263
264
}
227
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/ExpandPackagesAction.java (-75 / +58 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.nodes.actions;
44
package org.netbeans.modules.uml.project.ui.nodes.actions;
46
45
47
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
46
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
Lines 53-135 Link Here
53
import org.openide.util.NbBundle;
52
import org.openide.util.NbBundle;
54
import org.openide.util.actions.CookieAction;
53
import org.openide.util.actions.CookieAction;
55
54
56
57
/**
55
/**
58
 *
56
 *
59
 * @author  Administrator
57
 * @author  Administrator
60
 */
58
 */
61
public class ExpandPackagesAction extends CookieAction
59
public class ExpandPackagesAction extends CookieAction {
62
{
63
	public ExpandPackagesAction()
64
	{
65
	}
66
	
67
	
68
	public String getName()
69
	{
70
		return (String)NbBundle.getBundle(ExpandPackagesAction.class)
71
			.getString("ExpandPackagesAction_Name"); // NOI18N
72
	}
73
	
74
	public int mode()
75
	{
76
		return CookieAction.MODE_ANY;
77
	}
78
	
79
	public boolean enable(Node[] nodes)
80
	{
81
		return true;
82
	}
83
	
84
	public Class[] cookieClasses()
85
	{
86
		return new Class[]{null};
87
	}
88
	
89
	public HelpCtx getHelpCtx()
90
	{
91
		return null;
92
	}
93
	
94
60
95
	public void performAction(Node[] nodes)
61
    public ExpandPackagesAction() {
96
	{
62
    }
97
		inspectChildNodes(nodes[0].getChildren());
63
98
	}
64
    public String getName() {
99
	
65
        return (String) NbBundle.getBundle(ExpandPackagesAction.class).getString("ExpandPackagesAction_Name"); // NOI18N
100
	
66
    }
101
	private void inspectChildNodes(Children children)
67
102
	{
68
    public int mode() {
103
		Node[] childNodes = children.getNodes();
69
        return CookieAction.MODE_ANY;
104
		
70
    }
105
		for (Node curChildNode : childNodes)
71
106
		{
72
    public boolean enable(Node[] nodes) {
107
			if (!curChildNode.isLeaf())
73
        return true;
108
				inspectChildNodes(curChildNode.getChildren());
74
    }
109
			
75
110
			
76
    public Class[] cookieClasses() {
111
			IElement element =
77
        return new Class[]{null};
112
					(IElement)curChildNode.getCookie(IElement.class);
78
    }
113
			
79
114
			if (element != null)
80
    public HelpCtx getHelpCtx() {
115
			{
81
        return null;
116
				String elType = element.getElementType();
82
    }
117
				
83
118
				if (elType.equals(AbstractModelElementNode.ELEMENT_TYPE_PACKAGE))
84
    public void performAction(Node[] nodes) {
119
				{
85
        inspectChildNodes(nodes[0].getChildren());
120
					expandPackageNode(curChildNode);
86
    }
121
				}
87
122
			}
88
    private void inspectChildNodes(Children children) {
123
		} // for-each curChildNode
89
        Node[] childNodes = children.getNodes();
124
	}
90
125
	
91
        for (Node curChildNode : childNodes) {
126
	private void expandPackageNode(Node packageNode)
92
            if (!curChildNode.isLeaf()) {
127
	{
93
                inspectChildNodes(curChildNode.getChildren());
128
		// TODO: expand tree to the passed-in packageNode
94
            }
129
		// if the TreeView instance can be obtained, then
95
130
		// <TreeView>.expandNode(Node) should do the trick,
96
131
		// or if the ExplorerManager/ExplorerPanel can be obtained,
97
            IElement element =
132
		// then the setExploredContext(Node) method can be used.
98
                    (IElement) curChildNode.getCookie(IElement.class);
133
		// Neither seem possible right now.
99
134
	}
100
            if (element != null) {
101
                String elType = element.getElementType();
102
103
                if (elType.equals(AbstractModelElementNode.ELEMENT_TYPE_PACKAGE)) {
104
                    expandPackageNode(curChildNode);
105
                }
106
            }
107
        } // for-each curChildNode
108
    }
109
110
    private void expandPackageNode(Node packageNode) {
111
        // TODO: expand tree to the passed-in packageNode
112
        // if the TreeView instance can be obtained, then
113
        // <TreeView>.expandNode(Node) should do the trick,
114
        // or if the ExplorerManager/ExplorerPanel can be obtained,
115
        // then the setExploredContext(Node) method can be used.
116
        // Neither seem possible right now.
117
    }
135
}
118
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/FilterAction.java (-96 / +77 lines)
Lines 41-49 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
package org.netbeans.modules.uml.project.ui.nodes.actions;
44
45
45
46
package org.netbeans.modules.uml.project.ui.nodes.actions;
47
import javax.swing.SwingUtilities;
46
import javax.swing.SwingUtilities;
48
import org.netbeans.modules.uml.ui.controls.filter.IFilterDialog;
47
import org.netbeans.modules.uml.ui.controls.filter.IFilterDialog;
49
import org.netbeans.modules.uml.ui.support.ErrorDialogIconKind;
48
import org.netbeans.modules.uml.ui.support.ErrorDialogIconKind;
Lines 64-204 Link Here
64
import org.openide.util.actions.CookieAction;
63
import org.openide.util.actions.CookieAction;
65
import org.openide.windows.WindowManager;
64
import org.openide.windows.WindowManager;
66
65
67
68
69
/**
66
/**
70
 *
67
 *
71
 * @author  Craig Conover, craig.conover@sun.com
68
 * @author  Craig Conover, craig.conover@sun.com
72
 */
69
 */
73
public class FilterAction extends CookieAction
70
public class FilterAction extends CookieAction {
74
{
71
75
    public FilterAction ()
72
    public FilterAction() {
76
    {
77
    }
73
    }
78
    
74
79
    
75
    public String getName() {
80
    public String getName ()
76
        return (String) NbBundle.getBundle(FilterAction.class).getString("FilterAction_Name"); // NOI18N
81
    {
82
        return (String)NbBundle.getBundle (FilterAction.class)
83
                .getString ("FilterAction_Name"); // NOI18N
84
    }
77
    }
85
    
78
86
    public int mode ()
79
    public int mode() {
87
    {
88
        return CookieAction.MODE_ANY;
80
        return CookieAction.MODE_ANY;
89
    }
81
    }
90
    
82
91
    public boolean enable (Node[] nodes)
83
    public boolean enable(Node[] nodes) {
92
    {
84
        if (nodes != null && nodes.length == 1) {
93
        if (nodes != null && nodes.length == 1)
94
            return true;
85
            return true;
95
        
86
        }
87
96
        return false;
88
        return false;
97
    }
89
    }
98
    
90
99
    public Class[] cookieClasses ()
91
    public Class[] cookieClasses() {
100
    {
101
        return new Class[]{null};
92
        return new Class[]{null};
102
    }
93
    }
103
    
94
104
    public HelpCtx getHelpCtx ()
95
    public HelpCtx getHelpCtx() {
105
    {
106
        return null;
96
        return null;
107
    }
97
    }
108
    
98
109
    
99
    public void performAction(final Node[] nodes) {
110
    public void performAction (final Node[] nodes)
100
        SwingUtilities.invokeLater(new Runnable() {
111
    {
101
112
        SwingUtilities.invokeLater ( new Runnable ()
102
            public void run() {
113
        { 
114
            public void run ()
115
            {
116
                // cvc - 6286956
103
                // cvc - 6286956
117
                if (!continueToFilter ())
104
                if (!continueToFilter()) {
118
                    return;
105
                    return;
119
                
106
                }
120
                ModelRootNodeCookie cookie = (ModelRootNodeCookie)nodes[0]
107
121
                        .getCookie (ModelRootNodeCookie.class);
108
                ModelRootNodeCookie cookie = (ModelRootNodeCookie) nodes[0].getCookie(ModelRootNodeCookie.class);
122
                
109
123
                if (cookie != null)
110
                if (cookie != null) {
124
                {
125
                    // cvc - CR 6271328
111
                    // cvc - CR 6271328
126
                    // only listen while Filter dialog is "alive" otherwise, all
112
                    // only listen while Filter dialog is "alive" otherwise, all
127
                    // projects will listen to each others' filter dialogs
113
                    // projects will listen to each others' filter dialogs
128
                    cookie.filterListenerRegistered (true);
114
                    cookie.filterListenerRegistered(true);
129
                    
115
130
                    // attempt to retreive the cached filter dialog
116
                    // attempt to retreive the cached filter dialog
131
                    // IFilterDialog dialog = cookie.getFilterDialog();
117
                    // IFilterDialog dialog = cookie.getFilterDialog();
132
                    DefaultTreeModel model = cookie.getTreeModelFilter ();
118
                    DefaultTreeModel model = cookie.getTreeModelFilter();
133
                    
119
134
                    IFilterDialog dialog = UIFactory.createProjectTreeFilterDialog (
120
                    IFilterDialog dialog = UIFactory.createProjectTreeFilterDialog(
135
                            WindowManager.getDefault ().getMainWindow (),
121
                            WindowManager.getDefault().getMainWindow(),
136
                            UMLProjectModule.getProjectTreeModel ());
122
                            UMLProjectModule.getProjectTreeModel());
137
                    
123
138
                    if (dialog != null)
124
                    if (dialog != null) {
139
                    {
125
                        if (model != null && dialog instanceof JFilterDialog) {
140
                        if (model != null && dialog instanceof JFilterDialog)
126
                            // reuse the same filter settings as last time
127
                            JFilterDialog filterDialog = (JFilterDialog) dialog;
128
                            filterDialog.show(model);
129
                        } else // filtered for the very first time
141
                        {
130
                        {
142
                            // reuse the same filter settings as last time
131
                            dialog.show();
143
                            JFilterDialog filterDialog = (JFilterDialog)dialog;
144
                            filterDialog.show (model);
145
                        }
132
                        }
146
                        
133
147
                        else
148
                            // filtered for the very first time
149
                            dialog.show ();
150
                        
151
                        // cvc - CR6271053
134
                        // cvc - CR6271053
152
                        // the filter's OK action will be listened to directly by
135
                        // the filter's OK action will be listened to directly by
153
                        // the node(s) that need to refresh themselves.
136
                        // the node(s) that need to refresh themselves.
154
                        // final ModelRootNodeCookie cookie =
137
                        // final ModelRootNodeCookie cookie =
155
                        //	(ModelRootNodeCookie)nodes[0].getCookie(ModelRootNodeCookie.class);
138
                        //	(ModelRootNodeCookie)nodes[0].getCookie(ModelRootNodeCookie.class);
156
                        
139
157
                        // if (cookie != null)
140
                        // if (cookie != null)
158
                        // {
141
                        // {
159
                        //	cookie.recalculateChildren();
142
                        //	cookie.recalculateChildren();
160
                        // }
143
                        // }
161
                    } // if dialog !null
144
                    } // if dialog !null
162
                    
145
163
                    // cvc - CR 6271328
146
                    // cvc - CR 6271328
164
                    // only listen while Filter dialog is "alive" otherwise, all
147
                    // only listen while Filter dialog is "alive" otherwise, all
165
                    // projects will listen to each others' filter dialogs
148
                    // projects will listen to each others' filter dialogs
166
                    cookie.filterListenerRegistered (false);
149
                    cookie.filterListenerRegistered(false);
167
                    
150
168
                } // if cookie !null
151
                } // if cookie !null
169
            }
152
            }
170
        }); 
153
        });
171
    }
154
    }
172
    
155
173
    
174
    // cvc - 6286956
156
    // cvc - 6286956
175
    // the filter should be fixed in the Coke release to work properly so
157
    // the filter should be fixed in the Coke release to work properly so
176
    // that this warning dialog is not necessary
158
    // that this warning dialog is not necessary
177
    private boolean continueToFilter ()
159
    private boolean continueToFilter() {
178
    {
179
        String key = "Default"; // NOI18N
160
        String key = "Default"; // NOI18N
180
        String path = ""; // NOI18N
161
        String path = ""; // NOI18N
181
        String name = "UML_ShowMe_Dont_Show_Filter_Warning_Dialog"; // NOI18N
162
        String name = "UML_ShowMe_Dont_Show_Filter_Warning_Dialog"; // NOI18N
182
        
163
183
        //Kris Richards - This is a "show me dialog" preference. Need to get the 
164
        //Kris Richards - This is a "show me dialog" preference. Need to get the 
184
        // preference value for the propertysupport module.
165
        // preference value for the propertysupport module.
185
        String showMe = NbPreferences.forModule(DummyCorePreference.class).get(name, "PSK_ASK");
166
        String showMe = NbPreferences.forModule(DummyCorePreference.class).get(name, "PSK_ASK");
186
        
167
187
        if (showMe.equals("PSK_NEVER"))
168
        if (showMe.equals("PSK_NEVER")) {
188
            return true ;
169
            return true;
170
        }
189
171
190
        int result = 0;
172
        int result = 0;
191
        boolean userClickedYes = true;
173
        boolean userClickedYes = true;
192
        IPreferenceQuestionDialog dialog = new SwingPreferenceQuestionDialog ();
174
        IPreferenceQuestionDialog dialog = new SwingPreferenceQuestionDialog();
193
       
175
194
        String title = NbBundle.getMessage (FilterAction.class,
176
        String title = NbBundle.getMessage(FilterAction.class,
195
                "LBL_FilterCollapseNodesWarning_Title"); // NOI18N
177
                "LBL_FilterCollapseNodesWarning_Title"); // NOI18N
196
        
178
197
        String msg = NbBundle.getMessage (FilterAction.class,
179
        String msg = NbBundle.getMessage(FilterAction.class,
198
                "MSG_FilterCollapseNodesWarning_Message"); // NOI18N
180
                "MSG_FilterCollapseNodesWarning_Message"); // NOI18N
199
        
181
200
        result =
182
        result =
201
                (int)dialog.displayFromStrings (
183
                (int) dialog.displayFromStrings(
202
                key,
184
                key,
203
                path,
185
                path,
204
                name,
186
                name,
Lines 211-237 Link Here
211
                SimpleQuestionDialogKind.SQDK_YESNO,
193
                SimpleQuestionDialogKind.SQDK_YESNO,
212
                ErrorDialogIconKind.EDIK_ICONQUESTION,
194
                ErrorDialogIconKind.EDIK_ICONQUESTION,
213
                null);
195
                null);
214
        
196
215
        if (result == SimpleQuestionDialogResultKind.SQDRK_RESULT_YES)
197
        if (result == SimpleQuestionDialogResultKind.SQDRK_RESULT_YES) {
216
            userClickedYes = true;
198
            userClickedYes = true;
217
        
199
        }
218
        if (result == SimpleQuestionDialogResultKind.SQDRK_RESULT_NO)
200
201
        if (result == SimpleQuestionDialogResultKind.SQDRK_RESULT_NO) {
219
            userClickedYes = false;
202
            userClickedYes = false;
220
        
203
        }
221
        if (result == SimpleQuestionDialogResultKind.SQDRK_RESULT_CANCEL)
204
222
            //user pressed the escape key or cancelled the save dialog
205
        if (result == SimpleQuestionDialogResultKind.SQDRK_RESULT_CANCEL) //user pressed the escape key or cancelled the save dialog
223
            //in which case do not do nothing, getback to the old state.
206
        //in which case do not do nothing, getback to the old state.
207
        {
224
            userClickedYes = false;
208
            userClickedYes = false;
225
        
209
        }
210
226
        return userClickedYes;
211
        return userClickedYes;
227
    }
212
    }
228
213
229
    @Override
214
    @Override
230
    protected boolean asynchronous()
215
    protected boolean asynchronous() {
231
    {
232
        return false;
216
        return false;
233
    }
217
    }
234
235
236
    
237
}
218
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/INewTypeExt.java (-8 / +7 lines)
Lines 41-58 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.nodes.actions;
44
package org.netbeans.modules.uml.project.ui.nodes.actions;
46
45
47
/**
46
/**
48
 *
47
 *
49
 * @author Thuy
48
 * @author Thuy
50
 */
49
 */
51
public interface INewTypeExt
50
public interface INewTypeExt {
52
{
51
53
   /**
52
    /**
54
    * Returns the resource path of an icon
53
     * Returns the resource path of an icon
55
    * @return resource path of an icon. The path should not have the initial slash
54
     * @return resource path of an icon. The path should not have the initial slash
56
    */
55
     */
57
   public String getIconResource();
56
    public String getIconResource();
58
}
57
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/ImportedElementDeletePanel.form (-2 / +3 lines)
Lines 1-9 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.1" encoding="UTF-8" ?>
2
2
3
<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
4
  <AuxValues>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
7
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
8
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
8
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
10
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
Lines 31-37 Link Here
31
              <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
32
              <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
32
              <EmptySpace type="unrelated" max="-2" attributes="0"/>
33
              <EmptySpace type="unrelated" max="-2" attributes="0"/>
33
              <Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
34
              <Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
34
              <EmptySpace pref="15" max="32767" attributes="0"/>
35
              <EmptySpace max="32767" attributes="0"/>
35
          </Group>
36
          </Group>
36
      </Group>
37
      </Group>
37
    </DimensionLayout>
38
    </DimensionLayout>
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/ImportedElementDeletePanel.java (-17 / +10 lines)
Lines 3-9 Link Here
3
 *
3
 *
4
 * Created on October 11, 2007, 12:24 PM
4
 * Created on October 11, 2007, 12:24 PM
5
 */
5
 */
6
7
package org.netbeans.modules.uml.project.ui.nodes.actions;
6
package org.netbeans.modules.uml.project.ui.nodes.actions;
8
7
9
import org.openide.nodes.Node;
8
import org.openide.nodes.Node;
Lines 14-39 Link Here
14
 * @author  Sheryl Su
13
 * @author  Sheryl Su
15
 */
14
 */
16
public class ImportedElementDeletePanel extends javax.swing.JPanel {
15
public class ImportedElementDeletePanel extends javax.swing.JPanel {
17
    
16
18
    /** Creates new form ImportedElementDeletePanel */
17
    /** Creates new form ImportedElementDeletePanel */
19
    public ImportedElementDeletePanel(Node[] nodes) {
18
    public ImportedElementDeletePanel(Node[] nodes) {
20
        initComponents();
19
        initComponents();
21
        if (nodes.length == 1)
20
        if (nodes.length == 1) {
22
        {
21
            jLabel1.setText(NbBundle.getMessage(ImportedElementDeletePanel.class,
23
            jLabel1.setText(NbBundle.getMessage(ImportedElementDeletePanel.class, 
22
                    "ImportedElementDeletePanel.MSG_ConfirmDeleteObject", nodes[0].getName()));
24
                "ImportedElementDeletePanel.MSG_ConfirmDeleteObject", nodes[0].getName()));
23
        } else {
25
        }
24
            jLabel1.setText(NbBundle.getMessage(ImportedElementDeletePanel.class,
26
        else
25
                    "ImportedElementDeletePanel.MSG_ConfirmDeleteObjects", nodes.length));
27
        {
28
            jLabel1.setText(NbBundle.getMessage(ImportedElementDeletePanel.class, 
29
                "ImportedElementDeletePanel.MSG_ConfirmDeleteObjects", nodes.length));
30
        }
26
        }
31
    }
27
    }
32
    
28
33
    public boolean getDeleteFromOriginal()
29
    public boolean getDeleteFromOriginal() {
34
    {
35
        return jCheckBox1.isSelected();
30
        return jCheckBox1.isSelected();
36
    }
31
    }
32
37
    /** This method is called from within the constructor to
33
    /** This method is called from within the constructor to
38
     * initialize the form.
34
     * initialize the form.
39
     * WARNING: Do NOT modify this code. The content of this method is
35
     * WARNING: Do NOT modify this code. The content of this method is
Lines 73-83 Link Here
73
        jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportedElementDeletePanel.class, "ImportedElementDeletePanel.jLabel1.AccessibleContext.accessibleDescription")); // NOI18N
69
        jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportedElementDeletePanel.class, "ImportedElementDeletePanel.jLabel1.AccessibleContext.accessibleDescription")); // NOI18N
74
        jCheckBox1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportedElementDeletePanel.class, "ImportedElementDeletePanel.jCheckBox1.AccessibleContext.accessibleDescription")); // NOI18N
70
        jCheckBox1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportedElementDeletePanel.class, "ImportedElementDeletePanel.jCheckBox1.AccessibleContext.accessibleDescription")); // NOI18N
75
    }// </editor-fold>//GEN-END:initComponents
71
    }// </editor-fold>//GEN-END:initComponents
76
    
77
    
78
    // Variables declaration - do not modify//GEN-BEGIN:variables
72
    // Variables declaration - do not modify//GEN-BEGIN:variables
79
    private javax.swing.JCheckBox jCheckBox1;
73
    private javax.swing.JCheckBox jCheckBox1;
80
    private javax.swing.JLabel jLabel1;
74
    private javax.swing.JLabel jLabel1;
81
    // End of variables declaration//GEN-END:variables
75
    // End of variables declaration//GEN-END:variables
82
    
83
}
76
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/NewAttributeType.java (-63 / +51 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on March 4, 2005, 4:39 PM
48
 * Created on March 4, 2005, 4:39 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.nodes.actions;
50
package org.netbeans.modules.uml.project.ui.nodes.actions;
52
51
53
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
52
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
Lines 63-129 Link Here
63
 *
62
 *
64
 * @author Craig Conover, craig.conover@sun.com
63
 * @author Craig Conover, craig.conover@sun.com
65
 */
64
 */
66
public class NewAttributeType extends NewType implements INewTypeExt
65
public class NewAttributeType extends NewType implements INewTypeExt {
67
{
66
68
	private Node node;
67
    private Node node;
69
	
68
70
	public NewAttributeType(Node node)
69
    public NewAttributeType(Node node) {
71
	{
70
        this.node = node;
72
		this.node = node;
71
    }
73
	}
72
74
	
73
    /**
75
	
74
     *
76
	/**
75
     *
77
	 *
76
     */
78
	 *
77
    public String getName() {
79
	 */
78
        return NbBundle.getMessage(NewAttributeType.class,
80
	public String getName()
79
                "NewType_Attribute_Name"); // NOI18N
81
	{
80
    }
82
		return NbBundle.getMessage(NewAttributeType.class, 
81
83
                      "NewType_Attribute_Name"); // NOI18N
82
    public String getIconResource() {
84
	}
83
        return NbBundle.getMessage(NewAttributeType.class,
85
	
84
                "ATTRIBUTE_ICON"); // NOI18N
86
        public String getIconResource()
85
    }
87
	{
86
88
		return NbBundle.getMessage(NewAttributeType.class, 
87
    /**
89
                      "ATTRIBUTE_ICON"); // NOI18N
88
     *
89
     *
90
     */
91
    public HelpCtx getHelpCtx() {
92
        return HelpCtx.DEFAULT_HELP;
93
    }
94
95
    public void create() throws java.io.IOException {
96
        // code based on legacy code from in JProjectTree.NewAttributeAction
97
98
        // this action can be invoked via the Class node or the Attributes
99
        //  container node. If it's the Attributes container node, we must get  
100
        //  it's parent (the Class node) in order to pass the next "if" test
101
        if (node.getDisplayName().equals("Attributes")) {
102
            node = node.getParentNode();
90
        }
103
        }
91
        
104
92
	/**
105
        INamespace space = null;
93
	 *
106
        IElement element = (IElement) node.getCookie(IElement.class);
94
	 *
107
95
	 */
108
        try {
96
	public HelpCtx getHelpCtx()
109
            if (element != null && element instanceof IClassifier) {
97
	{
110
                IClassifier pClass = (IClassifier) element;
98
		return HelpCtx.DEFAULT_HELP;
111
                IAttribute pAttr = pClass.createAttribute3();
99
	}
112
                pClass.addAttribute(pAttr);
100
	
113
            }
101
	
114
        } catch (Exception ex) {
102
	public void create() throws java.io.IOException
115
        }
103
	{
116
    }
104
		// code based on legacy code from in JProjectTree.NewAttributeAction
105
		
106
		// this action can be invoked via the Class node or the Attributes
107
		//  container node. If it's the Attributes container node, we must get  
108
		//  it's parent (the Class node) in order to pass the next "if" test
109
		if (node.getDisplayName().equals("Attributes"))
110
			node = node.getParentNode();
111
		
112
		INamespace space = null;
113
		IElement element = (IElement)node.getCookie(IElement.class);
114
		
115
		try
116
		{
117
			if (element != null && element instanceof IClassifier)
118
			{
119
				IClassifier pClass = (IClassifier)element;
120
				IAttribute pAttr = pClass.createAttribute3();
121
				pClass.addAttribute(pAttr);
122
			}
123
		}
124
		
125
		catch (Exception ex)
126
		{
127
		}
128
	}
129
}
117
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/NewDiagramType.java (-84 / +74 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on March 4, 2005, 4:39 PM
48
 * Created on March 4, 2005, 4:39 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.nodes.actions;
50
package org.netbeans.modules.uml.project.ui.nodes.actions;
52
51
53
import org.netbeans.api.project.Project;
52
import org.netbeans.api.project.Project;
Lines 68-153 Link Here
68
 *
67
 *
69
 * @author Craig Conover, craig.conover@sun.com
68
 * @author Craig Conover, craig.conover@sun.com
70
 */
69
 */
71
public class NewDiagramType extends NewType implements INewTypeExt
70
public class NewDiagramType extends NewType implements INewTypeExt {
72
{
71
73
	private Node node;
72
    private Node node;
74
	private IElement element = null;
73
    private IElement element = null;
75
	
74
76
	/** Creates a new instance of NewDiagramType */
75
    /** Creates a new instance of NewDiagramType */
77
	public NewDiagramType(Node node)
76
    public NewDiagramType(Node node) {
78
	{
77
        this.node = node;
79
		this.node = node;
78
    }
80
	}
79
81
	
80
    public NewDiagramType(IElement element) {
82
	public NewDiagramType(IElement element)
81
        this.element = element;
83
	{
82
    }
84
		this.element=element;
83
85
	}
84
    /**
86
	
85
     *
87
	/**
86
     *
88
	 *
87
     */
89
	 *
88
    public String getName() {
90
	 */
89
        return NbBundle.getMessage(NewDiagramType.class,
91
	public String getName()
90
                "NewType_Diagram_Name"); // NOI18N
92
	{
91
    }
93
		return NbBundle.getMessage(NewDiagramType.class, 
92
94
                      "NewType_Diagram_Name"); // NOI18N
93
    public String getIconResource() {
95
	}
94
        return NbBundle.getMessage(NewDiagramType.class,
96
	
95
                "DIAGRAM_ICON"); // NOI18N
97
	 public String getIconResource()
96
    }
98
	{
97
99
		return NbBundle.getMessage(NewDiagramType.class, 
98
    /**
100
                      "DIAGRAM_ICON"); // NOI18N
99
     *
100
     *
101
     */
102
    public HelpCtx getHelpCtx() {
103
        return HelpCtx.DEFAULT_HELP;
104
    }
105
106
    public void create() throws java.io.IOException {
107
        boolean search = false;
108
        if (node == null) {
109
            search = true;
110
            Project project = ProjectUtil.findReferencingProject(element);
111
            if (project == null) {
112
                return;
113
            }
114
            UMLPhysicalViewProvider provider = (UMLPhysicalViewProvider) project.getLookup().lookup(UMLPhysicalViewProvider.class);
115
            if (provider != null) {
116
                node = provider.getModelRootNode();
117
            }
101
        }
118
        }
102
         
119
        // code based on legacy code from in JProjectTree.NewElementAction
103
	/**
120
        IProductDiagramManager pdManager =
104
	 *
121
                ProductHelper.getProductDiagramManager();
105
	 *
122
106
	 */
123
        if (pdManager != null) {
107
	public HelpCtx getHelpCtx()
124
            if (element == null) {
108
	{
125
                element = (IElement) node.getCookie(IElement.class);
109
		return HelpCtx.DEFAULT_HELP;
126
            }
110
	}
127
111
	
128
            if (element != null && element instanceof INamespace) {
112
	
129
                IDiagram newDiagram =
113
	public void create() throws java.io.IOException
130
                        pdManager.newDiagramDialog(
114
	{
131
                        (INamespace) element,
115
		boolean search = false;
132
                        IDiagramKind.DK_UNKNOWN,
116
		if (node==null)
133
                        IDiagramKind.DK_ALL,
117
		{
134
                        null);
118
			search = true;
135
119
			Project project = ProjectUtil.findReferencingProject(element);
136
                // Fixed issue 95782. When a diagram is 1st created, its dirty state is false.
120
			if (project==null)
137
                // Set the dirty state to true to have the diagram autosaved.
121
				return;
138
                if (newDiagram != null) {
122
			UMLPhysicalViewProvider provider = (UMLPhysicalViewProvider) project.getLookup().lookup(UMLPhysicalViewProvider.class);
139
                    newDiagram.setDirty(true);
123
			if (provider!= null)
140
                    newDiagram.save();
124
				node = provider.getModelRootNode();	
141
                }
125
		}      
126
		// code based on legacy code from in JProjectTree.NewElementAction
127
		IProductDiagramManager pdManager =
128
				ProductHelper.getProductDiagramManager();
129
		
130
		if (pdManager != null)
131
		{
132
			if (element==null)
133
                            element = (IElement)node.getCookie(IElement.class);
134
			
135
			if (element != null && element instanceof INamespace)
136
                        {
137
                            IDiagram newDiagram =
138
                                    pdManager.newDiagramDialog(
139
                                    (INamespace)element,
140
                                    IDiagramKind.DK_UNKNOWN,
141
                                    IDiagramKind.DK_ALL,
142
                                    null);
143
                            
144
                            // Fixed issue 95782. When a diagram is 1st created, its dirty state is false.
145
                            // Set the dirty state to true to have the diagram autosaved.
146
                            if (newDiagram != null )
147
                            {
148
                                newDiagram.setDirty(true);
149
                                newDiagram.save();
150
                            }
151
//				if (newDiagram != null )
142
//				if (newDiagram != null )
152
//				{
143
//				{
153
//					newDiagram.save();
144
//					newDiagram.save();
Lines 169-177 Link Here
169
//						ProjectUtil.findElementInProjectTree(newDiagram);
160
//						ProjectUtil.findElementInProjectTree(newDiagram);
170
//					}
161
//					}
171
//				}
162
//				}
172
                            
173
                        }
174
		}
175
	}
176
163
164
            }
165
        }
166
    }
177
}
167
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/NewElementType.java (-90 / +75 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on March 4, 2005, 4:39 PM
48
 * Created on March 4, 2005, 4:39 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.nodes.actions;
50
package org.netbeans.modules.uml.project.ui.nodes.actions;
52
51
53
import org.netbeans.api.project.Project;
52
import org.netbeans.api.project.Project;
Lines 68-166 Link Here
68
 *
67
 *
69
 * @author Craig Conover, craig.conover@sun.com
68
 * @author Craig Conover, craig.conover@sun.com
70
 */
69
 */
71
public class NewElementType extends NewType implements INewTypeExt
70
public class NewElementType extends NewType implements INewTypeExt {
72
{
71
73
	private Node node;
72
    private Node node;
74
	private IElement element = null;
73
    private IElement element = null;
75
	
74
76
	/** Creates a new instance of NewDiagramType */
75
    /** Creates a new instance of NewDiagramType */
77
	public NewElementType(Node node)
76
    public NewElementType(Node node) {
78
	{
77
        this.node = node;
79
		this.node = node;
78
    }
80
	}
79
81
	
80
    public NewElementType(IElement element) {
82
	public NewElementType(IElement element)
81
        this.element = element;
83
	{
82
    }
84
		this.element = element;
83
85
	}
84
    /**
86
	/**
85
     *
87
	 *
86
     *
88
	 *
87
     */
89
	 */
88
    public String getName() {
90
	public String getName()
89
        return NbBundle.getMessage(NewElementType.class,
91
	{
90
                "NewType_Element_Name"); // NOI18N
92
		return NbBundle.getMessage(NewElementType.class, 
91
    }
93
                      "NewType_Element_Name"); // NOI18N
92
94
	}
93
    public String getIconResource() {
95
	
94
        return NbBundle.getMessage(NewElementType.class,
96
        public String getIconResource()
95
                "ELEM_ICON"); // NOI18N
97
	{
96
    }
98
		return NbBundle.getMessage(NewElementType.class, 
97
99
                      "ELEM_ICON"); // NOI18N
98
    /**
99
     *
100
     *
101
     */
102
    public HelpCtx getHelpCtx() {
103
        return HelpCtx.DEFAULT_HELP;
104
    }
105
106
    public void create() throws java.io.IOException {
107
        // code based on legacy code from in JProjectTree.NewElementAction
108
109
        INamespace space = null;
110
        if (element == null) {
111
            element = (IElement) node.getCookie(IElement.class);
100
        }
112
        }
101
	
113
102
	/**
114
        if (node == null) {
103
	 *
115
            Project project = ProjectUtil.findReferencingProject(element);
104
	 *
116
            UMLPhysicalViewProvider provider = (UMLPhysicalViewProvider) project.getLookup().lookup(UMLPhysicalViewProvider.class);
105
	 */
117
            if (provider != null) {
106
	public HelpCtx getHelpCtx()
118
                node = provider.getModelRootNode();
107
	{
119
            }
108
		return HelpCtx.DEFAULT_HELP;
120
        }
109
	}
121
110
	
122
        if (node instanceof UMLDiagramNode) {
111
	
123
            // cvc - CR 6287660
112
	public void create() throws java.io.IOException
124
            while (element == null && node != null) {
113
	{
125
                node = node.getParentNode();
114
		// code based on legacy code from in JProjectTree.NewElementAction
126
                if (node != null) {
115
		
127
                    element = (IElement) node.getCookie(IElement.class);
116
		INamespace space = null;
128
                }
117
		if (element == null)
129
            }
118
			element = (IElement)node.getCookie(IElement.class);
130
        }
119
		
131
120
		if (node==null)
132
        if (element != null) {
121
		{
133
            if (element instanceof INamespace) {
122
			Project project = ProjectUtil.findReferencingProject(element);
134
                space = (INamespace) element;
123
			UMLPhysicalViewProvider provider = (UMLPhysicalViewProvider) 
135
            } else if (element instanceof INamedElement) {
124
					project.getLookup().lookup(UMLPhysicalViewProvider.class);
136
                //get the parent namespace
125
			if (provider!= null)
137
                space = ((INamedElement) element).getNamespace();
126
				node = provider.getModelRootNode();	
138
            }
127
		}      
139
        }
128
		
140
129
		if (node instanceof UMLDiagramNode)
141
        IProxyUserInterface proxyUI = ProductHelper.getProxyUserInterface();
130
		{
142
        if (proxyUI != null && space != null) {
131
			// cvc - CR 6287660
143
            IElement newElement = proxyUI.newElementDialog(space);
132
			while (element == null && node != null)
133
			{
134
				node = node.getParentNode();
135
				if (node != null)
136
					element = (IElement)node.getCookie(IElement.class);
137
			}
138
		}
139
		
140
		if (element != null)
141
		{
142
			if (element instanceof INamespace)
143
			{
144
				space = (INamespace)element;
145
			}
146
			
147
			else if (element instanceof INamedElement)
148
			{
149
				//get the parent namespace
150
				space = ((INamedElement)element).getNamespace();
151
			}
152
		}
153
		
154
		IProxyUserInterface proxyUI = ProductHelper.getProxyUserInterface();
155
		if (proxyUI != null && space != null)
156
		{
157
			IElement newElement = proxyUI.newElementDialog(space);
158
//			if (newElement != null && newElement instanceof INamedElement)
144
//			if (newElement != null && newElement instanceof INamedElement)
159
//			{
145
//			{
160
//				UMLProjectModule.getProjectTreeEngine().addNewlyCreatedElement((INamedElement)newElement);
146
//				UMLProjectModule.getProjectTreeEngine().addNewlyCreatedElement((INamedElement)newElement);
161
//				ProjectUtil.findElementInProjectTree(newElement);  
147
//				ProjectUtil.findElementInProjectTree(newElement);  
162
//			}
148
//			}
163
		}
149
        }
164
	}
150
    }
165
	
166
}
151
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/NewLiteralType.java (-75 / +61 lines)
Lines 47-61 Link Here
47
 *
47
 *
48
 * Created on March 4, 2005, 4:39 PM
48
 * Created on March 4, 2005, 4:39 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.nodes.actions;
50
package org.netbeans.modules.uml.project.ui.nodes.actions;
52
51
53
import org.netbeans.modules.uml.core.metamodel.core.constructs.IEnumeration;
52
import org.netbeans.modules.uml.core.metamodel.core.constructs.IEnumeration;
54
import org.netbeans.modules.uml.core.metamodel.core.constructs.IEnumerationLiteral;
53
import org.netbeans.modules.uml.core.metamodel.core.constructs.IEnumerationLiteral;
55
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
54
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
56
import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
55
import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
57
import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
58
import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IOperation;
59
import org.netbeans.modules.uml.core.preferenceframework.IPreferenceAccessor;
56
import org.netbeans.modules.uml.core.preferenceframework.IPreferenceAccessor;
60
import org.netbeans.modules.uml.core.preferenceframework.PreferenceAccessor;
57
import org.netbeans.modules.uml.core.preferenceframework.PreferenceAccessor;
61
import org.openide.nodes.Node;
58
import org.openide.nodes.Node;
Lines 67-143 Link Here
67
 *
64
 *
68
 * @author Sergey Petrov
65
 * @author Sergey Petrov
69
 */
66
 */
70
public class NewLiteralType extends NewType implements INewTypeExt
67
public class NewLiteralType extends NewType implements INewTypeExt {
71
{
68
72
	private Node node;
69
    private Node node;
73
	
70
74
	public NewLiteralType(Node node)
71
    public NewLiteralType(Node node) {
75
	{
72
        this.node = node;
76
		this.node = node;
73
    }
77
	}
74
78
	
75
    /**
79
	
76
     *
80
	/**
77
     *
81
	 *
78
     */
82
	 *
79
    public String getName() {
83
	 */
80
        return NbBundle.getMessage(NewLiteralType.class,
84
	public String getName()
81
                "NewType_Literal_Name"); // NOI18N
85
	{
82
    }
86
		return NbBundle.getMessage(NewLiteralType.class, 
83
87
                      "NewType_Literal_Name"); // NOI18N
84
    public String getIconResource() {
88
	}
85
        return NbBundle.getMessage(NewLiteralType.class,
89
	
86
                "LITERAL_ICON"); // NOI18N
90
        public String getIconResource()
87
    }
91
	{
88
92
		return NbBundle.getMessage(NewLiteralType.class, 
89
    /**
93
                      "LITERAL_ICON"); // NOI18N
90
     *
91
     *
92
     */
93
    public HelpCtx getHelpCtx() {
94
        return HelpCtx.DEFAULT_HELP;
95
    }
96
97
    public void create() throws java.io.IOException {
98
        // code based on legacy code from in JProjectTree.NewOperationAction
99
100
        // this action supposed to be invoken on Enumeration only
101
102
        INamespace space = null;
103
        IElement element = (IElement) node.getCookie(IElement.class);
104
105
        try {
106
            if (element != null && element instanceof IEnumeration) {
107
                IEnumeration pEnu = (IEnumeration) element;
108
                IEnumerationLiteral pLi = pEnu.createLiteral(retrieveDefaultName());
109
                pEnu.addLiteral(pLi);
110
            }
111
        } catch (Exception ex) {
94
        }
112
        }
95
	
113
    }
96
	/**
114
97
	 *
115
    /**
98
	 *
116
     *
99
	 */
117
     * Retrieves the default name for use for model elements that are just
100
	public HelpCtx getHelpCtx()
118
     * being created.
101
	{
119
     *
102
		return HelpCtx.DEFAULT_HELP;
120
     * @return the default name of the model element
103
	}
121
     *
104
	
122
     */
105
	
123
    protected String retrieveDefaultName() {
106
	public void create() throws java.io.IOException
124
        String name = "";
107
	{
125
        IPreferenceAccessor pref = PreferenceAccessor.instance();
108
		// code based on legacy code from in JProjectTree.NewOperationAction
126
        name = pref.getDefaultElementName();
109
		
127
        return name;
110
		// this action supposed to be invoken on Enumeration only
128
    }
111
		
112
		INamespace space = null;
113
		IElement element = (IElement)node.getCookie(IElement.class);
114
		
115
		try
116
		{
117
			if (element != null && element instanceof IEnumeration)
118
			{
119
				IEnumeration pEnu = (IEnumeration)element;
120
				IEnumerationLiteral pLi = pEnu.createLiteral(retrieveDefaultName());
121
				pEnu.addLiteral(pLi);
122
			}
123
		}
124
		
125
		catch (Exception ex)
126
		{
127
		}
128
	}
129
	/**
130
	 *
131
	 * Retrieves the default name for use for model elements that are just
132
	 * being created.
133
	 *
134
	 * @return the default name of the model element
135
	 *
136
	 */
137
	protected String retrieveDefaultName() {
138
		String name = "";
139
		IPreferenceAccessor pref = PreferenceAccessor.instance();
140
		name = pref.getDefaultElementName();
141
		return name;
142
	}
143
}
129
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/NewOperationType.java (-63 / +51 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on March 4, 2005, 4:39 PM
48
 * Created on March 4, 2005, 4:39 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.nodes.actions;
50
package org.netbeans.modules.uml.project.ui.nodes.actions;
52
51
53
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
52
import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
Lines 63-129 Link Here
63
 *
62
 *
64
 * @author Craig Conover, craig.conover@sun.com
63
 * @author Craig Conover, craig.conover@sun.com
65
 */
64
 */
66
public class NewOperationType extends NewType implements INewTypeExt
65
public class NewOperationType extends NewType implements INewTypeExt {
67
{
66
68
	private Node node;
67
    private Node node;
69
	
68
70
	public NewOperationType(Node node)
69
    public NewOperationType(Node node) {
71
	{
70
        this.node = node;
72
		this.node = node;
71
    }
73
	}
72
74
	
73
    /**
75
	
74
     *
76
	/**
75
     *
77
	 *
76
     */
78
	 *
77
    public String getName() {
79
	 */
78
        return NbBundle.getMessage(NewOperationType.class,
80
	public String getName()
79
                "NewType_Operation_Name"); // NOI18N
81
	{
80
    }
82
		return NbBundle.getMessage(NewOperationType.class, 
81
83
                      "NewType_Operation_Name"); // NOI18N
82
    public String getIconResource() {
84
	}
83
        return NbBundle.getMessage(NewOperationType.class,
85
	
84
                "OPERATION_ICON"); // NOI18N
86
        public String getIconResource()
85
    }
87
	{
86
88
		return NbBundle.getMessage(NewOperationType.class, 
87
    /**
89
                      "OPERATION_ICON"); // NOI18N
88
     *
89
     *
90
     */
91
    public HelpCtx getHelpCtx() {
92
        return HelpCtx.DEFAULT_HELP;
93
    }
94
95
    public void create() throws java.io.IOException {
96
        // code based on legacy code from in JProjectTree.NewOperationAction
97
98
        // this action can be invoked via the Class node or the Operations
99
        //  container node. If it's the Operations container node, we must get  
100
        //  it's parent (the Class node) in order to pass the next "if" test
101
        if (node.getDisplayName().equals("Operations")) {
102
            node = node.getParentNode();
90
        }
103
        }
91
	
104
92
	/**
105
        INamespace space = null;
93
	 *
106
        IElement element = (IElement) node.getCookie(IElement.class);
94
	 *
107
95
	 */
108
        try {
96
	public HelpCtx getHelpCtx()
109
            if (element != null && element instanceof IClassifier) {
97
	{
110
                IClassifier pClass = (IClassifier) element;
98
		return HelpCtx.DEFAULT_HELP;
111
                IOperation pOp = pClass.createOperation3();
99
	}
112
                pClass.addOperation(pOp);
100
	
113
            }
101
	
114
        } catch (Exception ex) {
102
	public void create() throws java.io.IOException
115
        }
103
	{
116
    }
104
		// code based on legacy code from in JProjectTree.NewOperationAction
105
		
106
		// this action can be invoked via the Class node or the Operations
107
		//  container node. If it's the Operations container node, we must get  
108
		//  it's parent (the Class node) in order to pass the next "if" test
109
		if (node.getDisplayName().equals("Operations"))
110
			node = node.getParentNode();
111
		
112
		INamespace space = null;
113
		IElement element = (IElement)node.getCookie(IElement.class);
114
		
115
		try
116
		{
117
			if (element != null && element instanceof IClassifier)
118
			{
119
				IClassifier pClass = (IClassifier)element;
120
				IOperation pOp = pClass.createOperation3();
121
				pClass.addOperation(pOp);
122
			}
123
		}
124
		
125
		catch (Exception ex)
126
		{
127
		}
128
	}
129
}
117
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/NewPackageType.java (-87 / +73 lines)
Lines 47-53 Link Here
47
 *
47
 *
48
 * Created on March 4, 2005, 4:39 PM
48
 * Created on March 4, 2005, 4:39 PM
49
 */
49
 */
50
51
package org.netbeans.modules.uml.project.ui.nodes.actions;
50
package org.netbeans.modules.uml.project.ui.nodes.actions;
52
51
53
import org.netbeans.api.project.Project;
52
import org.netbeans.api.project.Project;
Lines 68-158 Link Here
68
 *
67
 *
69
 * @author Craig Conover, craig.conover@sun.com
68
 * @author Craig Conover, craig.conover@sun.com
70
 */
69
 */
71
public class NewPackageType extends NewType implements INewTypeExt
70
public class NewPackageType extends NewType implements INewTypeExt {
72
{
71
73
	private Node node;
72
    private Node node;
74
	private IElement element = null;
73
    private IElement element = null;
75
	
74
76
	/** Creates a new instance of NewDiagramType */
75
    /** Creates a new instance of NewDiagramType */
77
	public NewPackageType(Node node)
76
    public NewPackageType(Node node) {
78
	{
77
        this.node = node;
79
		this.node = node;
78
    }
80
	}
79
81
	
80
    public NewPackageType(IElement element) {
82
	public NewPackageType(IElement element)
81
        this.element = element;
83
	{
82
    }
84
		this.element = element;
83
85
	}
84
    /**
86
	
85
     *
87
	/**
86
     *
88
	 *
87
     */
89
	 *
88
    public String getName() {
90
	 */
89
        return NbBundle.getMessage(NewPackageType.class,
91
	public String getName()
90
                "NewType_Package_Name"); // NOI18N
92
	{
91
    }
93
		return NbBundle.getMessage(NewPackageType.class, 
92
94
                      "NewType_Package_Name"); // NOI18N
93
    public String getIconResource() {
95
	}
94
        return NbBundle.getMessage(NewPackageType.class,
96
	
95
                "PACKAGE_ICON"); // NOI18N
97
	public String getIconResource()
96
    }
98
	{
97
99
		return NbBundle.getMessage(NewPackageType.class, 
98
    /**
100
                      "PACKAGE_ICON"); // NOI18N
99
     *
100
     *
101
     */
102
    public HelpCtx getHelpCtx() {
103
        return HelpCtx.DEFAULT_HELP;
104
    }
105
106
    public void create() throws java.io.IOException {
107
        // code based on legacy code from in JProjectTree.NewPackageAction
108
        if (node == null) {
109
            Project project = ProjectUtil.findReferencingProject(element);
110
            UMLPhysicalViewProvider provider = (UMLPhysicalViewProvider) project.getLookup().lookup(UMLPhysicalViewProvider.class);
111
            if (provider != null) {
112
                node = provider.getModelRootNode();
113
            }
101
        }
114
        }
102
        
115
        INamespace space = null;
103
	/**
116
        if (element == null) {
104
	 *
117
            element = (IElement) node.getCookie(IElement.class);
105
	 *
118
        }
106
	 */
119
107
	public HelpCtx getHelpCtx()
120
        if (node instanceof UMLDiagramNode) {
108
	{
121
            // cvc - CR 6287660
109
		return HelpCtx.DEFAULT_HELP;
122
            while (element == null && node != null) {
110
	}
123
                node = node.getParentNode();
111
	
124
                if (node != null) {
112
	
125
                    element = (IElement) node.getCookie(IElement.class);
113
	public void create() throws java.io.IOException
126
                }
114
	{
127
            }
115
		// code based on legacy code from in JProjectTree.NewPackageAction
128
        }
116
		if (node==null)
129
117
		{
130
        if (element != null) {
118
			Project project = ProjectUtil.findReferencingProject(element);
131
            if (element instanceof INamespace) {
119
			UMLPhysicalViewProvider provider = (UMLPhysicalViewProvider) 
132
                space = (INamespace) element;
120
					project.getLookup().lookup(UMLPhysicalViewProvider.class);
133
            } else if (element instanceof INamedElement) {
121
			if (provider!= null)
134
                //get the parent namespace
122
				node = provider.getModelRootNode();	
135
                space = ((INamedElement) element).getNamespace();
123
		}      
136
            }
124
		INamespace space = null;
137
        }
125
		if (element == null)
138
126
			element = (IElement)node.getCookie(IElement.class);
139
        IProxyUserInterface proxyUI = ProductHelper.getProxyUserInterface();
127
		
140
        if (proxyUI != null && space != null) {
128
		if (node instanceof UMLDiagramNode)
141
            IElement pkg = proxyUI.newPackageDialog(space);
129
		{
130
			// cvc - CR 6287660
131
			while (element == null && node != null)
132
			{
133
				node = node.getParentNode();
134
				if (node != null)
135
					element = (IElement)node.getCookie(IElement.class);
136
			}
137
		}
138
		
139
		if (element != null)
140
		{
141
			if (element instanceof INamespace)
142
			{
143
				space = (INamespace)element;
144
			}
145
			else if (element instanceof INamedElement)
146
			{
147
				//get the parent namespace
148
				space = ((INamedElement)element).getNamespace();
149
			}
150
		}
151
		
152
		IProxyUserInterface proxyUI = ProductHelper.getProxyUserInterface();
153
		if (proxyUI != null && space != null)
154
		{
155
			IElement pkg = proxyUI.newPackageDialog(space);
156
//			if (pkg != null && pkg instanceof INamedElement)
142
//			if (pkg != null && pkg instanceof INamedElement)
157
//			{
143
//			{
158
//				UMLProjectModule.getProjectTreeEngine().
144
//				UMLProjectModule.getProjectTreeEngine().
Lines 160-165 Link Here
160
//				ProjectUtil.findElementInProjectTree(pkg);  
146
//				ProjectUtil.findElementInProjectTree(pkg);  
161
//			}
147
//			}
162
148
163
		}
149
        }
164
	}
150
    }
165
}
151
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/UMLDeleteImportedElementAction.java (-50 / +26 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes.actions;
44
package org.netbeans.modules.uml.project.ui.nodes.actions;
47
45
48
import java.awt.Dialog;
46
import java.awt.Dialog;
Lines 60-100 Link Here
60
import org.openide.util.NbBundle;
58
import org.openide.util.NbBundle;
61
import org.openide.util.actions.CookieAction;
59
import org.openide.util.actions.CookieAction;
62
60
63
@org.openide.util.lookup.ServiceProvider(service=org.openide.explorer.ExtendedDelete.class)
61
@org.openide.util.lookup.ServiceProvider(service = org.openide.explorer.ExtendedDelete.class)
64
public final class UMLDeleteImportedElementAction extends CookieAction implements ExtendedDelete
62
public final class UMLDeleteImportedElementAction extends CookieAction implements ExtendedDelete {
65
{
66
63
67
    public boolean delete(final Node[] nodes) throws IOException
64
    public boolean delete(final Node[] nodes) throws IOException {
68
    {
65
        if (enable(nodes)) {
69
        if (enable(nodes))
66
            if (java.awt.EventQueue.isDispatchThread()) {
70
        {
71
            if (java.awt.EventQueue.isDispatchThread())
72
            {
73
                performAction(nodes);
67
                performAction(nodes);
74
            } else
68
            } else {
75
            {
69
                SwingUtilities.invokeLater(new Runnable() {
76
                SwingUtilities.invokeLater(new Runnable()
70
77
                {
71
                    public void run() {
78
                    public void run()
79
                    {
80
                        performAction(nodes);
72
                        performAction(nodes);
81
                    }
73
                    }
82
                });
74
                });
83
            }
75
            }
84
            return true;
76
            return true;
85
        } else
77
        } else {
86
        {
87
            return false;
78
            return false;
88
        }
79
        }
89
    }
80
    }
90
81
91
    protected void performAction(Node[] activatedNodes)
82
    protected void performAction(Node[] activatedNodes) {
92
    {
83
        if (activatedNodes.length == 0) {
93
        if (activatedNodes.length == 0)
94
        {
95
            return;
84
            return;
96
        }
85
        }
97
        
86
98
        ImportedElementDeletePanel panel = new ImportedElementDeletePanel(activatedNodes);
87
        ImportedElementDeletePanel panel = new ImportedElementDeletePanel(activatedNodes);
99
        String title = NbBundle.getMessage(UMLDeleteImportedElementAction.class,
88
        String title = NbBundle.getMessage(UMLDeleteImportedElementAction.class,
100
                "TITLE_ConfirmDeleteImportedElement");
89
                "TITLE_ConfirmDeleteImportedElement");
Lines 106-172 Link Here
106
        Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
95
        Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
107
        dialog.getAccessibleContext().setAccessibleDescription(title);
96
        dialog.getAccessibleContext().setAccessibleDescription(title);
108
97
109
        try
98
        try {
110
        {
111
            dialog.setVisible(true);
99
            dialog.setVisible(true);
112
            if (dialogDescriptor.getValue() == DialogDescriptor.YES_OPTION)
100
            if (dialogDescriptor.getValue() == DialogDescriptor.YES_OPTION) {
113
            {
114
                boolean deleteOriginal = panel.getDeleteFromOriginal();
101
                boolean deleteOriginal = panel.getDeleteFromOriginal();
115
102
116
                for (Node node : activatedNodes)
103
                for (Node node : activatedNodes) {
117
                {
104
                    if (deleteOriginal) {
118
                    if (deleteOriginal)
119
                    {
120
                        node.destroy();
105
                        node.destroy();
121
                    } else
106
                    } else {
122
                    {
123
                        ImportedElementCookie cookie = node.getLookup().lookup(ImportedElementCookie.class);
107
                        ImportedElementCookie cookie = node.getLookup().lookup(ImportedElementCookie.class);
124
                        cookie.removeImportedElement();
108
                        cookie.removeImportedElement();
125
                    }
109
                    }
126
                }
110
                }
127
            }
111
            }
128
        } catch (Exception e)
112
        } catch (Exception e) {
129
        {
130
            Logger.getLogger(UMLDeleteImportedElementAction.class.getName()).log(Level.SEVERE,
113
            Logger.getLogger(UMLDeleteImportedElementAction.class.getName()).log(Level.SEVERE,
131
                    e.getLocalizedMessage());
114
                    e.getLocalizedMessage());
132
        } finally
115
        } finally {
133
        {
134
            dialog.dispose();
116
            dialog.dispose();
135
        }
117
        }
136
    }
118
    }
137
119
138
    protected int mode()
120
    protected int mode() {
139
    {
140
        return CookieAction.MODE_ALL;
121
        return CookieAction.MODE_ALL;
141
    }
122
    }
142
123
143
    public String getName()
124
    public String getName() {
144
    {
145
        return NbBundle.getMessage(UMLDeleteImportedElementAction.class,
125
        return NbBundle.getMessage(UMLDeleteImportedElementAction.class,
146
                "CTL_RemoveFromImport");
126
                "CTL_RemoveFromImport");
147
    }
127
    }
148
128
149
    protected Class[] cookieClasses()
129
    protected Class[] cookieClasses() {
150
    {
151
        return new Class[]{ImportedElementCookie.class};
130
        return new Class[]{ImportedElementCookie.class};
152
    }
131
    }
153
132
154
    @Override
133
    @Override
155
    protected void initialize()
134
    protected void initialize() {
156
    {
157
        super.initialize();
135
        super.initialize();
158
        // see org.openide.util.actions.SystemAction.iconResource() javadoc for more details
136
        // see org.openide.util.actions.SystemAction.iconResource() javadoc for more details
159
        putValue("noIconInMenu", Boolean.TRUE);
137
        putValue("noIconInMenu", Boolean.TRUE);
160
    }
138
    }
161
139
162
    public HelpCtx getHelpCtx()
140
    public HelpCtx getHelpCtx() {
163
    {
164
        return HelpCtx.DEFAULT_HELP;
141
        return HelpCtx.DEFAULT_HELP;
165
    }
142
    }
166
143
167
    @Override
144
    @Override
168
    protected boolean asynchronous()
145
    protected boolean asynchronous() {
169
    {
170
        return false;
146
        return false;
171
    }
147
    }
172
}
148
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/nodes/actions/UMLNewAction.java (-361 / +289 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
46
package org.netbeans.modules.uml.project.ui.nodes.actions;
44
package org.netbeans.modules.uml.project.ui.nodes.actions;
47
45
48
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionEvent;
Lines 64-160 Link Here
64
import org.openide.util.ImageUtilities;
62
import org.openide.util.ImageUtilities;
65
import org.openide.util.Lookup;
63
import org.openide.util.Lookup;
66
import org.openide.util.NbBundle;
64
import org.openide.util.NbBundle;
67
import org.openide.util.Utilities;
68
import org.openide.util.actions.NodeAction;
65
import org.openide.util.actions.NodeAction;
69
import org.openide.util.actions.Presenter;
66
import org.openide.util.actions.Presenter;
70
import org.openide.util.datatransfer.NewType;
67
import org.openide.util.datatransfer.NewType;
71
import org.openide.windows.WindowManager;
68
import org.openide.windows.WindowManager;
72
69
70
public class UMLNewAction extends NodeAction {
73
71
74
public class UMLNewAction extends NodeAction
72
    private static ActSubMenuModel model = new ActSubMenuModel(null);
75
{
73
76
   private static ActSubMenuModel model = new ActSubMenuModel(null);
74
    protected void performAction(Node[] activatedNodes) {
77
   
75
        performAction(activatedNodes, 0);
78
   protected void performAction(Node[] activatedNodes)
76
    }
79
   {
77
80
      performAction(activatedNodes, 0);
78
    protected boolean asynchronous() {
81
   }
79
        return false;
82
   
80
    }
83
   protected boolean asynchronous()
81
84
   {
82
    /** Performs action on index and nodes.
85
      return false;
83
     */
86
   }
84
    private static void performAction(Node[] activatedNodes, int indx) {
87
   
85
        NewType[] types = getNewTypes(activatedNodes);
88
   /** Performs action on index and nodes.
86
89
    */
87
        if (types.length <= indx) {
90
   private static void performAction(Node[] activatedNodes, int indx)
88
            return;
91
   {
89
        }
92
      NewType[] types = getNewTypes(activatedNodes);
90
        NewType type = types[indx];
93
      
91
        try {
94
      if (types.length <= indx)
92
            type.create();
95
      {
93
        } catch (java.io.IOException e) {
96
         return;
94
            Exceptions.printStackTrace(e);
97
      }
95
        }
98
      NewType type = types[indx];
96
    }
99
      try
97
100
      {
98
    private static NewType[] getNewTypes() {
101
         type.create();
99
        return getNewTypes(WindowManager.getDefault().getRegistry().getCurrentNodes());
102
      }
100
    }
103
      catch (java.io.IOException e)
101
104
      {
102
    /** Getter for array of activated new types.
105
         Exceptions.printStackTrace(e);
103
     */
106
      }
104
    private static NewType[] getNewTypes(Node[] activatedNodes) {
107
   }
105
        if ((activatedNodes == null) || (activatedNodes.length != 1)) {
108
   
106
            return new NewType[0];
109
   private static NewType[] getNewTypes()
107
        } else {
110
   {
108
            return activatedNodes[0].getNewTypes();
111
      return getNewTypes(WindowManager.getDefault().getRegistry().getCurrentNodes());
109
        }
112
   }
110
    }
113
   
111
114
   /** Getter for array of activated new types.
112
    protected boolean enable(Node[] activatedNodes) {
115
    */
113
        NewType[] types = getNewTypes();
116
   private static NewType[] getNewTypes(Node[] activatedNodes)
114
        model.cs.fireChange();
117
   {
115
        return (types.length > 0);
118
      if ((activatedNodes == null) || (activatedNodes.length != 1))
116
    }
119
      {
117
120
         return new NewType[0];
118
    public String getName() {
121
      }
119
        return createName(getNewTypes());
122
      else
120
    }
123
      {
121
124
         return activatedNodes[0].getNewTypes();
122
    public HelpCtx getHelpCtx() {
125
      }
123
        return new HelpCtx(UMLNewAction.class);
126
   }
124
    }
127
   
125
128
   protected boolean enable(Node[] activatedNodes)
126
    public javax.swing.JMenuItem getPopupPresenter() {
129
   {
127
        return new Actions.SubMenu(this, model, true);
130
      NewType[] types = getNewTypes();
128
    }
131
      model.cs.fireChange();
129
132
      return (types.length > 0);
130
    public javax.swing.Action createContextAwareInstance(Lookup actionContext) {
133
   }
131
        return new DelegateAction(this, actionContext);
134
   
132
    }
135
   public String getName()
133
136
   {
134
    /** Utility method, creates name for action depending on specified new types. */
137
      return createName(getNewTypes());
135
    private static String createName(NewType[] newTypes) {
138
   }
139
   
140
   public HelpCtx getHelpCtx()
141
   {
142
      return new HelpCtx(UMLNewAction.class);
143
   }
144
   
145
   public javax.swing.JMenuItem getPopupPresenter()
146
   {
147
      return new Actions.SubMenu(this, model, true);
148
   }
149
   
150
   public javax.swing.Action createContextAwareInstance(Lookup actionContext)
151
   {
152
      return new DelegateAction(this, actionContext);
153
   }
154
   
155
   /** Utility method, creates name for action depending on specified new types. */
156
   private static String createName(NewType[] newTypes)
157
   {
158
//      if ((newTypes != null) && (newTypes.length == 1))
136
//      if ((newTypes != null) && (newTypes.length == 1))
159
//      {
137
//      {
160
//         return NbBundle.getMessage(UMLNewAction.class, 
138
//         return NbBundle.getMessage(UMLNewAction.class, 
Lines 163-444 Link Here
163
//      }
141
//      }
164
//      else
142
//      else
165
//      {
143
//      {
166
         return NbBundle.getMessage(UMLNewAction.class, 
144
        return NbBundle.getMessage(UMLNewAction.class,
167
               "LBL_New_Menu", "");  // NOI18N
145
                "LBL_New_Menu", "");  // NOI18N
168
//      }
146
//      }
169
   }
147
    }
170
   
171
148
172
   private static class ActSubMenuModel implements Actions.SubMenuModel
149
    private static class ActSubMenuModel implements Actions.SubMenuModel {
173
   {
150
174
      static final long serialVersionUID = -1L;
151
        static final long serialVersionUID = -1L;
175
      
152
        final ChangeSupport cs = new ChangeSupport(this);
176
      final ChangeSupport cs = new ChangeSupport(this);
153
        /** lookup to read the new types from or null if they whould be taken
177
      
154
         * directly from top component's selected nodes
178
      /** lookup to read the new types from or null if they whould be taken
155
         */
179
       * directly from top component's selected nodes
156
        private Lookup lookup;
180
       */
157
        private Node prevNode;
181
      private Lookup lookup;
158
        private NewType[] prevTypes;
182
      private Node prevNode;
159
183
      private NewType[] prevTypes;
160
        ActSubMenuModel(Lookup lookup) {
184
      
161
            this.lookup = lookup;
185
      ActSubMenuModel(Lookup lookup)
162
        }
186
      {
163
187
         this.lookup = lookup;
164
        private NewType[] newTypes() {
188
      }
165
            if (lookup != null) {
189
      
166
                java.util.Collection lkupResult = lookup.lookupResult(Node.class).allItems();
190
      private NewType[] newTypes()
167
191
      {
168
                if (lkupResult != null && lkupResult.size() == 1) {
192
         if (lookup != null)
169
                    java.util.Iterator it = lkupResult.iterator();
193
         {
170
194
            java.util.Collection lkupResult = lookup.lookupResult(Node.class).allItems();
171
                    while (it.hasNext()) {
195
            
172
                        Lookup.Item item = (Lookup.Item) it.next();
196
            if (lkupResult != null && lkupResult.size() == 1)
173
                        Node node = (Node) item.getInstance();
197
            {
174
198
               java.util.Iterator it = lkupResult.iterator();
175
                        if (node != null) {
199
               
176
                            if (node == prevNode && prevTypes != null) {
200
               while (it.hasNext())
177
                                return prevTypes;
201
               {
178
                            }
202
                  Lookup.Item item = (Lookup.Item) it.next();
179
                            prevNode = node;
203
                  Node node = (Node) item.getInstance();
180
                            prevTypes = node.getNewTypes();
204
                  
181
                            return prevTypes;
205
                  if (node != null)
182
                        }
206
                  {
183
                    }
207
                     if (node == prevNode && prevTypes != null)
184
                }
208
                     {
209
                        return prevTypes;
210
                     }
211
                     prevNode = node;
212
                     prevTypes = node.getNewTypes();
213
                     return prevTypes;
214
                  }
215
               }
216
            }
185
            }
217
         }
186
218
         
187
            return getNewTypes();
219
         return getNewTypes();
188
        }
220
      }
189
221
      
190
        public int getCount() {
222
      public int getCount()
191
            return newTypes().length;
223
      {
192
        }
224
         return newTypes().length;
193
225
      }
194
        public String getLabel(int index) {
226
      
195
            NewType[] newTypes = newTypes();
227
      public String getLabel(int index)
196
228
      {
197
            if (newTypes == null || newTypes.length <= index) {
229
         NewType[] newTypes = newTypes();
198
                return null;
230
         
199
            } else {
231
         if (newTypes == null || newTypes.length <= index)
200
                return newTypes[index].getName();
232
         {
233
            return null;
234
         }
235
         else
236
         {
237
            return newTypes[index].getName();
238
         }
239
      }
240
      
241
      public String getIconResource(int index)
242
      {
243
         String iconRes = null;
244
         NewType[] newTypes = newTypes();
245
         if (newTypes != null && newTypes.length > index)
246
         {
247
            NewType type = newTypes[index];
248
            iconRes = (type instanceof INewTypeExt ? ((INewTypeExt)type).getIconResource() : null);
249
         }
250
         return iconRes;
251
      }
252
      
253
      public HelpCtx getHelpCtx(int index)
254
      {
255
         NewType[] newTypes = newTypes();
256
         
257
         if (newTypes == null || newTypes.length <= index)
258
         {
259
            return null;
260
         }
261
         else
262
         {
263
            return newTypes[index].getHelpCtx();
264
         }
265
      }
266
      
267
      public void performActionAt(int index)
268
      {
269
         NewType[] nt = newTypes();
270
         
271
         if (nt == null || nt.length <= index)
272
         {
273
            return;
274
         }
275
         
276
         Node[] nodeArr;
277
         
278
         if (lookup != null)
279
         {
280
            nodeArr = (Node[]) lookup.lookupAll(Node.class).toArray(new Node[0]);
281
         }
282
         else
283
         {
284
            nodeArr = WindowManager.getDefault().getRegistry().getCurrentNodes();
285
         }
286
         performAction(nodeArr, index);
287
      }
288
      
289
      /** Adds change listener for changes of the model.
290
       */
291
      public void addChangeListener(ChangeListener l)
292
      {
293
         cs.addChangeListener(l);
294
      }
295
      
296
      /** Removes change listener for changes of the model.
297
       */
298
      public void removeChangeListener(ChangeListener l)
299
      {
300
         cs.removeChangeListener(l);
301
      }
302
   }
303
   // end of ActSubMenuModel
304
   
305
   /** A delegate action that is usually associated with a specific lookup and
306
    * extract the nodes it operates on from it. Otherwise it delegates to the
307
    * regular NodeAction.
308
    */
309
   private static final class DelegateAction extends javax.swing.AbstractAction
310
         implements Presenter.Popup
311
   {
312
      /** Action to delegate to. */
313
      private final NodeAction delegate;
314
      
315
      /** Associated model to use. */
316
      private final ActSubMenuModel model;
317
      
318
      public DelegateAction(NodeAction a, Lookup actionContext)
319
      {
320
         this.delegate = a;
321
         this.model = new ActSubMenuModel(actionContext);
322
         this.putValue(NAME, createName(model.newTypes()));
323
      }
324
      
325
      /** Overrides superclass method, adds delegate description. */
326
      public String toString()
327
      {
328
         return super.toString() + "[delegate=" + delegate + "]"; // NOI18N
329
      }
330
      
331
      /** Invoked when an action occurs.
332
       */
333
      public void actionPerformed(java.awt.event.ActionEvent e)
334
      {
335
         model.performActionAt(0);
336
      }
337
      
338
      public void addPropertyChangeListener(PropertyChangeListener listener)
339
      {
340
      }
341
      
342
      public void removePropertyChangeListener(PropertyChangeListener listener)
343
      {
344
      }
345
      
346
      public Object getValue(String key)
347
      {
348
         if (javax.swing.Action.NAME.equals(key))
349
         {
350
            return createName(model.newTypes());
351
         }
352
         else
353
         {
354
            return delegate.getValue(key);
355
         }
356
      }
357
      
358
      public boolean isEnabled()
359
      {
360
         return model.getCount() > 0;
361
      }
362
      
363
      public JMenuItem getPopupPresenter()
364
      {
365
         Actions.SubMenu popupPresenter  = new CustomedMenuItem(this, model, true);
366
         return popupPresenter;
367
      }
368
   }
369
   // end of DelegateAction
370
   
371
   private static class CustomedMenuItem extends Actions.SubMenu
372
   {
373
      private Actions.SubMenuModel model;
374
      private List<JMenuItem> menuList = new ArrayList<JMenuItem>();
375
      private JMenu aMenu;
376
      Action action;
377
      
378
      public CustomedMenuItem(Action aAction, Actions.SubMenuModel model, boolean popup)
379
      {
380
         super(aAction, model, popup);
381
         this.model = model;
382
         this.action = aAction;
383
      }
384
      
385
      public JComponent[] getMenuPresenters()
386
      {
387
         return synchMenuPresenters(null);
388
      }
389
      
390
      public JComponent[] synchMenuPresenters(JComponent[] items)
391
      {
392
         menuList.clear();
393
         if (model != null)
394
         {
395
            int count = model.getCount();
396
            if (count > 0 )
397
            {
398
               JMenuItem item = null;
399
               aMenu = new JMenu();
400
               Mnemonics.setLocalizedText(aMenu, (String)action.getValue(Action.NAME));
401
               
402
               // create sub menu items
403
               for (int i = 0; i < count; i++)
404
               {
405
                  String label = model.getLabel(i);
406
                  String iconRes = ((ActSubMenuModel)model).getIconResource(i);
407
                  if (label != null)
408
                  {
409
                     item = new JMenuItem();
410
                     Mnemonics.setLocalizedText(item, label);
411
                     if (iconRes != null)
412
                     {
413
                        ImageIcon icon = ImageUtilities.loadImageIcon(iconRes, false);
414
                        item.setIcon(icon);
415
                     }
416
                     item.addActionListener(new SubActionListener(i, model));
417
                     aMenu.add(item);
418
                  }
419
               }
420
               aMenu.setEnabled(true);
421
               menuList.add(aMenu);
422
            }
201
            }
423
         }
202
        }
424
         return menuList.toArray(new JMenuItem[menuList.size()]);
203
425
      }
204
        public String getIconResource(int index) {
426
      
205
            String iconRes = null;
427
      private static class SubActionListener implements java.awt.event.ActionListener
206
            NewType[] newTypes = newTypes();
428
      {
207
            if (newTypes != null && newTypes.length > index) {
429
         int index;
208
                NewType type = newTypes[index];
430
         Actions.SubMenuModel model;
209
                iconRes = (type instanceof INewTypeExt ? ((INewTypeExt) type).getIconResource() : null);
431
         
210
            }
432
         public SubActionListener(int index, Actions.SubMenuModel support)
211
            return iconRes;
433
         {
212
        }
434
            this.index = index;
213
435
            this.model = support;
214
        public HelpCtx getHelpCtx(int index) {
436
         }
215
            NewType[] newTypes = newTypes();
437
         
216
438
         public void actionPerformed(ActionEvent e)
217
            if (newTypes == null || newTypes.length <= index) {
439
         {
218
                return null;
440
            model.performActionAt(index);
219
            } else {
441
         }
220
                return newTypes[index].getHelpCtx();
442
      }
221
            }
443
   }
222
        }
223
224
        public void performActionAt(int index) {
225
            NewType[] nt = newTypes();
226
227
            if (nt == null || nt.length <= index) {
228
                return;
229
            }
230
231
            Node[] nodeArr;
232
233
            if (lookup != null) {
234
                nodeArr = (Node[]) lookup.lookupAll(Node.class).toArray(new Node[0]);
235
            } else {
236
                nodeArr = WindowManager.getDefault().getRegistry().getCurrentNodes();
237
            }
238
            performAction(nodeArr, index);
239
        }
240
241
        /** Adds change listener for changes of the model.
242
         */
243
        public void addChangeListener(ChangeListener l) {
244
            cs.addChangeListener(l);
245
        }
246
247
        /** Removes change listener for changes of the model.
248
         */
249
        public void removeChangeListener(ChangeListener l) {
250
            cs.removeChangeListener(l);
251
        }
252
    }
253
    // end of ActSubMenuModel
254
255
    /** A delegate action that is usually associated with a specific lookup and
256
     * extract the nodes it operates on from it. Otherwise it delegates to the
257
     * regular NodeAction.
258
     */
259
    private static final class DelegateAction extends javax.swing.AbstractAction
260
            implements Presenter.Popup {
261
262
        /** Action to delegate to. */
263
        private final NodeAction delegate;
264
        /** Associated model to use. */
265
        private final ActSubMenuModel model;
266
267
        public DelegateAction(NodeAction a, Lookup actionContext) {
268
            this.delegate = a;
269
            this.model = new ActSubMenuModel(actionContext);
270
            this.putValue(NAME, createName(model.newTypes()));
271
        }
272
273
        /** Overrides superclass method, adds delegate description. */
274
        public String toString() {
275
            return super.toString() + "[delegate=" + delegate + "]"; // NOI18N
276
        }
277
278
        /** Invoked when an action occurs.
279
         */
280
        public void actionPerformed(java.awt.event.ActionEvent e) {
281
            model.performActionAt(0);
282
        }
283
284
        public void addPropertyChangeListener(PropertyChangeListener listener) {
285
        }
286
287
        public void removePropertyChangeListener(PropertyChangeListener listener) {
288
        }
289
290
        public Object getValue(String key) {
291
            if (javax.swing.Action.NAME.equals(key)) {
292
                return createName(model.newTypes());
293
            } else {
294
                return delegate.getValue(key);
295
            }
296
        }
297
298
        public boolean isEnabled() {
299
            return model.getCount() > 0;
300
        }
301
302
        public JMenuItem getPopupPresenter() {
303
            Actions.SubMenu popupPresenter = new CustomedMenuItem(this, model, true);
304
            return popupPresenter;
305
        }
306
    }
307
    // end of DelegateAction
308
309
    private static class CustomedMenuItem extends Actions.SubMenu {
310
311
        private Actions.SubMenuModel model;
312
        private List<JMenuItem> menuList = new ArrayList<JMenuItem>();
313
        private JMenu aMenu;
314
        Action action;
315
316
        public CustomedMenuItem(Action aAction, Actions.SubMenuModel model, boolean popup) {
317
            super(aAction, model, popup);
318
            this.model = model;
319
            this.action = aAction;
320
        }
321
322
        public JComponent[] getMenuPresenters() {
323
            return synchMenuPresenters(null);
324
        }
325
326
        public JComponent[] synchMenuPresenters(JComponent[] items) {
327
            menuList.clear();
328
            if (model != null) {
329
                int count = model.getCount();
330
                if (count > 0) {
331
                    JMenuItem item = null;
332
                    aMenu = new JMenu();
333
                    Mnemonics.setLocalizedText(aMenu, (String) action.getValue(Action.NAME));
334
335
                    // create sub menu items
336
                    for (int i = 0; i < count; i++) {
337
                        String label = model.getLabel(i);
338
                        String iconRes = ((ActSubMenuModel) model).getIconResource(i);
339
                        if (label != null) {
340
                            item = new JMenuItem();
341
                            Mnemonics.setLocalizedText(item, label);
342
                            if (iconRes != null) {
343
                                ImageIcon icon = ImageUtilities.loadImageIcon(iconRes, false);
344
                                item.setIcon(icon);
345
                            }
346
                            item.addActionListener(new SubActionListener(i, model));
347
                            aMenu.add(item);
348
                        }
349
                    }
350
                    aMenu.setEnabled(true);
351
                    menuList.add(aMenu);
352
                }
353
            }
354
            return menuList.toArray(new JMenuItem[menuList.size()]);
355
        }
356
357
        private static class SubActionListener implements java.awt.event.ActionListener {
358
359
            int index;
360
            Actions.SubMenuModel model;
361
362
            public SubActionListener(int index, Actions.SubMenuModel support) {
363
                this.index = index;
364
                this.model = support;
365
            }
366
367
            public void actionPerformed(ActionEvent e) {
368
                model.performActionAt(index);
369
            }
370
        }
371
    }
444
}
372
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/palette/PaletteComponent.java (-6 / +1 lines)
Lines 41-56 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.palette;
44
package org.netbeans.modules.uml.project.ui.palette;
46
45
47
import javax.swing.JButton;
48
import javax.swing.JPanel;
46
import javax.swing.JPanel;
49
47
50
import org.netbeans.modules.uml.resources.images.ImageUtil;
48
public class PaletteComponent extends JPanel {
51
52
public class PaletteComponent extends JPanel
53
{
54
    // TODO: meteora
49
    // TODO: meteora
55
//   private IDrawingAreaControl m_Control = null;
50
//   private IDrawingAreaControl m_Control = null;
56
//
51
//
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/palette/UMLPalette.java (-74 / +58 lines)
Lines 41-130 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.palette;
44
package org.netbeans.modules.uml.project.ui.palette;
46
45
47
import java.awt.BorderLayout;
46
import java.awt.BorderLayout;
48
import java.awt.Dimension;
47
import java.awt.Dimension;
49
48
50
import javax.swing.JLabel;
51
52
import org.openide.util.Lookup;
49
import org.openide.util.Lookup;
53
import org.openide.windows.TopComponent;
50
import org.openide.windows.TopComponent;
54
import org.openide.windows.WindowManager;
51
import org.openide.windows.WindowManager;
55
52
56
public class UMLPalette extends TopComponent
53
public class UMLPalette extends TopComponent {
57
{
58
   private static UMLPalette m_TopComponent = null;
59
   private PaletteComponent m_Control = null;
60
54
61
   public UMLPalette()
55
    private static UMLPalette m_TopComponent = null;
62
   {
56
    private PaletteComponent m_Control = null;
63
      super();
64
      initComponents();
65
   }
66
57
67
   public UMLPalette(Lookup lookup)
58
    public UMLPalette() {
68
   {
59
        super();
69
      super(lookup);
60
        initComponents();
70
      initComponents();
61
    }
71
   }
72
   
73
   public void initComponents()
74
   {
75
      setName("UMLPalette");
76
      setDisplayName("UMLPalette");
77
      
78
      setLayout(new BorderLayout());
79
      
80
      m_Control = new PaletteComponent();
81
      
82
      add(m_Control, BorderLayout.CENTER);
83
      
84
      setPreferredSize(new Dimension(200,70));
85
   }
86
   
87
   public static synchronized UMLPalette getDefault()
88
   {
89
      if (m_TopComponent == null)
90
      {
91
         m_TopComponent = new UMLPalette();
92
      }
93
      return m_TopComponent;
94
   }
95
   
96
   public static synchronized UMLPalette getInstance()
97
   {
98
      if(m_TopComponent == null)
99
      {
100
         TopComponent tc = WindowManager.getDefault().findTopComponent("UMLPalette");
101
         if (tc != null)
102
         {
103
            m_TopComponent = (UMLPalette)tc;
104
         }
105
         else
106
         {
107
            m_TopComponent = new UMLPalette();      
108
         }
109
      }
110
      
111
      return m_TopComponent;
112
   }
113
   
114
   /** Overriden to explicitely set persistence type of UmlPalette
115
    * to PERSISTENCE_ALWAYS */
116
   public int getPersistenceType() {
117
       return TopComponent.PERSISTENCE_ALWAYS;
118
   }
119
   
120
   public void addNotify()
121
   {
122
      super.addNotify();
123
   }
124
   
125
   public void removeNotify()
126
   {
127
      super.removeNotify();
128
   }
129
62
63
    public UMLPalette(Lookup lookup) {
64
        super(lookup);
65
        initComponents();
66
    }
67
68
    public void initComponents() {
69
        setName("UMLPalette");
70
        setDisplayName("UMLPalette");
71
72
        setLayout(new BorderLayout());
73
74
        m_Control = new PaletteComponent();
75
76
        add(m_Control, BorderLayout.CENTER);
77
78
        setPreferredSize(new Dimension(200, 70));
79
    }
80
81
    public static synchronized UMLPalette getDefault() {
82
        if (m_TopComponent == null) {
83
            m_TopComponent = new UMLPalette();
84
        }
85
        return m_TopComponent;
86
    }
87
88
    public static synchronized UMLPalette getInstance() {
89
        if (m_TopComponent == null) {
90
            TopComponent tc = WindowManager.getDefault().findTopComponent("UMLPalette");
91
            if (tc != null) {
92
                m_TopComponent = (UMLPalette) tc;
93
            } else {
94
                m_TopComponent = new UMLPalette();
95
            }
96
        }
97
98
        return m_TopComponent;
99
    }
100
101
    /** Overriden to explicitely set persistence type of UmlPalette
102
     * to PERSISTENCE_ALWAYS */
103
    public int getPersistenceType() {
104
        return TopComponent.PERSISTENCE_ALWAYS;
105
    }
106
107
    public void addNotify() {
108
        super.addNotify();
109
    }
110
111
    public void removeNotify() {
112
        super.removeNotify();
113
    }
130
}
114
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/wizards/NewUMLProjectWizardIterator.java (-213 / +159 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.wizards;
44
package org.netbeans.modules.uml.project.ui.wizards;
46
45
47
import java.awt.Component;
46
import java.awt.Component;
Lines 69-88 Link Here
69
import org.netbeans.modules.uml.project.ui.UMLProjectSettings;
68
import org.netbeans.modules.uml.project.ui.UMLProjectSettings;
70
import org.netbeans.modules.uml.project.ui.common.JavaSourceRootsUI;
69
import org.netbeans.modules.uml.project.ui.common.JavaSourceRootsUI;
71
70
72
73
/**
71
/**
74
 * Wizard to create a new UML project.
72
 * Wizard to create a new UML project.
75
 */
73
 */
76
public class NewUMLProjectWizardIterator 
74
public class NewUMLProjectWizardIterator
77
    implements WizardDescriptor.InstantiatingIterator 
75
        implements WizardDescriptor.InstantiatingIterator {
78
{
76
79
    private static final long serialVersionUID = 1L;
77
    private static final long serialVersionUID = 1L;
80
    
81
    public static final int TYPE_UML = 0;  // platform independent
78
    public static final int TYPE_UML = 0;  // platform independent
82
    public static final int TYPE_UML_JAVA = 1; // Java platform
79
    public static final int TYPE_UML_JAVA = 1; // Java platform
83
    public static final int TYPE_REVERSE_ENGINEER = 2; // reverse engineer Java project
80
    public static final int TYPE_REVERSE_ENGINEER = 2; // reverse engineer Java project
84
//    public static final int TYPE_ROSE_IMPORT = 3; // import Rose model
81
//    public static final int TYPE_ROSE_IMPORT = 3; // import Rose model
85
    
86
    public static final String PROP_WIZARD_TYPE = "uml-wizard-type"; //NOI18N
82
    public static final String PROP_WIZARD_TYPE = "uml-wizard-type"; //NOI18N
87
    public static final String PROP_NAME_INDEX = "nameIndex"; //NOI18N
83
    public static final String PROP_NAME_INDEX = "nameIndex"; //NOI18N
88
    public static final String PROP_PROJECT_NAME = "name"; //NOI18N
84
    public static final String PROP_PROJECT_NAME = "name"; //NOI18N
Lines 91-101 Link Here
91
    public static final String PROP_WIZARD_ERROR_MESSAGE = WizardDescriptor.PROP_ERROR_MESSAGE; //NOI18N
87
    public static final String PROP_WIZARD_ERROR_MESSAGE = WizardDescriptor.PROP_ERROR_MESSAGE; //NOI18N
92
    public static final String PROP_SET_AS_MAIN = "setAsMain"; //NOI18N
88
    public static final String PROP_SET_AS_MAIN = "setAsMain"; //NOI18N
93
    public static final String PROP_JAVA_SOURCE_PROJECT = "javaSrcProject"; //NOI18N
89
    public static final String PROP_JAVA_SOURCE_PROJECT = "javaSrcProject"; //NOI18N
94
    public static final String PROP_JAVA_SOURCE_ROOTS_MODEL= "javaSourceRootsModel"; //NOI18N
90
    public static final String PROP_JAVA_SOURCE_ROOTS_MODEL = "javaSourceRootsModel"; //NOI18N
95
//    public static final String PROP_ROSE_FILE= "roseFile"; //NOI18N
91
//    public static final String PROP_ROSE_FILE= "roseFile"; //NOI18N
96
    public static final String PROP_MODELING_MODE = "modelingMode"; //NOI18N
92
    public static final String PROP_MODELING_MODE = "modelingMode"; //NOI18N
97
    public static final String PROP_PROJECT_MODEL_TYPE = "projectModelType"; // NOI18N
93
    public static final String PROP_PROJECT_MODEL_TYPE = "projectModelType"; // NOI18N
98
99
    private int type;
94
    private int type;
100
    private File projectDir;
95
    private File projectDir;
101
    private transient int index;
96
    private transient int index;
Lines 103-265 Link Here
103
    private transient WizardDescriptor wiz;
98
    private transient WizardDescriptor wiz;
104
    private boolean hideJavaProjectPanel = true;
99
    private boolean hideJavaProjectPanel = true;
105
100
106
    public NewUMLProjectWizardIterator() 
101
    public NewUMLProjectWizardIterator() {
107
    {
108
        this(TYPE_UML);
102
        this(TYPE_UML);
109
    }
103
    }
110
    
104
111
    public NewUMLProjectWizardIterator(int type) 
105
    public NewUMLProjectWizardIterator(int type) {
112
    {
113
        this.type = type;
106
        this.type = type;
114
    }
107
    }
115
    
108
116
    public static NewUMLProjectWizardIterator umlJava() 
109
    public static NewUMLProjectWizardIterator umlJava() {
117
    {
118
        return new NewUMLProjectWizardIterator(TYPE_UML_JAVA);
110
        return new NewUMLProjectWizardIterator(TYPE_UML_JAVA);
119
    }
111
    }
120
    
112
121
    public static NewUMLProjectWizardIterator reverseEngineer() 
113
    public static NewUMLProjectWizardIterator reverseEngineer() {
122
    {
123
        return new NewUMLProjectWizardIterator(TYPE_REVERSE_ENGINEER);
114
        return new NewUMLProjectWizardIterator(TYPE_REVERSE_ENGINEER);
124
    }
115
    }
125
    
116
126
//    public static NewUMLProjectWizardIterator roseImport() 
117
//    public static NewUMLProjectWizardIterator roseImport() 
127
//    {
118
//    {
128
//        return new NewUMLProjectWizardIterator( TYPE_ROSE_IMPORT );
119
//        return new NewUMLProjectWizardIterator( TYPE_ROSE_IMPORT );
129
//    }
120
//    }
130
    
121
    private WizardDescriptor.Panel[] createPanels() {
131
    private WizardDescriptor.Panel[] createPanels () 
132
    {
133
        // UML Analysis project
122
        // UML Analysis project
134
        if (this.type == TYPE_UML) 
123
        if (this.type == TYPE_UML) {
135
        {
124
            return new WizardDescriptor.Panel[]{
136
            return new WizardDescriptor.Panel[] 
125
                        new PanelConfigureProject(this.type)
137
            {
126
                    };
138
                new PanelConfigureProject(this.type)
127
        } // UML Java Project
139
            };       
128
        else if (this.type == TYPE_UML_JAVA) {
140
        }
129
            return new WizardDescriptor.Panel[]{
141
        
130
                        new PanelConfigureProject(this.type)
142
        // UML Java Project
131
                    // new PanelAssociateJavaProject(this.type)            
143
        else if (this.type == TYPE_UML_JAVA) 
132
                    };
144
        {
133
        } else {
145
            return new WizardDescriptor.Panel[] 
134
            return new WizardDescriptor.Panel[]{
146
            {
135
                        new PanelConfigureProject(this.type)
147
                new PanelConfigureProject(this.type)
136
                    };
148
                // new PanelAssociateJavaProject(this.type)            
149
            };       
150
        }
151
        
152
        else 
153
        {
154
            return new WizardDescriptor.Panel[] 
155
            {
156
                new PanelConfigureProject(this.type)
157
            };
158
        }         
159
    }
160
    
161
    private String[] createSteps()
162
    {
163
        // UML Analysis project
164
        if (this.type == TYPE_UML)
165
        {
166
            return new String[]
167
            {
168
                NbBundle.getMessage(NewUMLProjectWizardIterator.class,
169
                    "LAB_ConfigureProject")  //NOI18N
170
            };
171
        }
172
        
173
        //UML Java Project
174
        else if(this.type == TYPE_UML_JAVA)
175
        {
176
            return new String[] 
177
            {
178
                NbBundle.getMessage(NewUMLProjectWizardIterator.class,
179
                    "LAB_ConfigureProject")  //NOI18N
180
//                NbBundle.getMessage(NewUMLProjectWizardIterator.class,
181
//                    "LAB_AssociateJavaProject")  //NOI18N
182
            };
183
        }
184
185
        else
186
        {
187
            return new String[] 
188
            {
189
                NbBundle.getMessage(NewUMLProjectWizardIterator.class,
190
                    "LAB_ConfigureProject"),  //NOI18N
191
            };
192
        }
137
        }
193
    }
138
    }
194
    
139
195
    
140
    private String[] createSteps() {
196
    public Set/*<FileObject>*/ instantiate() throws IOException 
141
        // UML Analysis project
197
    {
142
        if (this.type == TYPE_UML) {
198
        Set resultSet = new HashSet ();
143
            return new String[]{
199
        
144
                        NbBundle.getMessage(NewUMLProjectWizardIterator.class,
200
        File dirF = (File)wiz.getProperty(
145
                        "LAB_ConfigureProject") //NOI18N
201
                NewUMLProjectWizardIterator.PROP_PROJECT_DIR);   
146
                    };
202
        
147
        } //UML Java Project
203
        if (dirF != null) 
148
        else if (this.type == TYPE_UML_JAVA) {
204
        {
149
            return new String[]{
150
                        NbBundle.getMessage(NewUMLProjectWizardIterator.class,
151
                        "LAB_ConfigureProject") //NOI18N
152
                    //                NbBundle.getMessage(NewUMLProjectWizardIterator.class,
153
                    //                    "LAB_AssociateJavaProject")  //NOI18N
154
                    };
155
        } else {
156
            return new String[]{
157
                        NbBundle.getMessage(NewUMLProjectWizardIterator.class,
158
                        "LAB_ConfigureProject"), //NOI18N
159
                    };
160
        }
161
    }
162
163
    public Set/*<FileObject>*/ instantiate() throws IOException {
164
        Set resultSet = new HashSet();
165
166
        File dirF = (File) wiz.getProperty(
167
                NewUMLProjectWizardIterator.PROP_PROJECT_DIR);
168
169
        if (dirF != null) {
205
            dirF = FileUtil.normalizeFile(dirF);
170
            dirF = FileUtil.normalizeFile(dirF);
206
            projectDir = dirF;
171
            projectDir = dirF;
207
        }
172
        }
208
        
173
209
        String name = (String)wiz.getProperty(
174
        String name = (String) wiz.getProperty(
210
            NewUMLProjectWizardIterator.PROP_PROJECT_NAME);     
175
                NewUMLProjectWizardIterator.PROP_PROJECT_NAME);
211
176
212
        AntProjectHelper helper = null;
177
        AntProjectHelper helper = null;
213
        
178
214
        // MCF - we need slightly different handling for the basic UML project
179
        // MCF - we need slightly different handling for the basic UML project
215
        // depending on the mode      
180
        // depending on the mode      
216
        if (this.type == TYPE_UML || this.type == TYPE_UML_JAVA) 
181
        if (this.type == TYPE_UML || this.type == TYPE_UML_JAVA) {
217
        {
182
            String modelingMode = null;
218
           String modelingMode = null ; 
219
//                (String)wiz.getProperty(NewUMLProjectWizardIterator.PROP_MODELING_MODE);
183
//                (String)wiz.getProperty(NewUMLProjectWizardIterator.PROP_MODELING_MODE);
220
            
184
221
            if (this.type == TYPE_UML_JAVA)
185
            if (this.type == TYPE_UML_JAVA) {
222
               modelingMode = UMLProject.PROJECT_MODE_IMPL_STR ;
186
                modelingMode = UMLProject.PROJECT_MODE_IMPL_STR;
223
            else if (this.type == TYPE_UML)
187
            } else if (this.type == TYPE_UML) {
224
               modelingMode = UMLProject.PROJECT_MODE_DESIGN_STR ;
188
                modelingMode = UMLProject.PROJECT_MODE_DESIGN_STR;
225
            else
189
            } else {
226
                modelingMode = UMLProject.PROJECT_MODE_ANALYSIS_STR ;
190
                modelingMode = UMLProject.PROJECT_MODE_ANALYSIS_STR;
227
            
191
            }
192
228
            // If the user chose the Mode Impl path, then we actually treat this
193
            // If the user chose the Mode Impl path, then we actually treat this
229
            // like a reverse enginneering case.
194
            // like a reverse enginneering case.
230
            if (modelingMode.equalsIgnoreCase(UMLProject.PROJECT_MODE_IMPL_STR)) 
195
            if (modelingMode.equalsIgnoreCase(UMLProject.PROJECT_MODE_IMPL_STR)) {
231
            {
196
                Project srcProj = (Project) wiz.getProperty(
232
                Project srcProj = (Project)wiz.getProperty(
197
                        NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_PROJECT);
198
199
                JavaSourceRootsUI.JavaSourceRootsModel rootsModel =
200
                        (JavaSourceRootsUI.JavaSourceRootsModel) wiz.getProperty(
201
                        NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_ROOTS_MODEL);
202
203
                helper = UMLProjectGenerator.createRevEngProject(
204
                        dirF, name, srcProj, rootsModel, null, type);
205
            } else {
206
                helper = UMLProjectGenerator.createEmptyProject(
207
                        dirF, name, modelingMode, null, new String[0], type);
208
            }
209
        } else if (this.type == TYPE_REVERSE_ENGINEER) {
210
            Project srcProj = (Project) wiz.getProperty(
233
                    NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_PROJECT);
211
                    NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_PROJECT);
234
            
235
                JavaSourceRootsUI.JavaSourceRootsModel rootsModel =
236
                    (JavaSourceRootsUI.JavaSourceRootsModel)
237
                
238
                wiz.getProperty(
239
                    NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_ROOTS_MODEL);   
240
                
241
                helper = UMLProjectGenerator.createRevEngProject(
242
                    dirF, name, srcProj, rootsModel, null, type);               
243
            }
244
            
245
            else 
246
            {
247
                helper = UMLProjectGenerator.createEmptyProject(
248
                    dirF, name, modelingMode, null, new String[0], type);                  
249
            }
250
        }
251
212
252
        else if (this.type == TYPE_REVERSE_ENGINEER) 
253
        {
254
            Project srcProj = (Project)wiz.getProperty(
255
                NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_PROJECT);
256
            
257
            JavaSourceRootsUI.JavaSourceRootsModel rootsModel =
213
            JavaSourceRootsUI.JavaSourceRootsModel rootsModel =
258
                (JavaSourceRootsUI.JavaSourceRootsModel)wiz.getProperty(
214
                    (JavaSourceRootsUI.JavaSourceRootsModel) wiz.getProperty(
259
                NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_ROOTS_MODEL);
215
                    NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_ROOTS_MODEL);
260
            
216
261
            helper = UMLProjectGenerator.createRevEngProject(
217
            helper = UMLProjectGenerator.createRevEngProject(
262
                dirF, name, srcProj, rootsModel, null, type);
218
                    dirF, name, srcProj, rootsModel, null, type);
263
        }
219
        }
264
220
265
//        else if (this.type == TYPE_ROSE_IMPORT)    
221
//        else if (this.type == TYPE_ROSE_IMPORT)    
Lines 278-404 Link Here
278
234
279
        // Returning FileObject of project diretory. 
235
        // Returning FileObject of project diretory. 
280
        // Project will be open and set as main
236
        // Project will be open and set as main
281
        Integer index = (Integer)wiz.getProperty(PROP_NAME_INDEX);
237
        Integer index = (Integer) wiz.getProperty(PROP_NAME_INDEX);
282
        
238
283
        // MCF 
239
        // MCF 
284
	// This project count stuff is intended to help automatically increment
240
        // This project count stuff is intended to help automatically increment
285
	// the default project name that appears in wizard.
241
        // the default project name that appears in wizard.
286
        UMLProjectSettings.getDefault().setNewProjectCount(index.intValue());
242
        UMLProjectSettings.getDefault().setNewProjectCount(index.intValue());
287
             
243
288
        resultSet.add (dir);
244
        resultSet.add(dir);
289
        dirF = (dirF != null) ? dirF.getParentFile() : null;
245
        dirF = (dirF != null) ? dirF.getParentFile() : null;
290
        
246
291
        if (dirF != null && dirF.exists()) 
247
        if (dirF != null && dirF.exists()) {
292
            ProjectChooser.setProjectsFolder (dirF);    
248
            ProjectChooser.setProjectsFolder(dirF);
293
                        
249
        }
250
294
        return resultSet;
251
        return resultSet;
295
    }
252
    }
296
    
253
297
    public void initialize(WizardDescriptor wiz) 
254
    public void initialize(WizardDescriptor wiz) {
298
    {
299
        this.wiz = wiz;
255
        this.wiz = wiz;
300
        index = 0;
256
        index = 0;
301
        panels = createPanels();
257
        panels = createPanels();
302
        
258
303
        // Make sure list of steps is accurate.
259
        // Make sure list of steps is accurate.
304
        String[] steps = createSteps();
260
        String[] steps = createSteps();
305
        
261
306
        for (int i = 0; i < panels.length; i++) 
262
        for (int i = 0; i < panels.length; i++) {
307
        {
308
            Component c = panels[i].getComponent();
263
            Component c = panels[i].getComponent();
309
        
264
310
            if (steps[i] == null) 
265
            if (steps[i] == null) {
311
            {
312
                // Default step name to component name of panel.
266
                // Default step name to component name of panel.
313
                // Mainly useful for getting the name of the target
267
                // Mainly useful for getting the name of the target
314
                // chooser to appear in the list of steps.
268
                // chooser to appear in the list of steps.
315
                steps[i] = c.getName();
269
                steps[i] = c.getName();
316
            }
270
            }
317
            
271
318
            if (c instanceof JComponent) 
272
            if (c instanceof JComponent) {
319
            { 
320
                // assume Swing components
273
                // assume Swing components
321
                JComponent jc = (JComponent)c;
274
                JComponent jc = (JComponent) c;
322
                // Step #.
275
                // Step #.
323
                jc.putClientProperty(
276
                jc.putClientProperty(
324
                    WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, new Integer(i)); // NOI18N
277
                        WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, new Integer(i)); // NOI18N
325
                
278
326
                // Step name (actually the whole list for reference).
279
                // Step name (actually the whole list for reference).
327
                jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); // NOI18N
280
                jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); // NOI18N
328
            }
281
            }
329
        }
282
        }
330
    }
283
    }
331
284
332
    public void uninitialize(WizardDescriptor wiz) 
285
    public void uninitialize(WizardDescriptor wiz) {
333
    {
334
        // why bother with this if we set wiz to null?
286
        // why bother with this if we set wiz to null?
335
        this.wiz.putProperty(PROP_PROJECT_DIR,null);
287
        this.wiz.putProperty(PROP_PROJECT_DIR, null);
336
        this.wiz.putProperty(PROP_PROJECT_NAME,null);
288
        this.wiz.putProperty(PROP_PROJECT_NAME, null);
337
        this.wiz = null;
289
        this.wiz = null;
338
        panels = null;
290
        panels = null;
339
    }
291
    }
340
    
292
341
    public File getProjectDir()
293
    public File getProjectDir() {
342
    {
343
        return projectDir;
294
        return projectDir;
344
    }
295
    }
345
    
296
346
	
297
    public String name() {
347
    public String name() 
348
    {
349
        return MessageFormat.format(NbBundle.getMessage(
298
        return MessageFormat.format(NbBundle.getMessage(
350
            NewUMLProjectWizardIterator.class,"LAB_IteratorName"), // NO18N
299
                NewUMLProjectWizardIterator.class, "LAB_IteratorName"), // NO18N
351
            new Object[] {new Integer(index + 1), new Integer(panels.length)});
300
                new Object[]{new Integer(index + 1), new Integer(panels.length)});
352
    }
353
    
354
    public boolean hasNext() 
355
    {
356
        PanelConfigureProject configPanel = (PanelConfigureProject)panels[0];
357
        
358
        if( this.type == TYPE_UML_JAVA && 
359
            (!configPanel.isImplementationModeSelected())) 
360
        {
361
            return index < panels.length - 2;
362
        }
363
        
364
        else 
365
            return index < panels.length - 1;       
366
    }
301
    }
367
302
368
    private boolean hideJavaProjectPanel()
303
    public boolean hasNext() {
369
    {
304
        PanelConfigureProject configPanel = (PanelConfigureProject) panels[0];
305
306
        if (this.type == TYPE_UML_JAVA
307
                && (!configPanel.isImplementationModeSelected())) {
308
            return index < panels.length - 2;
309
        } else {
310
            return index < panels.length - 1;
311
        }
312
    }
313
314
    private boolean hideJavaProjectPanel() {
370
        return hideJavaProjectPanel;
315
        return hideJavaProjectPanel;
371
    }
316
    }
372
    
317
373
    public void hideJavaProjectPanel(boolean hide)
318
    public void hideJavaProjectPanel(boolean hide) {
374
    {
375
        hideJavaProjectPanel = hide;
319
        hideJavaProjectPanel = hide;
376
    }
320
    }
377
    
321
378
    public boolean hasPrevious()
322
    public boolean hasPrevious() {
379
    {
380
        return index > 0;
323
        return index > 0;
381
    }
324
    }
382
    
325
383
    public void nextPanel()
326
    public void nextPanel() {
384
    {
327
        if (!hasNext()) {
385
        if (!hasNext()) throw new NoSuchElementException();
328
            throw new NoSuchElementException();
329
        }
386
        index++;
330
        index++;
387
    }
331
    }
388
    
332
389
    public void previousPanel()
333
    public void previousPanel() {
390
    {
334
        if (!hasPrevious()) {
391
        if (!hasPrevious()) throw new NoSuchElementException();
335
            throw new NoSuchElementException();
336
        }
392
        index--;
337
        index--;
393
    }
338
    }
394
    
339
395
    public WizardDescriptor.Panel current()
340
    public WizardDescriptor.Panel current() {
396
    {
397
        return panels[index];
341
        return panels[index];
398
    }
342
    }
399
    
343
400
    // If nothing unusual changes in the middle of the wizard, simply:
344
    // If nothing unusual changes in the middle of the wizard, simply:
401
    public final void addChangeListener(ChangeListener l){}
345
    public final void addChangeListener(ChangeListener l) {
402
    public final void removeChangeListener(ChangeListener l){}
346
    }
403
    
347
348
    public final void removeChangeListener(ChangeListener l) {
349
    }
404
}
350
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/wizards/PanelConfigureProject.java (-103 / +68 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.wizards;
44
package org.netbeans.modules.uml.project.ui.wizards;
46
45
47
import java.awt.Component;
46
import java.awt.Component;
Lines 65-170 Link Here
65
 * Panel just asking for basic info.
64
 * Panel just asking for basic info.
66
 * @author Mike Frisino
65
 * @author Mike Frisino
67
 */
66
 */
68
public final class PanelConfigureProject 
67
public final class PanelConfigureProject
69
    implements WizardDescriptor.Panel, WizardDescriptor.ValidatingPanel, 
68
        implements WizardDescriptor.Panel, WizardDescriptor.ValidatingPanel,
70
        WizardDescriptor.FinishablePanel, PropertyChangeListener, ActionListener
69
        WizardDescriptor.FinishablePanel, PropertyChangeListener, ActionListener {
71
{
70
72
    private int type;
71
    private int type;
73
    private WizardDescriptor wizardDescriptor;
72
    private WizardDescriptor wizardDescriptor;
74
    private PanelConfigureProjectVisual component;
73
    private PanelConfigureProjectVisual component;
75
    private final Set/*<ChangeListener>*/ listeners = new HashSet(1);
74
    private final Set/*<ChangeListener>*/ listeners = new HashSet(1);
76
75
77
    /** Create the wizard panel descriptor. */
76
    /** Create the wizard panel descriptor. */
78
    public PanelConfigureProject(int type)
77
    public PanelConfigureProject(int type) {
79
    {
80
        this.type = type;
78
        this.type = type;
81
    }
79
    }
82
    
80
83
    public Component getComponent()
81
    public Component getComponent() {
84
    {
82
        if (component == null) {
85
        if (component == null)
86
            component = new PanelConfigureProjectVisual(this, this.type);
83
            component = new PanelConfigureProjectVisual(this, this.type);
87
        
84
        }
85
88
        return component;
86
        return component;
89
    }
87
    }
90
    
88
91
    public HelpCtx getHelp()
89
    public HelpCtx getHelp() {
92
    {
93
        return new HelpCtx("uml_tasks_projects_creating_project"); // NOI18N
90
        return new HelpCtx("uml_tasks_projects_creating_project"); // NOI18N
94
    }
91
    }
95
    
92
96
    public boolean isValid()
93
    public boolean isValid() {
97
    {
98
        getComponent();
94
        getComponent();
99
        return component.valid(wizardDescriptor);
95
        return component.valid(wizardDescriptor);
100
    }
96
    }
101
    
102
97
103
    
98
    public void readSettings(Object settings) {
104
    public void readSettings(Object settings)
99
        wizardDescriptor = (WizardDescriptor) settings;
105
    {
106
        wizardDescriptor = (WizardDescriptor)settings;
107
        component.read(wizardDescriptor);
100
        component.read(wizardDescriptor);
108
        
101
109
        // XXX hack, TemplateWizard in final setTemplateImpl() forces new wizard's title
102
        // XXX hack, TemplateWizard in final setTemplateImpl() forces new wizard's title
110
        // this name is used in NewProjectWizard to modify the title
103
        // this name is used in NewProjectWizard to modify the title
111
        Object substitute = ((JComponent)component)
104
        Object substitute = ((JComponent) component).getClientProperty("NewProjectWizard_Title"); // NOI18N
112
            .getClientProperty("NewProjectWizard_Title"); // NOI18N
105
113
        
106
        if (substitute != null) {
114
        if (substitute != null)
107
            wizardDescriptor.putProperty("NewProjectWizard_Title", substitute); // NOI18N
115
        {
116
            wizardDescriptor.putProperty
117
                ("NewProjectWizard_Title", substitute); // NOI18N
118
        }
108
        }
119
    }
109
    }
120
    
110
121
    public void storeSettings(Object settings)
111
    public void storeSettings(Object settings) {
122
    {
112
        WizardDescriptor wizDesc = (WizardDescriptor) settings;
123
        WizardDescriptor wizDesc = (WizardDescriptor)settings;
124
        component.store(wizDesc);
113
        component.store(wizDesc);
125
         
114
126
        wizDesc.putProperty(
115
        wizDesc.putProperty(
127
            NewUMLProjectWizardIterator.PROP_WIZARD_TITLE, null);
116
                NewUMLProjectWizardIterator.PROP_WIZARD_TITLE, null);
128
    }
117
    }
129
    
118
130
    public boolean isFinishPanel()
119
    public boolean isFinishPanel() {
131
    {
120
132
        
133
        // MCF - unfortunately, it looks like this is ONLY called when the
121
        // MCF - unfortunately, it looks like this is ONLY called when the
134
        // panel is entered ... not as dynamic as I was hoping.
122
        // panel is entered ... not as dynamic as I was hoping.
135
        if (this.type == NewUMLProjectWizardIterator.TYPE_UML_JAVA)
123
        if (this.type == NewUMLProjectWizardIterator.TYPE_UML_JAVA) {
136
        {
124
            if (isImplementationModeSelected()) {
137
            if (isImplementationModeSelected())
138
            {
139
                // since the implementation mode is selected they must
125
                // since the implementation mode is selected they must
140
                // go to the next panel to complete wizard
126
                // go to the next panel to complete wizard
141
                return false;
127
                return false;
128
            } else {
129
                return true;
142
            }
130
            }
143
            
131
        } else {
144
            else
132
            return true;
145
                return true;
146
        }
133
        }
147
        else
148
            return true;
149
    }
134
    }
150
    
135
151
    public void validate() throws WizardValidationException
136
    public void validate() throws WizardValidationException {
152
    {
153
        getComponent();
137
        getComponent();
154
        component.validate(wizardDescriptor);
138
        component.validate(wizardDescriptor);
155
    }
139
    }
156
    
140
157
    
158
    //// MCF - support for dynamically enabling/disabling the java project
141
    //// MCF - support for dynamically enabling/disabling the java project
159
    // panel based on whether the modeling mode is impl or not.
142
    // panel based on whether the modeling mode is impl or not.
160
    public boolean isImplementationModeSelected()
143
    public boolean isImplementationModeSelected() {
161
    {
144
        return ReferencedJavaProjectPanel.mIsImplementationMode;
162
    	return ReferencedJavaProjectPanel.mIsImplementationMode;
163
    }
145
    }
164
    
146
165
    
147
    public void propertyChange(PropertyChangeEvent evt) {
166
    public void propertyChange(PropertyChangeEvent evt)
167
    {
168
// IZ 84855 - conover - this is no longer valid with live RT disabled
148
// IZ 84855 - conover - this is no longer valid with live RT disabled
169
//        if (PanelCodeGen.MODE_CHANGED_PROP.equals(evt.getPropertyName()))
149
//        if (PanelCodeGen.MODE_CHANGED_PROP.equals(evt.getPropertyName()))
170
//        {
150
//        {
Lines 187-258 Link Here
187
//            this.fireChangeEvent();
167
//            this.fireChangeEvent();
188
//        }
168
//        }
189
169
190
        
170
191
        if (evt.getPropertyName().equals(
171
        if (evt.getPropertyName().equals(
192
                NewUMLProjectWizardIterator.PROP_WIZARD_TYPE))
172
                NewUMLProjectWizardIterator.PROP_WIZARD_TYPE)) {
193
        {
173
            if (((Integer) evt.getNewValue()).intValue()
194
            if (((Integer)evt.getNewValue()).intValue() == 
174
                    == NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER) {
195
                NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER)
196
            {
197
                ReferencedJavaProjectPanel.mIsImplementationMode = true;
175
                ReferencedJavaProjectPanel.mIsImplementationMode = true;
176
            } else {
177
                ReferencedJavaProjectPanel.mIsImplementationMode = false;
198
            }
178
            }
199
            
179
200
            else
180
            fireChangeEvent();
201
                ReferencedJavaProjectPanel.mIsImplementationMode = false;
181
        } else if (evt.getPropertyName().equals(
202
            
182
                ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP)
183
                || evt.getPropertyName().equals(
184
                ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP)) {
203
            fireChangeEvent();
185
            fireChangeEvent();
204
        }
186
        }
205
        
187
206
        else if (evt.getPropertyName().equals(
207
                ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP) ||
208
            evt.getPropertyName().equals(
209
                ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP))
210
        {
211
            fireChangeEvent();
212
        }
213
        
214
//        else if (RoseImportProjectPanel.ROSE_MODEL_PROP.equals(evt.getPropertyName()))
188
//        else if (RoseImportProjectPanel.ROSE_MODEL_PROP.equals(evt.getPropertyName()))
215
//            fireChangeEvent();
189
//            fireChangeEvent();
216
    }
190
    }
217
191
218
    public void actionPerformed(ActionEvent actionEvent)
192
    public void actionPerformed(ActionEvent actionEvent) {
219
    {
220
//        if (actionEvent.getActionCommand().equals("OK"))
193
//        if (actionEvent.getActionCommand().equals("OK"))
221
//        {
194
//        {
222
//            
195
//            
223
//        }
196
//        }
224
    }
197
    }
225
198
226
    public final void addChangeListener(ChangeListener l)
199
    public final void addChangeListener(ChangeListener l) {
227
    {
200
        synchronized (listeners) {
228
        synchronized (listeners)
229
        {
230
            listeners.add(l);
201
            listeners.add(l);
231
        }
202
        }
232
    }
203
    }
233
    
204
234
    public final void removeChangeListener(ChangeListener l)
205
    public final void removeChangeListener(ChangeListener l) {
235
    {
206
        synchronized (listeners) {
236
        synchronized (listeners)
237
        {
238
            listeners.remove(l);
207
            listeners.remove(l);
239
        }
208
        }
240
    }
209
    }
241
    
210
242
    public final void fireChangeEvent()
211
    public final void fireChangeEvent() {
243
    {
244
        Iterator it;
212
        Iterator it;
245
        synchronized (listeners)
213
        synchronized (listeners) {
246
        {
247
            it = new HashSet(listeners).iterator();
214
            it = new HashSet(listeners).iterator();
248
        }
215
        }
249
        
216
250
        ChangeEvent ev = new ChangeEvent(this);
217
        ChangeEvent ev = new ChangeEvent(this);
251
        
218
252
        while (it.hasNext())
219
        while (it.hasNext()) {
253
        {
220
            ((ChangeListener) it.next()).stateChanged(ev);
254
            ((ChangeListener)it.next()).stateChanged(ev);
255
        }
221
        }
256
    }
222
    }
257
    
258
}
223
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/wizards/PanelConfigureProjectVisual.form (-2 / +4 lines)
Lines 1-11 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.1" encoding="UTF-8" ?>
2
2
3
<Form version="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AccessibilityProperties>
4
  <AccessibilityProperties>
5
    <Property name="AccessibleContext.accessibleName" type="java.lang.String" value=""/>
5
    <Property name="AccessibleContext.accessibleName" type="java.lang.String" value=""/>
6
    <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
6
    <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
7
  </AccessibilityProperties>
7
  </AccessibilityProperties>
8
  <AuxValues>
8
  <AuxValues>
9
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
12
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
13
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/wizards/PanelConfigureProjectVisual.java (-80 / +55 lines)
Lines 41-55 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.wizards;
44
package org.netbeans.modules.uml.project.ui.wizards;
46
45
47
import java.io.File;
48
import java.beans.PropertyChangeListener;
49
import javax.swing.JPanel;
46
import javax.swing.JPanel;
50
import javax.swing.event.DocumentEvent;
51
import javax.swing.event.DocumentListener;
52
import javax.swing.text.Document;
53
47
54
import org.openide.WizardDescriptor;
48
import org.openide.WizardDescriptor;
55
import org.openide.WizardValidationException;
49
import org.openide.WizardValidationException;
Lines 60-67 Link Here
60
 *
54
 *
61
 * @author Mike Frisino
55
 * @author Mike Frisino
62
 */
56
 */
63
public class PanelConfigureProjectVisual extends JPanel
57
public class PanelConfigureProjectVisual extends JPanel {
64
{
58
65
    private PanelConfigureProject panel;
59
    private PanelConfigureProject panel;
66
    private boolean ignoreProjectDirChanges;
60
    private boolean ignoreProjectDirChanges;
67
    private boolean ignoreAntProjectNameChanges;
61
    private boolean ignoreAntProjectNameChanges;
Lines 69-142 Link Here
69
    private SettingsPanel projectLocationPanel;
63
    private SettingsPanel projectLocationPanel;
70
    private PanelOptionsVisual optionsPanel;
64
    private PanelOptionsVisual optionsPanel;
71
    private int type;
65
    private int type;
72
    
66
73
    
67
    public PanelConfigureProjectVisual(PanelConfigureProject panel, int type) {
74
    public PanelConfigureProjectVisual(PanelConfigureProject panel, int type)
75
    {
76
        this.panel = panel;
68
        this.panel = panel;
77
        initComponents();
69
        initComponents();
78
        this.type = type;
70
        this.type = type;
79
        
71
80
        setName(NbBundle.getMessage(
72
        setName(NbBundle.getMessage(
81
            PanelConfigureProjectVisual.class, "TXT_NameAndLoc")); // NOI18N
73
                PanelConfigureProjectVisual.class, "TXT_NameAndLoc")); // NOI18N
82
        
74
83
        // Platform-Independent Model
75
        // Platform-Independent Model
84
        if (type == NewUMLProjectWizardIterator.TYPE_UML)
76
        if (type == NewUMLProjectWizardIterator.TYPE_UML) {
85
        {
86
            projectLocationPanel = new ProjectLocationVisualPanel(panel, type);
77
            projectLocationPanel = new ProjectLocationVisualPanel(panel, type);
87
78
88
            putClientProperty("NewProjectWizard_Title",// NOI18N
79
            putClientProperty("NewProjectWizard_Title",// NOI18N
89
                NbBundle.getMessage(PanelConfigureProjectVisual.class,
80
                    NbBundle.getMessage(PanelConfigureProjectVisual.class,
90
                    "TXT_NewUMLProject")); // NOI18N
81
                    "TXT_NewUMLProject")); // NOI18N
91
            
82
92
            jSeparator1.setVisible(true);
83
            jSeparator1.setVisible(true);
93
            
84
94
            getAccessibleContext().setAccessibleName(
85
            getAccessibleContext().setAccessibleName(
95
                NbBundle.getMessage(PanelConfigureProjectVisual.class,
86
                    NbBundle.getMessage(PanelConfigureProjectVisual.class,
96
                    "TXT_NewUMLProject")); // NOI18N
87
                    "TXT_NewUMLProject")); // NOI18N
97
            getAccessibleContext().setAccessibleDescription(
88
            getAccessibleContext().setAccessibleDescription(
98
                NbBundle.getMessage(PanelConfigureProjectVisual.class,
89
                    NbBundle.getMessage(PanelConfigureProjectVisual.class,
99
                    "ACSD_NewUMLProject")); // NOI18N
90
                    "ACSD_NewUMLProject")); // NOI18N
100
        }
91
        } // Java-Platform Model
101
        
92
        else if (type == NewUMLProjectWizardIterator.TYPE_UML_JAVA) {
102
        // Java-Platform Model
103
        else if (type == NewUMLProjectWizardIterator.TYPE_UML_JAVA)
104
        {
105
            projectLocationPanel = new ProjectLocationVisualPanel(panel, type);
93
            projectLocationPanel = new ProjectLocationVisualPanel(panel, type);
106
94
107
            putClientProperty("NewProjectWizard_Title", // NOI18N
95
            putClientProperty("NewProjectWizard_Title", // NOI18N
108
                NbBundle.getMessage(PanelConfigureProjectVisual.class,
96
                    NbBundle.getMessage(PanelConfigureProjectVisual.class,
109
                    "TXT_NewUMLJavaProject")); // NOI18N
97
                    "TXT_NewUMLJavaProject")); // NOI18N
110
            
98
111
            jSeparator1.setVisible(true);
99
            jSeparator1.setVisible(true);
112
            
100
113
            getAccessibleContext().setAccessibleName(
101
            getAccessibleContext().setAccessibleName(
114
                NbBundle.getMessage(PanelConfigureProjectVisual.class,
102
                    NbBundle.getMessage(PanelConfigureProjectVisual.class,
115
                    "TXT_NewUMLJavaProject")); // NOI18N
103
                    "TXT_NewUMLJavaProject")); // NOI18N
116
            getAccessibleContext().setAccessibleDescription(
104
            getAccessibleContext().setAccessibleDescription(
117
                NbBundle.getMessage(PanelConfigureProjectVisual.class,
105
                    NbBundle.getMessage(PanelConfigureProjectVisual.class,
118
                    "ACSD_NewUMLJavaProject")); // NOI18N
106
                    "ACSD_NewUMLJavaProject")); // NOI18N
119
        }
107
        } // Reverse Engineere Java Project Model
120
        
108
        else if (type == NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER) {
121
        // Reverse Engineere Java Project Model
122
        else if (type == NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER)
123
        {
124
            projectLocationPanel = new ProjectLocationVisualPanel(panel, type);
109
            projectLocationPanel = new ProjectLocationVisualPanel(panel, type);
125
            
110
126
            putClientProperty("NewProjectWizard_Title", // NOI18N
111
            putClientProperty("NewProjectWizard_Title", // NOI18N
127
                NbBundle.getMessage(PanelConfigureProjectVisual.class,
112
                    NbBundle.getMessage(PanelConfigureProjectVisual.class,
128
                    "TXT_NewReverseEngineering")); // NOI18N
113
                    "TXT_NewReverseEngineering")); // NOI18N
129
114
130
            jSeparator1.setVisible(true);
115
            jSeparator1.setVisible(true);
131
            
116
132
            getAccessibleContext().setAccessibleName(
117
            getAccessibleContext().setAccessibleName(
133
                NbBundle.getMessage(PanelConfigureProjectVisual.class,
118
                    NbBundle.getMessage(PanelConfigureProjectVisual.class,
134
                    "TXT_NewReverseEngineering")); // NOI18N
119
                    "TXT_NewReverseEngineering")); // NOI18N
135
            getAccessibleContext().setAccessibleDescription(
120
            getAccessibleContext().setAccessibleDescription(
136
                NbBundle.getMessage(PanelConfigureProjectVisual.class,
121
                    NbBundle.getMessage(PanelConfigureProjectVisual.class,
137
                    "ACSD_NewReverseEngineering")); // NOI18N
122
                    "ACSD_NewReverseEngineering")); // NOI18N
138
        }
123
        }
139
        
124
140
//        else if (type == NewUMLProjectWizardIterator.TYPE_ROSE_IMPORT)
125
//        else if (type == NewUMLProjectWizardIterator.TYPE_ROSE_IMPORT)
141
//        {
126
//        {
142
//            projectLocationPanel = new ProjectLocationVisualPanel(panel, type);
127
//            projectLocationPanel = new ProjectLocationVisualPanel(panel, type);
Lines 154-211 Link Here
154
//                NbBundle.getMessage(PanelConfigureProjectVisual.class,
139
//                NbBundle.getMessage(PanelConfigureProjectVisual.class,
155
//                    "ACSD_NewRoseImport")); // NOI18N
140
//                    "ACSD_NewRoseImport")); // NOI18N
156
//        }
141
//        }
157
        
142
158
        locationContainer.add(
143
        locationContainer.add(
159
            projectLocationPanel, java.awt.BorderLayout.CENTER);
144
                projectLocationPanel, java.awt.BorderLayout.CENTER);
160
        
145
161
        optionsPanel = new PanelOptionsVisual(panel, type);
146
        optionsPanel = new PanelOptionsVisual(panel, type);
162
        optionsContainer.add(optionsPanel, java.awt.BorderLayout.CENTER );
147
        optionsContainer.add(optionsPanel, java.awt.BorderLayout.CENTER);
163
    }
148
    }
164
    
149
165
    boolean valid( WizardDescriptor wizardDescriptor )
150
    boolean valid(WizardDescriptor wizardDescriptor) {
166
    {
167
        wizardDescriptor.putProperty(
151
        wizardDescriptor.putProperty(
168
            NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, "" ); //NOI18N
152
                NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, ""); //NOI18N
169
        
153
170
        return projectLocationPanel.valid(wizardDescriptor) && 
154
        return projectLocationPanel.valid(wizardDescriptor)
171
                optionsPanel.valid(wizardDescriptor);
155
                && optionsPanel.valid(wizardDescriptor);
172
    }
156
    }
173
    
157
174
    void read(WizardDescriptor wizDesc)
158
    void read(WizardDescriptor wizDesc) {
175
    {
159
        Integer lastType = (Integer) wizDesc.getProperty(
176
        Integer lastType = (Integer)wizDesc.getProperty(
160
                NewUMLProjectWizardIterator.PROP_WIZARD_TYPE);
177
            NewUMLProjectWizardIterator.PROP_WIZARD_TYPE);
161
178
        
162
        if (lastType == null || lastType.intValue() != this.type) {
179
        if (lastType == null || lastType.intValue() != this.type)
180
        {
181
            //bugfix #46387 The type of project changed, reset values to defaults
163
            //bugfix #46387 The type of project changed, reset values to defaults
182
            wizDesc.putProperty(
164
            wizDesc.putProperty(
183
                NewUMLProjectWizardIterator.PROP_PROJECT_NAME, null);
165
                    NewUMLProjectWizardIterator.PROP_PROJECT_NAME, null);
184
            
166
185
            wizDesc.putProperty(
167
            wizDesc.putProperty(
186
                NewUMLProjectWizardIterator.PROP_PROJECT_DIR, null);
168
                    NewUMLProjectWizardIterator.PROP_PROJECT_DIR, null);
187
        }
169
        }
188
        
170
189
        projectLocationPanel.read(wizDesc);
171
        projectLocationPanel.read(wizDesc);
190
        optionsPanel.read(wizDesc);
172
        optionsPanel.read(wizDesc);
191
    }
173
    }
192
    
174
193
    void store(WizardDescriptor wizDesc)
175
    void store(WizardDescriptor wizDesc) {
194
    {
195
        wizDesc.putProperty(NewUMLProjectWizardIterator.PROP_WIZARD_TYPE,
176
        wizDesc.putProperty(NewUMLProjectWizardIterator.PROP_WIZARD_TYPE,
196
            new Integer(this.type));
177
                new Integer(this.type));
197
178
198
        projectLocationPanel.store(wizDesc);
179
        projectLocationPanel.store(wizDesc);
199
        optionsPanel.store(wizDesc);
180
        optionsPanel.store(wizDesc);
200
    }
181
    }
201
    
182
202
    void validate(WizardDescriptor wizDesc) 
183
    void validate(WizardDescriptor wizDesc)
203
        throws WizardValidationException
184
            throws WizardValidationException {
204
    {
205
        projectLocationPanel.validate(wizDesc);
185
        projectLocationPanel.validate(wizDesc);
206
    }
186
    }
207
    
187
208
    
209
    /** This method is called from within the constructor to
188
    /** This method is called from within the constructor to
210
     * initialize the form.
189
     * initialize the form.
211
     * WARNING: Do NOT modify this code. The content of this method is
190
     * WARNING: Do NOT modify this code. The content of this method is
Lines 256-270 Link Here
256
        optionsContainer.getAccessibleContext().setAccessibleDescription("");
235
        optionsContainer.getAccessibleContext().setAccessibleDescription("");
257
236
258
    }// </editor-fold>//GEN-END:initComponents
237
    }// </editor-fold>//GEN-END:initComponents
259
    
260
    /** Currently only handles the "Browse..." button
238
    /** Currently only handles the "Browse..." button
261
     */
239
     */
262
    
263
    // Variables declaration - do not modify//GEN-BEGIN:variables
240
    // Variables declaration - do not modify//GEN-BEGIN:variables
264
    private javax.swing.JSeparator jSeparator1;
241
    private javax.swing.JSeparator jSeparator1;
265
    private javax.swing.JPanel locationContainer;
242
    private javax.swing.JPanel locationContainer;
266
    private javax.swing.JPanel optionsContainer;
243
    private javax.swing.JPanel optionsContainer;
267
    // End of variables declaration//GEN-END:variables
244
    // End of variables declaration//GEN-END:variables
268
    
269
    
270
}
245
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/wizards/PanelOptionsVisual.form (-2 / +4 lines)
Lines 1-11 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.1" encoding="UTF-8" ?>
2
2
3
<Form version="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AccessibilityProperties>
4
  <AccessibilityProperties>
5
    <Property name="AccessibleContext.accessibleName" type="java.lang.String" value=""/>
5
    <Property name="AccessibleContext.accessibleName" type="java.lang.String" value=""/>
6
    <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
6
    <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
7
  </AccessibilityProperties>
7
  </AccessibilityProperties>
8
  <AuxValues>
8
  <AuxValues>
9
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
12
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
13
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/wizards/PanelOptionsVisual.java (-108 / +74 lines)
Lines 41-53 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.wizards;
44
package org.netbeans.modules.uml.project.ui.wizards;
46
45
47
import java.awt.BorderLayout;
46
import java.awt.BorderLayout;
48
47
49
import javax.swing.JPanel;
50
51
import org.netbeans.modules.uml.project.UMLProject;
48
import org.netbeans.modules.uml.project.UMLProject;
52
import org.netbeans.modules.uml.project.ui.common.ReferencedJavaProjectPanel;
49
import org.netbeans.modules.uml.project.ui.common.ReferencedJavaProjectPanel;
53
import org.openide.WizardDescriptor;
50
import org.openide.WizardDescriptor;
Lines 57-87 Link Here
57
 *
54
 *
58
 * @author  Mike Frisino
55
 * @author  Mike Frisino
59
 */
56
 */
60
public class PanelOptionsVisual extends SettingsPanel
57
public class PanelOptionsVisual extends SettingsPanel {
61
{
58
62
    private static boolean lastMainClassCheck = true; // XXX Store somewhere
59
    private static boolean lastMainClassCheck = true; // XXX Store somewhere
63
    private PanelConfigureProject panelConfigureProject;
60
    private PanelConfigureProject panelConfigureProject;
64
    private boolean valid;
61
    private boolean valid;
65
    private int wizardType = NewUMLProjectWizardIterator.TYPE_UML;
62
    private int wizardType = NewUMLProjectWizardIterator.TYPE_UML;
66
    private ReferencedJavaProjectPanel javaProjectPanel;
63
    private ReferencedJavaProjectPanel javaProjectPanel;
67
//    private RoseImportProjectPanel roseImportProjectPanel;
64
//    private RoseImportProjectPanel roseImportProjectPanel;
65
    public final static String MODE_CHANGED_PROP = "MODE_CHANGED"; // NOI18N
68
66
69
    public final static String MODE_CHANGED_PROP = "MODE_CHANGED"; // NOI18N
67
    public PanelOptionsVisual(PanelConfigureProject panel, int type) {
70
    
71
    public PanelOptionsVisual(PanelConfigureProject panel, int type)
72
    {
73
        initComponents();
68
        initComponents();
74
        this.panelConfigureProject = panel;
69
        this.panelConfigureProject = panel;
75
        this.wizardType = type;
70
        this.wizardType = type;
76
        
71
77
        switch (type)
72
        switch (type) {
78
        {
79
            case NewUMLProjectWizardIterator.TYPE_UML:
73
            case NewUMLProjectWizardIterator.TYPE_UML:
80
            case NewUMLProjectWizardIterator.TYPE_UML_JAVA:
74
            case NewUMLProjectWizardIterator.TYPE_UML_JAVA:
81
                hideJavaProjectPanel();
75
                hideJavaProjectPanel();
82
//                hideRoseImportProjectPanel();
76
//                hideRoseImportProjectPanel();
83
                break;
77
                break;
84
                
78
85
            case NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER:
79
            case NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER:
86
                createJavaProjectPanel();
80
                createJavaProjectPanel();
87
                showJavaProjectPanel();
81
                showJavaProjectPanel();
Lines 95-111 Link Here
95
//                break;
89
//                break;
96
        }
90
        }
97
    }
91
    }
98
    
99
92
100
    private void createJavaProjectPanel()
93
    private void createJavaProjectPanel() {
101
    {
94
        if (javaProjectPanel == null) {
102
        if (javaProjectPanel == null)
103
        {
104
            javaProjectPanel = new ReferencedJavaProjectPanel(panelConfigureProject, wizardType);
95
            javaProjectPanel = new ReferencedJavaProjectPanel(panelConfigureProject, wizardType);
105
            add(javaProjectPanel, BorderLayout.CENTER);
96
            add(javaProjectPanel, BorderLayout.CENTER);
106
        }
97
        }
107
    }
98
    }
108
    
99
109
//    private void createRoseImportProjectPanel()
100
//    private void createRoseImportProjectPanel()
110
//    {
101
//    {
111
//        if (roseImportProjectPanel == null)
102
//        if (roseImportProjectPanel == null)
Lines 115-132 Link Here
115
//            add(roseImportProjectPanel, BorderLayout.CENTER);
106
//            add(roseImportProjectPanel, BorderLayout.CENTER);
116
//        }
107
//        }
117
//    }
108
//    }
118
    
109
    private void showJavaProjectPanel() {
119
    private void showJavaProjectPanel()
120
    {
121
        javaProjectPanel.setVisible(true);
110
        javaProjectPanel.setVisible(true);
122
111
123
        javaProjectPanel.addPropertyChangeListener(
112
        javaProjectPanel.addPropertyChangeListener(
124
            ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP, 
113
                ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP,
125
            panelConfigureProject);
114
                panelConfigureProject);
126
        
115
127
        javaProjectPanel.addPropertyChangeListener(
116
        javaProjectPanel.addPropertyChangeListener(
128
            ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP, 
117
                ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP,
129
            panelConfigureProject);
118
                panelConfigureProject);
130
    }
119
    }
131
120
132
//    private void showRoseImportProjectPanel()
121
//    private void showRoseImportProjectPanel()
Lines 137-161 Link Here
137
//            RoseImportProjectPanel.ROSE_MODEL_PROP, 
126
//            RoseImportProjectPanel.ROSE_MODEL_PROP, 
138
//            panelConfigureProject);
127
//            panelConfigureProject);
139
//    }
128
//    }
140
129
    private void hideJavaProjectPanel() {
141
    private void hideJavaProjectPanel()
142
    {
143
        // if never instatiated, then it doesn't need to be hidden
130
        // if never instatiated, then it doesn't need to be hidden
144
        // this is just defensive code and shouldn't happen
131
        // this is just defensive code and shouldn't happen
145
        if (javaProjectPanel == null)
132
        if (javaProjectPanel == null) {
146
            return;
133
            return;
147
        
134
        }
135
148
        javaProjectPanel.setVisible(false);
136
        javaProjectPanel.setVisible(false);
149
        
150
        javaProjectPanel.removePropertyChangeListener(
151
            ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP, 
152
            panelConfigureProject);
153
137
154
        javaProjectPanel.removePropertyChangeListener(
138
        javaProjectPanel.removePropertyChangeListener(
155
            ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP, 
139
                ReferencedJavaProjectPanel.ASSOCIATED_JAVA_PROJ_PROP,
156
            panelConfigureProject);
140
                panelConfigureProject);
141
142
        javaProjectPanel.removePropertyChangeListener(
143
                ReferencedJavaProjectPanel.SOURCE_GROUP_CHANGED_PROP,
144
                panelConfigureProject);
157
    }
145
    }
158
    
146
159
//    private void hideRoseImportProjectPanel()
147
//    private void hideRoseImportProjectPanel()
160
//    {
148
//    {
161
//        // if never instatiated, then it doesn't need to be hidden
149
//        // if never instatiated, then it doesn't need to be hidden
Lines 169-263 Link Here
169
//            RoseImportProjectPanel.ROSE_MODEL_PROP, 
157
//            RoseImportProjectPanel.ROSE_MODEL_PROP, 
170
//            panelConfigureProject);
158
//            panelConfigureProject);
171
//    }
159
//    }
172
    
160
    boolean valid(WizardDescriptor settings) {
173
174
    boolean valid(WizardDescriptor settings)
175
    {
176
        /* MCF - TODO - this is sample of bulletproofing code from the
161
        /* MCF - TODO - this is sample of bulletproofing code from the
177
         * j2se project or wherever i copied it from. We may need to do similar
162
         * j2se project or wherever i copied it from. We may need to do similar
178
         * here
163
         * here
179
         *
164
         *
180
        if (mainClassTextField.isVisible () && mainClassTextField.isEnabled ()) 
165
        if (mainClassTextField.isVisible () && mainClassTextField.isEnabled ()) 
181
         {
166
        {
182
            if (!valid) 
167
        if (!valid) 
183
            {
168
        {
184
                settings.putProperty(
169
        settings.putProperty(
185
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, // NOI18N
170
        NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, // NOI18N
186
                    NbBundle.getMessage(PanelOptionsVisual.class,
171
        NbBundle.getMessage(PanelOptionsVisual.class,
187
                        "ERROR_IllegalMainClassName")); //NOI18N
172
        "ERROR_IllegalMainClassName")); //NOI18N
188
            }
173
        }
189
174
        
190
            return this.valid;
175
        return this.valid;
191
        }
176
        }
192
        
177
        
193
        else 
178
        else 
194
            return true;
179
        return true;
195
         */
180
         */
196
181
197
        if (javaProjectPanel != null)
182
        if (javaProjectPanel != null) {
198
            return javaProjectPanel.valid(settings);
183
            return javaProjectPanel.valid(settings);
199
        
184
        } //        else if (roseImportProjectPanel != null)
200
//        else if (roseImportProjectPanel != null)
185
        //            return roseImportProjectPanel.valid(settings);
201
//            return roseImportProjectPanel.valid(settings);
186
        else {
187
            return true;
188
        }
189
    }
202
190
203
        else
191
    void read(WizardDescriptor wizDesc) {
204
            return true;
205
    }
206
    
207
    void read(WizardDescriptor wizDesc)
208
    {
209
        // TODO: do we need to do anything?
192
        // TODO: do we need to do anything?
210
    }
193
    }
211
    
194
212
    void validate(WizardDescriptor wizDesc) 
195
    void validate(WizardDescriptor wizDesc)
213
        throws WizardValidationException
196
            throws WizardValidationException {
214
    {
215
        // nothing to validate
197
        // nothing to validate
216
        if (wizardType == NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER)
198
        if (wizardType == NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER) {
217
        {
218
            // TODO - make sure they have selected a target
199
            // TODO - make sure they have selected a target
219
            // otherwise there is nothing to rev engineer
200
            // otherwise there is nothing to rev engineer
220
            if (javaProjectPanel.getSelectedProject() == null)
201
            if (javaProjectPanel.getSelectedProject() == null) {
221
            {
222
                // TODO set message and throw except
202
                // TODO set message and throw except
223
            }
203
            }
224
        }
204
        }
225
    }
205
    }
226
    
206
227
    void store(WizardDescriptor wizDesc)
207
    void store(WizardDescriptor wizDesc) {
228
    {
229
        wizDesc.putProperty(
208
        wizDesc.putProperty(
230
            NewUMLProjectWizardIterator.PROP_SET_AS_MAIN, Boolean.FALSE);
209
                NewUMLProjectWizardIterator.PROP_SET_AS_MAIN, Boolean.FALSE);
231
        
210
232
        if (wizardType == NewUMLProjectWizardIterator.TYPE_UML)
211
        if (wizardType == NewUMLProjectWizardIterator.TYPE_UML) {
233
        {
234
            wizDesc.putProperty(
212
            wizDesc.putProperty(
235
                NewUMLProjectWizardIterator.PROP_MODELING_MODE,
213
                    NewUMLProjectWizardIterator.PROP_MODELING_MODE,
236
                UMLProject.PROJECT_MODE_ANALYSIS_STR);
214
                    UMLProject.PROJECT_MODE_ANALYSIS_STR);
215
        } else if (wizardType == NewUMLProjectWizardIterator.TYPE_UML_JAVA) {
216
            wizDesc.putProperty(
217
                    NewUMLProjectWizardIterator.PROP_MODELING_MODE,
218
                    UMLProject.PROJECT_MODE_DESIGN_STR);
237
        }
219
        }
238
        
220
239
        else if (wizardType == NewUMLProjectWizardIterator.TYPE_UML_JAVA)
221
        if (wizardType == NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER) {
240
        {
241
            wizDesc.putProperty(
222
            wizDesc.putProperty(
242
                NewUMLProjectWizardIterator.PROP_MODELING_MODE,
223
                    NewUMLProjectWizardIterator.PROP_MODELING_MODE,
243
                UMLProject.PROJECT_MODE_DESIGN_STR);
224
                    UMLProject.PROJECT_MODE_IMPL_STR);
244
        }
245
        
246
        if (wizardType == NewUMLProjectWizardIterator.TYPE_REVERSE_ENGINEER)
247
        {
248
            wizDesc.putProperty(
249
                NewUMLProjectWizardIterator.PROP_MODELING_MODE,
250
                UMLProject.PROJECT_MODE_IMPL_STR);
251
225
252
            wizDesc.putProperty(
226
            wizDesc.putProperty(
253
                NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_PROJECT,
227
                    NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_PROJECT,
254
                javaProjectPanel.getSelectedProject());
228
                    javaProjectPanel.getSelectedProject());
255
            
229
256
            wizDesc.putProperty(
230
            wizDesc.putProperty(
257
                NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_ROOTS_MODEL,
231
                    NewUMLProjectWizardIterator.PROP_JAVA_SOURCE_ROOTS_MODEL,
258
                javaProjectPanel.getJavaSourceRootsModel());
232
                    javaProjectPanel.getJavaSourceRootsModel());
259
        }
233
        }
260
        
234
261
//        if (wizardType == NewUMLProjectWizardIterator.TYPE_ROSE_IMPORT)
235
//        if (wizardType == NewUMLProjectWizardIterator.TYPE_ROSE_IMPORT)
262
//        {
236
//        {
263
//            wizDesc.putProperty(
237
//            wizDesc.putProperty(
Lines 269-276 Link Here
269
//                roseImportProjectPanel.getModelingMode());
243
//                roseImportProjectPanel.getModelingMode());
270
//        }
244
//        }
271
    }
245
    }
272
    
246
273
    
274
    /** This method is called from within the constructor to
247
    /** This method is called from within the constructor to
275
     * initialize the form.
248
     * initialize the form.
276
     * WARNING: Do NOT modify this code. The content of this method is
249
     * WARNING: Do NOT modify this code. The content of this method is
Lines 284-292 Link Here
284
        getAccessibleContext().setAccessibleName("");
257
        getAccessibleContext().setAccessibleName("");
285
        getAccessibleContext().setAccessibleDescription("");
258
        getAccessibleContext().setAccessibleDescription("");
286
    }// </editor-fold>//GEN-END:initComponents
259
    }// </editor-fold>//GEN-END:initComponents
287
288
    
289
    
290
//    public void propertyChange(PropertyChangeEvent evt)
260
//    public void propertyChange(PropertyChangeEvent evt)
291
//    {
261
//    {
292
//        if (evt.getPropertyName().equals(
262
//        if (evt.getPropertyName().equals(
Lines 302-308 Link Here
302
//                hideJavaProjectPanel();
272
//                hideJavaProjectPanel();
303
//        }
273
//        }
304
//    }
274
//    }
305
    
306
    // This panelConfigureProject is added at the bottom of the container to
275
    // This panelConfigureProject is added at the bottom of the container to
307
    // just pushes the other items up so the layout is as intended.
276
    // just pushes the other items up so the layout is as intended.
308
    // MCF - this was needed when we were using the grid bag layout
277
    // MCF - this was needed when we were using the grid bag layout
Lines 327-335 Link Here
327
//            java.util.ResourceBundle.getBundle(
296
//            java.util.ResourceBundle.getBundle(
328
//            "org/netbeans/modules/uml/project/ui/wizards/Bundle").getString("ASCD_jPanel1"));
297
//            "org/netbeans/modules/uml/project/ui/wizards/Bundle").getString("ASCD_jPanel1"));
329
//    }
298
//    }
330
    
331
    
332
    // Variables declaration - do not modify//GEN-BEGIN:variables
299
    // Variables declaration - do not modify//GEN-BEGIN:variables
333
    // End of variables declaration//GEN-END:variables
300
    // End of variables declaration//GEN-END:variables
334
335
}
301
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/wizards/ProjectLocationVisualPanel.form (-2 / +4 lines)
Lines 1-11 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.1" encoding="UTF-8" ?>
2
2
3
<Form version="1.3" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <NonVisualComponents>
4
  <NonVisualComponents>
5
    <Component class="javax.swing.ButtonGroup" name="modelTypeButtonGroup">
5
    <Component class="javax.swing.ButtonGroup" name="modelTypeButtonGroup">
6
    </Component>
6
    </Component>
7
  </NonVisualComponents>
7
  </NonVisualComponents>
8
  <AuxValues>
8
  <AuxValues>
9
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
12
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
13
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/wizards/ProjectLocationVisualPanel.java (-178 / +133 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.wizards;
44
package org.netbeans.modules.uml.project.ui.wizards;
46
45
47
import java.io.File;
46
import java.io.File;
Lines 60-76 Link Here
60
import org.netbeans.spi.project.ui.support.ProjectChooser;
59
import org.netbeans.spi.project.ui.support.ProjectChooser;
61
60
62
import org.netbeans.modules.uml.project.ui.UMLProjectSettings;
61
import org.netbeans.modules.uml.project.ui.UMLProjectSettings;
63
import org.netbeans.modules.uml.project.ui.common.ReferencedJavaProjectPanel;
64
62
65
/**
63
/**
66
 *
64
 *
67
 * @author  Craig Conover, craig.conover@sun.com
65
 * @author  Craig Conover, craig.conover@sun.com
68
 */
66
 */
69
public class ProjectLocationVisualPanel extends SettingsPanel
67
public class ProjectLocationVisualPanel extends SettingsPanel
70
    implements DocumentListener
68
        implements DocumentListener {
71
{
69
72
    public ProjectLocationVisualPanel(PanelConfigureProject panel, int type)
70
    public ProjectLocationVisualPanel(PanelConfigureProject panel, int type) {
73
    {
74
        initComponents();
71
        initComponents();
75
        this.panel = panel;
72
        this.panel = panel;
76
        this.type = type;
73
        this.type = type;
Lines 79-91 Link Here
79
        projectNameTextField.getDocument().addDocumentListener(this);
76
        projectNameTextField.getDocument().addDocumentListener(this);
80
        projectLocationTextField.getDocument().addDocumentListener(this);
77
        projectLocationTextField.getDocument().addDocumentListener(this);
81
    }
78
    }
82
    
79
83
    
80
    public String getProjectName() {
84
    public String getProjectName()
85
    {
86
        return this.projectNameTextField.getText().trim();
81
        return this.projectNameTextField.getText().trim();
87
    }
82
    }
88
    
83
89
    /** This method is called from within the constructor to
84
    /** This method is called from within the constructor to
90
     * initialize the form.
85
     * initialize the form.
91
     * WARNING: Do NOT modify this code. The content of this method is
86
     * WARNING: Do NOT modify this code. The content of this method is
Lines 187-249 Link Here
187
        {
182
        {
188
            JFileChooser chooser = new JFileChooser();
183
            JFileChooser chooser = new JFileChooser();
189
            FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
184
            FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
190
            
185
191
            chooser.setDialogTitle(
186
            chooser.setDialogTitle(
192
                bundle.getString("LBL_NWP1_SelectProjectLocation")); // NOI18N
187
                    bundle.getString("LBL_NWP1_SelectProjectLocation")); // NOI18N
193
            
188
194
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
189
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
195
            String path = this.projectLocationTextField.getText();
190
            String path = this.projectLocationTextField.getText();
196
            
191
197
            if (path.length() > 0)
192
            if (path.length() > 0) {
198
            {
199
                File f = new File(path);
193
                File f = new File(path);
200
194
201
                if (f.exists())
195
                if (f.exists()) {
202
                    chooser.setSelectedFile(f);
196
                    chooser.setSelectedFile(f);
197
                }
203
            }
198
            }
204
            
199
205
            if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this))
200
            if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
206
            {
207
                File projectDir = chooser.getSelectedFile();
201
                File projectDir = chooser.getSelectedFile();
208
                projectLocationTextField.setText(projectDir.getAbsolutePath());
202
                projectLocationTextField.setText(projectDir.getAbsolutePath());
209
            }
203
            }
210
            
204
211
            panel.fireChangeEvent();
205
            panel.fireChangeEvent();
212
        }
206
        }
213
    }//GEN-LAST:event_browseLocationAction
207
    }//GEN-LAST:event_browseLocationAction
214
    
208
215
    boolean valid(WizardDescriptor wizardDescriptor)
209
    boolean valid(WizardDescriptor wizardDescriptor) {
216
    {
217
        String projectName = projectNameTextField.getText();
210
        String projectName = projectNameTextField.getText();
218
        String trimmedName = projectName.trim();
211
        String trimmedName = projectName.trim();
219
        int trimmedLen = trimmedName.length();
212
        int trimmedLen = trimmedName.length();
220
        
213
221
        // Ported the fix from coco CR# 6458824 to coke.
214
        // Ported the fix from coco CR# 6458824 to coke.
222
        // Not allowing leading/trailing spaces in project name and project folder name
215
        // Not allowing leading/trailing spaces in project name and project folder name
223
        if (trimmedLen == 0 || trimmedLen < projectName.length())
216
        if (trimmedLen == 0 || trimmedLen < projectName.length()) {
224
        {
217
            String errorMsg = (trimmedLen == 0
225
            String errorMsg = (trimmedLen == 0 ?
218
                    ? bundle.getString("MSG_IllegalProjectName")
226
                bundle.getString("MSG_IllegalProjectName") :
219
                    : bundle.getString("MSG_SpacesInProjectName"));
227
                bundle.getString("MSG_SpacesInProjectName") );
220
228
            
229
            wizardDescriptor.putProperty(
221
            wizardDescriptor.putProperty(
230
                NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
222
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
231
                errorMsg);
223
                    errorMsg);
232
            
224
233
            return false; // Display name is invalid
225
            return false; // Display name is invalid
234
        }
226
        }
235
        
227
236
        File f = new File(projectLocationTextField.getText()).getAbsoluteFile();
228
        File f = new File(projectLocationTextField.getText()).getAbsoluteFile();
237
        
229
238
        if (getCanonicalFile(f)==null)
230
        if (getCanonicalFile(f) == null) {
239
        {
240
            String message = bundle.getString("MSG_IllegalProjectLocation"); // NOI18N
231
            String message = bundle.getString("MSG_IllegalProjectLocation"); // NOI18N
241
            
232
242
            wizardDescriptor.putProperty(
233
            wizardDescriptor.putProperty(
243
                NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, message);
234
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, message);
244
            return false;
235
            return false;
245
        }
236
        }
246
        
237
247
        // if none of the source groups are checked then the panel is invalid
238
        // if none of the source groups are checked then the panel is invalid
248
//        if (ReferencedJavaProjectPanel.mIsImplementationMode
239
//        if (ReferencedJavaProjectPanel.mIsImplementationMode
249
//            // no more Rose Import support
240
//            // no more Rose Import support
Lines 252-476 Link Here
252
//        {
243
//        {
253
//            return false;
244
//            return false;
254
//        }
245
//        }
255
        
246
256
        final File destFolder = getCanonicalFile(new File(
247
        final File destFolder = getCanonicalFile(new File(
257
            createdFolderTextField.getText()).getAbsoluteFile());
248
                createdFolderTextField.getText()).getAbsoluteFile());
258
        
249
259
        if (destFolder == null)
250
        if (destFolder == null) {
260
        {
261
            String message = bundle.getString("MSG_IllegalProjectName"); // NOI18N
251
            String message = bundle.getString("MSG_IllegalProjectName"); // NOI18N
262
            
252
263
            wizardDescriptor.putProperty(
253
            wizardDescriptor.putProperty(
264
                NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,message);
254
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, message);
265
            
255
266
            return false;
256
            return false;
267
        }
257
        }
268
        
258
269
        File projLoc = destFolder;
259
        File projLoc = destFolder;
270
        boolean readonly = true;
260
        boolean readonly = true;
271
        
261
272
        while (projLoc != null && !projLoc.exists())
262
        while (projLoc != null && !projLoc.exists()) {
273
            projLoc = projLoc.getParentFile();
263
            projLoc = projLoc.getParentFile();
274
        
264
        }
265
275
        // workaround for File.canWrite() 99009
266
        // workaround for File.canWrite() 99009
276
        if (projLoc != null)
267
        if (projLoc != null) {
277
        {
268
            try {
278
            try
279
            {
280
                File temp = File.createTempFile("temp", "", projLoc);
269
                File temp = File.createTempFile("temp", "", projLoc);
281
                if (temp.exists())
270
                if (temp.exists()) {
282
                {
283
                    readonly = false;
271
                    readonly = false;
284
                    temp.delete();
272
                    temp.delete();
285
                }
273
                }
286
            }
274
            } catch (IOException e) {
287
            catch (IOException e)
288
            {
289
                // nothing special to be handled
275
                // nothing special to be handled
290
            }
276
            }
291
        }
277
        }
292
        
278
293
        if (readonly)
279
        if (readonly) {
294
        {
295
            wizardDescriptor.putProperty(
280
            wizardDescriptor.putProperty(
296
                NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
281
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
297
                bundle.getString("MSG_ProjectFolderReadOnly")); // NOI18N
282
                    bundle.getString("MSG_ProjectFolderReadOnly")); // NOI18N
298
            
283
299
            return false;
284
            return false;
300
        }
285
        }
301
        
286
302
        if (FileUtil.toFileObject(projLoc) == null)
287
        if (FileUtil.toFileObject(projLoc) == null) {
303
        {
304
            String message = bundle.getString("MSG_IllegalProjectLocation"); // NOI18N
288
            String message = bundle.getString("MSG_IllegalProjectLocation"); // NOI18N
305
            
289
306
            wizardDescriptor.putProperty(
290
            wizardDescriptor.putProperty(
307
                NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, message);
291
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE, message);
308
            
292
309
            return false;
293
            return false;
310
        }
294
        }
311
        
295
312
        File[] kids = destFolder.listFiles();
296
        File[] kids = destFolder.listFiles();
313
        
297
314
        if (destFolder.exists() && kids != null && kids.length > 0)
298
        if (destFolder.exists() && kids != null && kids.length > 0) {
315
        {
316
            // Folder exists and is not empty
299
            // Folder exists and is not empty
317
            wizardDescriptor.putProperty(
300
            wizardDescriptor.putProperty(
318
                NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
301
                    NewUMLProjectWizardIterator.PROP_WIZARD_ERROR_MESSAGE,
319
                bundle.getString("MSG_ProjectFolderExists")); // NOI18N
302
                    bundle.getString("MSG_ProjectFolderExists")); // NOI18N
320
            
303
321
            return false;
304
            return false;
322
        }
305
        }
323
        
306
324
        return true;
307
        return true;
325
    }
308
    }
326
    
309
327
    void store(WizardDescriptor wizDesc)
310
    void store(WizardDescriptor wizDesc) {
328
    {
329
        wizDesc.putProperty(
311
        wizDesc.putProperty(
330
            NewUMLProjectWizardIterator.PROP_PROJECT_NAME, 
312
                NewUMLProjectWizardIterator.PROP_PROJECT_NAME,
331
            projectNameTextField.getText().trim());
313
                projectNameTextField.getText().trim());
332
314
333
        wizDesc.putProperty(
315
        wizDesc.putProperty(
334
            NewUMLProjectWizardIterator.PROP_PROJECT_DIR, 
316
                NewUMLProjectWizardIterator.PROP_PROJECT_DIR,
335
            new File(createdFolderTextField.getText().trim()));
317
                new File(createdFolderTextField.getText().trim()));
336
318
337
        wizDesc.putProperty(
319
        wizDesc.putProperty(
338
            NewUMLProjectWizardIterator.PROP_WIZARD_TYPE, 
320
                NewUMLProjectWizardIterator.PROP_WIZARD_TYPE,
339
            Integer.valueOf(type));
321
                Integer.valueOf(type));
340
    }
322
    }
341
    
323
342
    void read(WizardDescriptor wizDesc)
324
    void read(WizardDescriptor wizDesc) {
343
    {
325
        File projectLocation = (File) wizDesc.getProperty(
344
        File projectLocation = (File)wizDesc.getProperty(
326
                NewUMLProjectWizardIterator.PROP_PROJECT_DIR);
345
            NewUMLProjectWizardIterator.PROP_PROJECT_DIR);
327
346
        
328
        if (projectLocation == null
347
        if (projectLocation == null ||
329
                || projectLocation.getParentFile() == null
348
            projectLocation.getParentFile() == null ||
330
                || !projectLocation.getParentFile().isDirectory()) {
349
            !projectLocation.getParentFile().isDirectory())
350
        {
351
            projectLocation = ProjectChooser.getProjectsFolder();
331
            projectLocation = ProjectChooser.getProjectsFolder();
332
        } else {
333
            projectLocation = projectLocation.getParentFile();
352
        }
334
        }
353
        
335
354
        else
355
            projectLocation = projectLocation.getParentFile();
356
        
357
        projectLocationTextField.setText(projectLocation.getAbsolutePath());
336
        projectLocationTextField.setText(projectLocation.getAbsolutePath());
358
        
337
359
        String projectName = (String)wizDesc.getProperty(
338
        String projectName = (String) wizDesc.getProperty(
360
            NewUMLProjectWizardIterator.PROP_PROJECT_NAME);
339
                NewUMLProjectWizardIterator.PROP_PROJECT_NAME);
361
        
340
362
        if (projectName == null)
341
        if (projectName == null) {
363
        {
364
            String baseName = bundle.getString("TXT_UMLProject"); // NOI18N
342
            String baseName = bundle.getString("TXT_UMLProject"); // NOI18N
365
343
366
            projectName = ProjectUtil.createUniqueProjectName(
344
            projectName = ProjectUtil.createUniqueProjectName(
367
                projectLocation, baseName, false);
345
                    projectLocation, baseName, false);
368
346
369
            wizDesc.putProperty(
347
            wizDesc.putProperty(
370
                NewUMLProjectWizardIterator.PROP_NAME_INDEX,
348
                    NewUMLProjectWizardIterator.PROP_NAME_INDEX,
371
                new Integer(UMLProjectSettings.getDefault().getNewProjectCount()));
349
                    new Integer(UMLProjectSettings.getDefault().getNewProjectCount()));
372
        }
350
        }
373
        
351
374
        projectNameTextField.setText(projectName);
352
        projectNameTextField.setText(projectName);
375
        projectNameTextField.selectAll();
353
        projectNameTextField.selectAll();
376
        
354
377
        firePropertyChange(PanelOptionsVisual.MODE_CHANGED_PROP, null, 
355
        firePropertyChange(PanelOptionsVisual.MODE_CHANGED_PROP, null,
378
            wizDesc.getProperty(NewUMLProjectWizardIterator.PROP_WIZARD_TYPE));
356
                wizDesc.getProperty(NewUMLProjectWizardIterator.PROP_WIZARD_TYPE));
379
    }
357
    }
380
    
358
381
    void validate(WizardDescriptor d) throws WizardValidationException
359
    void validate(WizardDescriptor d) throws WizardValidationException {
382
    {
383
        // nothing to validate
360
        // nothing to validate
384
    }
361
    }
385
    
362
386
    
363
    private static JFileChooser createChooser() {
387
    private static JFileChooser createChooser()
388
    {
389
        JFileChooser chooser = new JFileChooser();
364
        JFileChooser chooser = new JFileChooser();
390
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
365
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
391
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
366
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
392
        chooser.setAcceptAllFileFilterUsed(false);
367
        chooser.setAcceptAllFileFilterUsed(false);
393
        
368
394
        chooser.setName(NbBundle.getMessage(
369
        chooser.setName(NbBundle.getMessage(
395
            ProjectLocationVisualPanel.class,
370
                ProjectLocationVisualPanel.class,
396
            "LBL_NWP1_SelectProjectLocation"));  // NOI18N
371
                "LBL_NWP1_SelectProjectLocation"));  // NOI18N
397
        
372
398
        return chooser;
373
        return chooser;
399
    }
374
    }
400
    
401
375
402
    public void changedUpdate(DocumentEvent event)
376
    public void changedUpdate(DocumentEvent event) {
403
    {
404
        updateTexts(event);
377
        updateTexts(event);
405
        
378
406
        if (this.projectNameTextField.getDocument() == event.getDocument())
379
        if (this.projectNameTextField.getDocument() == event.getDocument()) {
407
        {
408
            firePropertyChange(NewUMLProjectWizardIterator.PROP_PROJECT_NAME,
380
            firePropertyChange(NewUMLProjectWizardIterator.PROP_PROJECT_NAME,
409
                null,this.projectNameTextField.getText());
381
                    null, this.projectNameTextField.getText());
410
        }
382
        }
411
    }
383
    }
412
    
384
413
    public void insertUpdate( DocumentEvent event )
385
    public void insertUpdate(DocumentEvent event) {
414
    {
415
        updateTexts(event);
386
        updateTexts(event);
416
        
387
417
        if (this.projectNameTextField.getDocument() == event.getDocument())
388
        if (this.projectNameTextField.getDocument() == event.getDocument()) {
418
        {
419
            firePropertyChange(NewUMLProjectWizardIterator.PROP_PROJECT_NAME,
389
            firePropertyChange(NewUMLProjectWizardIterator.PROP_PROJECT_NAME,
420
                null,this.projectNameTextField.getText());
390
                    null, this.projectNameTextField.getText());
421
        }
391
        }
422
    }
392
    }
423
    
393
424
    public void removeUpdate(DocumentEvent event)
394
    public void removeUpdate(DocumentEvent event) {
425
    {
426
        updateTexts(event);
395
        updateTexts(event);
427
        
396
428
        if (this.projectNameTextField.getDocument() == event.getDocument())
397
        if (this.projectNameTextField.getDocument() == event.getDocument()) {
429
        {
430
            firePropertyChange(NewUMLProjectWizardIterator.PROP_PROJECT_NAME,
398
            firePropertyChange(NewUMLProjectWizardIterator.PROP_PROJECT_NAME,
431
                null,this.projectNameTextField.getText());
399
                    null, this.projectNameTextField.getText());
432
        }
400
        }
433
    }
401
    }
434
    
402
435
    
436
    /** Handles changes in the Project name and project directory
403
    /** Handles changes in the Project name and project directory
437
     */
404
     */
438
    private void updateTexts(DocumentEvent event)
405
    private void updateTexts(DocumentEvent event) {
439
    {
440
        Document doc = event.getDocument();
406
        Document doc = event.getDocument();
441
        
407
442
        if (doc == projectNameTextField.getDocument() ||
408
        if (doc == projectNameTextField.getDocument()
443
            doc == projectLocationTextField.getDocument())
409
                || doc == projectLocationTextField.getDocument()) {
444
        {
445
            // Change in the project name
410
            // Change in the project name
446
            String projectName = projectNameTextField.getText();
411
            String projectName = projectNameTextField.getText();
447
            String projectFolder = projectLocationTextField.getText();
412
            String projectFolder = projectLocationTextField.getText();
448
            
413
449
            //if ( projectFolder.trim().length() == 0 ||
414
            //if ( projectFolder.trim().length() == 0 ||
450
            //	projectFolder.equals( oldName )  ) {
415
            //	projectFolder.equals( oldName )  ) {
451
            createdFolderTextField.setText(
416
            createdFolderTextField.setText(
452
                projectFolder + File.separatorChar + projectName);
417
                    projectFolder + File.separatorChar + projectName);
453
            //}
418
            //}
454
        }
419
        }
455
        
420
456
        panel.fireChangeEvent(); // Notify that the panel changed
421
        panel.fireChangeEvent(); // Notify that the panel changed
457
    }
422
    }
458
    
423
459
    static File getCanonicalFile(File file)
424
    static File getCanonicalFile(File file) {
460
    {
425
        try {
461
        try
462
        {
463
            return file.getCanonicalFile();
426
            return file.getCanonicalFile();
464
        }
427
        } catch (IOException e) {
465
        
466
        catch (IOException e)
467
        {
468
            return null;
428
            return null;
469
        }
429
        }
470
    }
430
    }
471
472
473
    
474
    // Variables declaration - do not modify//GEN-BEGIN:variables
431
    // Variables declaration - do not modify//GEN-BEGIN:variables
475
    private javax.swing.JButton browseButton;
432
    private javax.swing.JButton browseButton;
476
    private javax.swing.JLabel createdFolderLabel;
433
    private javax.swing.JLabel createdFolderLabel;
Lines 481-490 Link Here
481
    private javax.swing.JLabel projectNameLabel;
438
    private javax.swing.JLabel projectNameLabel;
482
    private javax.swing.JTextField projectNameTextField;
439
    private javax.swing.JTextField projectNameTextField;
483
    // End of variables declaration//GEN-END:variables
440
    // End of variables declaration//GEN-END:variables
484
    
441
    private java.util.ResourceBundle bundle =
485
    private java.util.ResourceBundle bundle = 
442
            NbBundle.getBundle(ProjectLocationVisualPanel.class);
486
        NbBundle.getBundle(ProjectLocationVisualPanel.class);
487
    
488
    private PanelConfigureProject panel;
443
    private PanelConfigureProject panel;
489
    private int type;
444
    private int type;
490
}
445
}
(-)a/uml.project/src/org/netbeans/modules/uml/project/ui/wizards/newtemplates/NewUMLDiagWizardIterator.java (-266 / +221 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.uml.project.ui.wizards.newtemplates;
44
package org.netbeans.modules.uml.project.ui.wizards.newtemplates;
46
45
47
import java.awt.Component;
46
import java.awt.Component;
Lines 53-59 Link Here
53
import javax.swing.event.ChangeListener;
52
import javax.swing.event.ChangeListener;
54
53
55
import org.netbeans.api.project.Project;
54
import org.netbeans.api.project.Project;
56
import org.netbeans.modules.uml.core.UMLSettings;
57
55
58
import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
56
import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
59
import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramKind;
57
import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramKind;
Lines 71-77 Link Here
71
import org.netbeans.modules.uml.ui.controls.newdialog.NewDialogElementDetails;
69
import org.netbeans.modules.uml.ui.controls.newdialog.NewDialogElementDetails;
72
import org.netbeans.modules.uml.ui.controls.newdialog.NewDialogPackageDetails;
70
import org.netbeans.modules.uml.ui.controls.newdialog.NewDialogPackageDetails;
73
import org.netbeans.modules.uml.ui.controls.newdialog.NewDialogResultProcessor;
71
import org.netbeans.modules.uml.ui.controls.newdialog.NewDialogResultProcessor;
74
import org.netbeans.modules.uml.ui.controls.newdialog.NewDialogUtilities;
75
import org.netbeans.modules.uml.ui.controls.newdialog.NewUMLDiagWizardPanel1;
72
import org.netbeans.modules.uml.ui.controls.newdialog.NewUMLDiagWizardPanel1;
76
import org.netbeans.spi.project.ui.templates.support.Templates;
73
import org.netbeans.spi.project.ui.templates.support.Templates;
77
74
Lines 81-354 Link Here
81
import org.openide.util.NbBundle;
78
import org.openide.util.NbBundle;
82
79
83
public final class NewUMLDiagWizardIterator
80
public final class NewUMLDiagWizardIterator
84
      implements TemplateWizard.Iterator, INewUMLFileTemplates
81
        implements TemplateWizard.Iterator, INewUMLFileTemplates {
85
{
82
86
   private int index;
83
    private int index;
87
   private TemplateWizard wizard;
84
    private TemplateWizard wizard;
88
   private WizardDescriptor.Panel[] panels;
85
    private WizardDescriptor.Panel[] panels;
89
   private int templateType = NEW_DIAGRAM;
86
    private int templateType = NEW_DIAGRAM;
90
   
87
91
   private NewUMLDiagWizardIterator(int type)
88
    private NewUMLDiagWizardIterator(int type) {
92
   {
89
        this.templateType = type;
93
      this.templateType = type;
90
    }
94
   }
91
95
   
92
    public static NewUMLDiagWizardIterator createDiagramIterator() {
96
   public static NewUMLDiagWizardIterator createDiagramIterator()
93
        return new NewUMLDiagWizardIterator(NEW_DIAGRAM);
97
   {
94
    }
98
      return new NewUMLDiagWizardIterator(NEW_DIAGRAM);
95
99
   }
96
    public static NewUMLDiagWizardIterator createPackageIterator() {
100
   
97
        return new NewUMLDiagWizardIterator(NEW_PACKAGE);
101
   public static NewUMLDiagWizardIterator createPackageIterator()
98
    }
102
   {
99
103
      return new NewUMLDiagWizardIterator(NEW_PACKAGE);
100
    public static NewUMLDiagWizardIterator createElementIterator() {
104
   }
101
        return new NewUMLDiagWizardIterator(NEW_ELEMENT);
105
   
102
    }
106
   public static NewUMLDiagWizardIterator createElementIterator()
103
107
   {
104
    public void initialize(TemplateWizard wiz) {
108
      return new NewUMLDiagWizardIterator(NEW_ELEMENT);
105
        this.wizard = wiz;
109
   }
106
        createPanels();
110
   
107
        Project currentProject = Templates.getProject(wiz);
111
   public void initialize(TemplateWizard wiz)
108
        if (currentProject == null) {
112
   {
109
            throw new IllegalArgumentException();
113
      this.wizard = wiz;
110
        }
114
      createPanels();
111
115
      Project currentProject = Templates.getProject(wiz); 
112
        UMLProjectHelper prjHelper = (UMLProjectHelper) currentProject.getLookup().lookup(UMLProjectHelper.class);
116
      if (currentProject == null)
113
117
      {
114
        if (prjHelper != null) {
118
         throw new IllegalArgumentException();
115
            IProject umlProject = prjHelper.getProject();
119
      }
116
120
      
117
            switch (this.templateType) {
121
      UMLProjectHelper prjHelper = (UMLProjectHelper)
118
                case NEW_PACKAGE:
122
            currentProject.getLookup().lookup(UMLProjectHelper.class);
119
                    INewDialogPackageDetails pDetails = new NewDialogPackageDetails();
123
      
120
                    if (umlProject instanceof INamespace) {
124
      if ( prjHelper != null )
121
                        pDetails.setNamespace((INamespace) umlProject);
125
      {
122
                    }
126
         IProject umlProject = prjHelper.getProject();
123
127
         
124
                    pDetails.setAllowFromRESelection(false);
128
         switch (this.templateType)
125
                    wiz.putProperty(PACKAGE_DETAILS, pDetails);
129
         {
126
                    break;
130
         case NEW_PACKAGE:
127
131
            INewDialogPackageDetails pDetails = new NewDialogPackageDetails();
128
                case NEW_ELEMENT:
132
            if (umlProject instanceof INamespace)
129
                    INewDialogElementDetails eDetails = new NewDialogElementDetails();
133
            {
130
                    if (umlProject instanceof INamespace) {
134
               pDetails.setNamespace( (INamespace) umlProject );
131
                        eDetails.setNamespace((INamespace) umlProject);
132
                    }
133
134
                    wiz.putProperty(ELEMENT_DETAILS, eDetails);
135
                    break;
136
137
                case NEW_DIAGRAM:
138
                default:
139
                    INewDialogDiagramDetails details = new NewDialogDiagramDetails();
140
                    if (umlProject instanceof INamespace) {
141
                        details.setNamespace((INamespace) umlProject);
142
                    }
143
144
                    details.setDiagramKind(IDiagramKind.DK_UNKNOWN);
145
                    details.setAvailableDiagramKinds(IDiagramKind.DK_ALL);
146
                    wiz.putProperty(DIAGRAM_DETAILS, details);
147
                    wiz.putProperty(PROP_PROJECT, currentProject);
148
                    break;
135
            }
149
            }
136
            
150
        }
137
            pDetails.setAllowFromRESelection( false );
151
    }
138
            wiz.putProperty(PACKAGE_DETAILS, pDetails);
152
139
            break;
153
    public void uninitialize(TemplateWizard wiz) {
140
            
154
        panels = null;
141
         case NEW_ELEMENT:
155
        wizard = null;
142
            INewDialogElementDetails eDetails = new NewDialogElementDetails();
156
    }
143
            if (umlProject instanceof INamespace)
157
144
            {
158
    /**
145
               eDetails.setNamespace( (INamespace) umlProject );
159
     * Initialize panels representing individual wizard's steps and sets
160
     * various properties for them influencing wizard appearance.
161
     */
162
    private WizardDescriptor.Panel[] createPanels() {
163
        if (panels == null) {
164
            switch (this.templateType) {
165
                case NEW_PACKAGE:
166
                    panels = new WizardDescriptor.Panel[]{
167
                                new AddPackageWizardPanel1()
168
                            };
169
                    break;
170
171
                case NEW_ELEMENT:
172
                    panels = new WizardDescriptor.Panel[]{
173
                                new AddElementWizardPanel1()
174
                            };
175
                    break;
176
177
                case NEW_DIAGRAM:
178
                default:  //NEW_DIAGRAM
179
                    panels = new WizardDescriptor.Panel[]{
180
                                new NewUMLDiagWizardPanel1()
181
                            };
182
                    break;
146
            }
183
            }
147
            
184
148
            wiz.putProperty(ELEMENT_DETAILS, eDetails);
185
            String[] steps = createSteps();
149
            break;
186
            for (int i = 0; i < panels.length; i++) {
150
            
187
                Component c = panels[i].getComponent();
151
         case NEW_DIAGRAM:
188
                if (steps[i] == null) {
152
         default:
189
                    steps[i] = c.getName();
153
            INewDialogDiagramDetails details = new NewDialogDiagramDetails();
190
                }
154
            if (umlProject instanceof INamespace)
191
155
            {
192
                if (c instanceof JComponent) { // assume Swing components
156
               details.setNamespace((INamespace) umlProject);
193
                    JComponent jc = (JComponent) c;
194
                    // Sets step number of a component
195
                    jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, new Integer(i)); // NOI18N
196
                    // Sets steps names for a panel
197
                    jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); // NOI18N
198
                    // Turn on subtitle creation on each step
199
                    jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, Boolean.TRUE); // NOI18N
200
                }
157
            }
201
            }
158
            
202
        }
159
            details.setDiagramKind(IDiagramKind.DK_UNKNOWN);
203
160
            details.setAvailableDiagramKinds(IDiagramKind.DK_ALL);
204
        return panels;
161
            wiz.putProperty(DIAGRAM_DETAILS, details);
205
    }
162
            wiz.putProperty(PROP_PROJECT, currentProject);
206
163
            break;
207
    private String[] createSteps() {
164
         }
208
        String[] beforeSteps = null;
165
      }
209
        Object prop = wizard.getProperty(WizardDescriptor.PROP_CONTENT_DATA); // NOI18N
166
   }
210
        if (prop != null && prop instanceof String[]) {
167
   
211
            beforeSteps = (String[]) prop;
168
   public void uninitialize(TemplateWizard wiz)
212
        }
169
   {
213
170
      panels = null;
214
        if (beforeSteps == null) {
171
      wizard = null;
215
            beforeSteps = new String[0];
172
   }
216
        }
173
   
217
174
   /**
218
        String[] res = new String[(beforeSteps.length - 1) + panels.length];
175
    * Initialize panels representing individual wizard's steps and sets
219
        for (int i = 0; i < res.length; i++) {
176
    * various properties for them influencing wizard appearance.
220
            if (i < (beforeSteps.length - 1)) {
177
    */
221
                res[i] = beforeSteps[i];
178
   private WizardDescriptor.Panel[] createPanels()
222
            } else {
179
   {
223
                res[i] = panels[i - beforeSteps.length + 1].getComponent().getName();
180
      if (panels == null)
181
      {
182
         switch (this.templateType)
183
         {
184
         case NEW_PACKAGE:
185
            panels = new WizardDescriptor.Panel[] {
186
               new AddPackageWizardPanel1()
187
            };
188
            break;
189
            
190
         case NEW_ELEMENT:
191
            panels = new WizardDescriptor.Panel[] {
192
               new AddElementWizardPanel1()
193
            };
194
            break;
195
            
196
         case NEW_DIAGRAM:
197
         default:  //NEW_DIAGRAM
198
            panels = new WizardDescriptor.Panel[] {
199
               new NewUMLDiagWizardPanel1()
200
            };
201
            break;
202
         }
203
         
204
         String[] steps = createSteps();
205
         for (int i = 0; i < panels.length; i++)
206
         {
207
            Component c = panels[i].getComponent();
208
            if (steps[i] == null)
209
            {
210
               steps[i] = c.getName();
211
            }
224
            }
212
            
225
        }
213
            if (c instanceof JComponent)
226
        return res;
214
            { // assume Swing components
227
    }
215
               JComponent jc = (JComponent) c;
216
               // Sets step number of a component
217
               jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, new Integer(i)); // NOI18N
218
               // Sets steps names for a panel
219
               jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); // NOI18N
220
               // Turn on subtitle creation on each step
221
               jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, Boolean.TRUE); // NOI18N
222
            }
223
         }
224
      }
225
      
226
      return panels;
227
   }
228
   
229
   private String[] createSteps()
230
   {
231
      String[] beforeSteps = null;
232
      Object prop = wizard.getProperty(WizardDescriptor.PROP_CONTENT_DATA); // NOI18N
233
      if (prop != null && prop instanceof String[])
234
      {
235
         beforeSteps = (String[]) prop;
236
      }
237
      
238
      if (beforeSteps == null)
239
      {
240
         beforeSteps = new String[0];
241
      }
242
      
243
      String[] res = new String[(beforeSteps.length - 1) + panels.length];
244
      for (int i = 0; i < res.length; i++)
245
      {
246
         if (i < (beforeSteps.length - 1))
247
         {
248
            res[i] = beforeSteps[i];
249
         }
250
         
251
         else
252
         {
253
            res[i] = panels[i - beforeSteps.length + 1].getComponent().getName();
254
         }
255
      }
256
      return res;
257
   }
258
   
259
   public Set instantiate(TemplateWizard wiz) throws IOException
260
   {
261
      Set resultSet = new HashSet();
262
228
263
      switch (this.templateType)
229
    public Set instantiate(TemplateWizard wiz) throws IOException {
264
      {
230
        Set resultSet = new HashSet();
265
      case NEW_PACKAGE:
231
266
         INewDialogPackageDetails pDetails = (INewDialogPackageDetails)
232
        switch (this.templateType) {
267
               wiz.getProperty(this.PACKAGE_DETAILS);
233
            case NEW_PACKAGE:
268
         if (pDetails != null)
234
                INewDialogPackageDetails pDetails = (INewDialogPackageDetails) wiz.getProperty(this.PACKAGE_DETAILS);
269
         {
235
                if (pDetails != null) {
270
            INewDialogResultProcessor processor = new NewDialogResultProcessor();
236
                    INewDialogResultProcessor processor = new NewDialogResultProcessor();
271
            processor.handleResult( pDetails );
237
                    processor.handleResult(pDetails);
272
         }
238
                }
273
         break;
239
                break;
274
         
240
275
      case NEW_ELEMENT:
241
            case NEW_ELEMENT:
276
         INewDialogElementDetails eDetails = (INewDialogElementDetails)
242
                INewDialogElementDetails eDetails = (INewDialogElementDetails) wiz.getProperty(this.ELEMENT_DETAILS);
277
               wiz.getProperty(this.ELEMENT_DETAILS);
243
                if (eDetails != null) {
278
         if (eDetails != null)
244
                    INewDialogResultProcessor processor = new NewDialogResultProcessor();
279
         {
245
                    processor.handleResult(eDetails);
280
            INewDialogResultProcessor processor = new NewDialogResultProcessor();
246
                }
281
            processor.handleResult( eDetails );
247
                break;
282
         }
248
283
         break;
249
            case NEW_DIAGRAM:
284
         
250
            default:
285
      case NEW_DIAGRAM:
251
                INewDialogDiagramDetails dDetails = (INewDialogDiagramDetails) wiz.getProperty(DIAGRAM_DETAILS);
286
      default:
252
287
         INewDialogDiagramDetails dDetails = (INewDialogDiagramDetails)
253
                if (dDetails != null) {
288
               wiz.getProperty(DIAGRAM_DETAILS);
289
         
290
         if (dDetails != null)
291
         {
292
//             UMLSettings.getDefault().incrementDiagramCount(
254
//             UMLSettings.getDefault().incrementDiagramCount(
293
//                 dDetails.getName(), dDetails.getDiagramKind());
255
//                 dDetails.getName(), dDetails.getDiagramKind());
294
             
256
295
             UMLProjectGenerator.createNewDiagram(dDetails.getNamespace(), 
257
                    UMLProjectGenerator.createNewDiagram(dDetails.getNamespace(),
296
                 dDetails.getDiagramKind(), dDetails.getName());
258
                            dDetails.getDiagramKind(), dDetails.getName());
297
         }
259
                }
298
         break;
260
                break;
299
      }
261
        }
300
      
262
301
      Project project = (Project)wiz.getProperty(this.PROP_PROJECT);
263
        Project project = (Project) wiz.getProperty(this.PROP_PROJECT);
302
      FileObject dir = project.getProjectDirectory();
264
        FileObject dir = project.getProjectDirectory();
303
      resultSet.add(dir);
265
        resultSet.add(dir);
304
      return resultSet;
266
        return resultSet;
305
   }
267
    }
306
   
268
307
   public WizardDescriptor.Panel current()
269
    public WizardDescriptor.Panel current() {
308
   {
270
        return panels[index];
309
      return panels[index];
271
    }
310
   }
272
311
   
273
    public String name() {
312
   public String name()
274
        return NbBundle.getMessage(
313
   {
275
                NewUMLDiagWizardIterator.class,
314
      return  NbBundle.getMessage(
276
                "NEWWIZARD_TITLE_INDEX", // NOI18N
315
            NewUMLDiagWizardIterator.class,
277
                String.valueOf(index + 1),
316
            "NEWWIZARD_TITLE_INDEX", // NOI18N
278
                String.valueOf(panels.length));
317
            String.valueOf(index + 1),
279
    }
318
            String.valueOf(panels.length) );
280
319
   }
281
    public boolean hasNext() {
320
   
282
        return index < panels.length - 1;
321
   public boolean hasNext()
283
    }
322
   {
284
323
      return index < panels.length - 1;
285
    public boolean hasPrevious() {
324
   }
286
        return index > 0;
325
   
287
    }
326
   public boolean hasPrevious()
288
327
   {
289
    public void nextPanel() {
328
      return index > 0;
290
        if (!hasNext()) {
329
   }
291
            throw new NoSuchElementException();
330
   
292
        }
331
   public void nextPanel()
293
        index++;
332
   {
294
    }
333
      if (!hasNext())
295
334
      {
296
    public void previousPanel() {
335
         throw new NoSuchElementException();
297
        if (!hasPrevious()) {
336
      }
298
            throw new NoSuchElementException();
337
      index++;
299
        }
338
   }
300
        index--;
339
   
301
    }
340
   public void previousPanel()
302
341
   {
303
    // If nothing unusual changes in the middle of the wizard, simply:
342
      if (!hasPrevious())
304
    public void addChangeListener(ChangeListener l) {
343
      {
305
    }
344
         throw new NoSuchElementException();
306
345
      }
307
    public void removeChangeListener(ChangeListener l) {
346
      index--;
308
    }
347
   }
348
   
349
   // If nothing unusual changes in the middle of the wizard, simply:
350
   public void addChangeListener(ChangeListener l)
351
   {}
352
   public void removeChangeListener(ChangeListener l)
353
   {}
354
}
309
}

Return to bug 187303