KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > MainClassUpdater


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.clientproject;
20
21 import java.beans.PropertyChangeListener JavaDoc;
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import org.openide.util.RequestProcessor;
24 import org.netbeans.api.java.classpath.ClassPath;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
27
28 //TODO: RETOUCHE almost complete rewrite needed
29
class MainClassUpdater implements PropertyChangeListener JavaDoc {
30
31     private static RequestProcessor performer = new RequestProcessor();
32
33     private final Project project;
34     private final PropertyEvaluator eval;
35     private final UpdateHelper helper;
36     private final ClassPath sourcePath;
37     private final String JavaDoc mainClassPropName;
38 // private JavaClass mainClass;
39

40     public MainClassUpdater (Project project, PropertyEvaluator eval, UpdateHelper helper, ClassPath sourcePath, String JavaDoc mainClassPropName) {
41         this.project = project;
42         this.eval = eval;
43         this.helper = helper;
44         this.sourcePath = sourcePath;
45         this.mainClassPropName = mainClassPropName;
46         this.eval.addPropertyChangeListener (this);
47 // this.addClassListener ();
48
}
49
50     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
51         if (mainClassPropName.equals(evt.getPropertyName())) {
52 // this.addClassListener ();
53
}
54     }
55
56 // public void change(MDRChangeEvent event) {
57
// if (event.isOfType (AttributeEvent.EVENTMASK_ATTRIBUTE)) {
58
// AttributeEvent atEvent = (AttributeEvent) event;
59
// String attributeName = atEvent.getAttributeName();
60
// if ("name".equals(attributeName)) { //NOI18N
61
// final String newMainClassName = (String) atEvent.getNewElement();
62
// if (newMainClassName != null) {
63
// Runnable r = new Runnable () {
64
// public void run () {
65
// try {
66
// //#63048:Deadlock while renaming main class of older j2se project
67
// //Don't show a modal dialog under mutex
68
// final String oldMainClass = (String) ProjectManager.mutex().readAccess(
69
// new Mutex.ExceptionAction () {
70
// public Object run () throws Exception {
71
// EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
72
// return props.getProperty(mainClassPropName);
73
// }
74
// });
75
// if (!newMainClassName.equals(oldMainClass) && helper.requestSave()) {
76
// ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction () {
77
// public Object run() throws Exception {
78
// EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
79
// props.put(mainClassPropName, newMainClassName);
80
// helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); // #47609
81
// ProjectManager.getDefault().saveProject (project);
82
// return null;
83
// }
84
// });
85
// }
86
// } catch (MutexException e) {
87
// ErrorManager.getDefault().notify (e);
88
// }
89
// catch (IOException ioe) {
90
// ErrorManager.getDefault().notify (ioe);
91
// }
92
// }
93
// };
94
// //#63048:Deadlock while renaming main class of older j2se project
95
// //If we are not in the AWT thread reschedule it,
96
// //the UpdateHelper may need to display a dialog
97
// if (SwingUtilities.isEventDispatchThread()) {
98
// r.run();
99
// }
100
// else {
101
// SwingUtilities.invokeLater(r);
102
// }
103
// }
104
// }
105
// }
106
// }
107

108     public synchronized void unregister () {
109 // if (mainClass != null) {
110
// ((MDRChangeSource)mainClass).removeListener (this);
111
// mainClass = null;
112
// }
113
}
114
115 // private void addClassListener () {
116
// performer.post( new Runnable () {
117
// public void run() {
118
// //XXX: Implementation dependency, no way how to do it
119
// JMManager manager = (JMManager) JavaMetamodel.getManager();
120
// manager.waitScanFinished();
121
// JavaModel.getJavaRepository().beginTrans(false);
122
// try {
123
// JavaModel.setClassPath (sourcePath);
124
// String mainClassName = MainClassUpdater.this.eval.getProperty (mainClassPropName);
125
// Type type = manager.getDefaultExtent().getType().resolve(mainClassName);
126
// if ((type instanceof JavaClass) && ! (type instanceof UnresolvedClass)) {
127
// synchronized (MainClassUpdater.this) {
128
// if (MainClassUpdater.this.mainClass != null) {
129
// ((MDRChangeSource)mainClass).removeListener (MainClassUpdater.this);
130
// }
131
// MainClassUpdater.this.mainClass = (JavaClass) type;
132
// ((MDRChangeSource)MainClassUpdater.this.mainClass).addListener (MainClassUpdater.this);
133
// }
134
// }
135
// } finally {
136
// JavaModel.getJavaRepository().endTrans();
137
// }
138
// }
139
// });
140
// }
141

142 }
143
Popular Tags