001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.sql.project;
043:
044: import java.awt.event.ActionEvent;
045: import java.beans.PropertyChangeEvent;
046: import java.beans.PropertyChangeListener;
047: import java.util.ResourceBundle;
048:
049: import javax.swing.AbstractAction;
050: import javax.swing.Action;
051:
052: import org.openide.nodes.*;
053: import org.openide.util.*;
054: import org.openide.util.actions.SystemAction;
055:
056: import org.netbeans.api.project.Project;
057: import org.netbeans.api.project.ProjectUtils;
058: import org.netbeans.spi.project.ui.support.CommonProjectActions;
059: import org.netbeans.spi.project.ActionProvider;
060: import org.netbeans.spi.project.SubprojectProvider;
061: import org.netbeans.spi.project.support.ant.AntProjectHelper;
062: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
063: import org.netbeans.spi.project.support.ant.ReferenceHelper;
064: import org.netbeans.spi.project.ui.LogicalViewProvider;
065: import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
066: import org.netbeans.modules.sql.project.SQLproConstants;
067: import org.netbeans.modules.sql.project.IcanproViews; //import org.netbeans.modules.sql.project.ui.customizer.IcanproProjectProperties;
068: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
069: import org.openide.loaders.DataFolder;
070: import org.openide.util.lookup.Lookups;
071:
072: /**
073: * Support for creating logical views.
074: * @author Petr Hrebejk
075: */
076: public class IcanproLogicalViewProvider implements LogicalViewProvider {
077:
078: private final Project project;
079: private final AntProjectHelper helper;
080: private final PropertyEvaluator evaluator;
081: private final SubprojectProvider spp;
082: private final ReferenceHelper resolver;
083:
084: public IcanproLogicalViewProvider(Project project,
085: AntProjectHelper helper, PropertyEvaluator evaluator,
086: SubprojectProvider spp, ReferenceHelper resolver) {
087: this .project = project;
088: assert project != null;
089: this .helper = helper;
090: assert helper != null;
091: this .evaluator = evaluator;
092: assert evaluator != null;
093: this .spp = spp;
094: assert spp != null;
095: this .resolver = resolver;
096: }
097:
098: public Node createLogicalView() {
099: return new IcanLogicalViewRootNode();
100: }
101:
102: public Node findPath(Node root, Object target) {
103: // XXX implement
104: return null;
105: }
106:
107: private static Lookup createLookup(Project project) {
108: DataFolder rootFolder = DataFolder.findFolder(project
109: .getProjectDirectory());
110: // XXX Remove root folder after FindAction rewrite
111: return Lookups.fixed(new Object[] { project, rootFolder });
112: }
113:
114: // Private innerclasses ----------------------------------------------------
115:
116: private static final String[] BREAKABLE_PROPERTIES = new String[] {
117: IcanproProjectProperties.JAVAC_CLASSPATH,
118: IcanproProjectProperties.DEBUG_CLASSPATH,
119: IcanproProjectProperties.SRC_DIR, };
120:
121: public static boolean hasBrokenLinks(AntProjectHelper helper,
122: ReferenceHelper resolver) {
123: /*
124: return BrokenReferencesSupport.isBroken(helper, resolver, BREAKABLE_PROPERTIES,
125: new String[] {IcanproProjectProperties.JAVA_PLATFORM});
126: */
127: return false;
128: }
129:
130: /** Filter node containin additional features for the J2SE physical
131: */
132: private final class IcanLogicalViewRootNode extends AbstractNode {
133:
134: private Action brokenLinksAction;
135: private boolean broken;
136:
137: public IcanLogicalViewRootNode() {
138: super (new IcanproViews.LogicalViewChildren(helper,
139: evaluator, project), createLookup(project));
140: setIconBase("org/netbeans/modules/sql/project/ui/resources/sqlproProjectIcon.gif"); // NOI18N
141: setName(ProjectUtils.getInformation(project)
142: .getDisplayName());
143: if (hasBrokenLinks(helper, resolver)) {
144: broken = true;
145: brokenLinksAction = new BrokenLinksAction();
146: }
147: }
148:
149: public Action[] getActions(boolean context) {
150: if (context)
151: return super .getActions(true);
152: else
153: return getAdditionalActions();
154: }
155:
156: public boolean canRename() {
157: return false;
158: }
159:
160: // Private methods -------------------------------------------------
161:
162: private Action[] getAdditionalActions() {
163:
164: ResourceBundle bundle = NbBundle
165: .getBundle(IcanproLogicalViewProvider.class);
166:
167: return new Action[] {
168: // disable new action at the top...
169: // CommonProjectActions.newFileAction(),
170: // null,
171: ProjectSensitiveActions.projectCommandAction(
172: ActionProvider.COMMAND_BUILD, bundle
173: .getString("LBL_BuildAction_Name"),
174: null), // NOI18N
175: ProjectSensitiveActions.projectCommandAction(
176: ActionProvider.COMMAND_REBUILD,
177: bundle.getString("LBL_RebuildAction_Name"),
178: null), // NOI18N
179: ProjectSensitiveActions.projectCommandAction(
180: ActionProvider.COMMAND_CLEAN, bundle
181: .getString("LBL_CleanAction_Name"),
182: null), // NOI18N
183: // null,
184: // ProjectSensitiveActions.projectCommandAction( IcanproConstants.COMMAND_REDEPLOY, bundle.getString( "LBL_RedeployAction_Name" ), null ), // NOI18N
185: // ProjectSensitiveActions.projectCommandAction( IcanproConstants.COMMAND_DEPLOY, bundle.getString( "LBL_DeployAction_Name" ), null ), // NOI18N
186: null,
187: CommonProjectActions.setAsMainProjectAction(),
188: CommonProjectActions.openSubprojectsAction(),
189: CommonProjectActions.closeProjectAction(),
190: null,
191: SystemAction
192: .get(org.openide.actions.FindAction.class),
193: // null,
194: // SystemAction.get(org.openide.actions.OpenLocalExplorerAction.class),
195: null, brokenLinksAction,
196: CommonProjectActions.customizeProjectAction(), };
197: }
198:
199: /** This action is created only when project has broken references.
200: * Once these are resolved the action is disabled.
201: */
202: private class BrokenLinksAction extends AbstractAction
203: implements PropertyChangeListener {
204:
205: public BrokenLinksAction() {
206: evaluator.addPropertyChangeListener(this );
207: putValue(Action.NAME, NbBundle.getMessage(
208: IcanproLogicalViewProvider.class,
209: "LBL_Fix_Broken_Links_Action"));
210: }
211:
212: public void actionPerformed(ActionEvent e) {
213: /*
214: BrokenReferencesSupport.showCustomizer(helper, resolver, BREAKABLE_PROPERTIES, new String[]{IcanproProjectProperties.JAVA_PLATFORM});
215: if (!hasBrokenLinks(helper, resolver)) {
216: disable();
217: }
218: */
219: // do nothing...
220: }
221:
222: public void propertyChange(PropertyChangeEvent evt) {
223: if (!broken) {
224: disable();
225: return;
226: }
227: broken = hasBrokenLinks(helper, resolver);
228: if (!broken) {
229: disable();
230: }
231: }
232:
233: private void disable() {
234: broken = false;
235: setEnabled(false);
236: evaluator.removePropertyChangeListener(this );
237: fireIconChange();
238: fireOpenedIconChange();
239: }
240:
241: }
242:
243: }
244:
245: /** Factory for project actions.<BR>
246: * XXX This class is a candidate for move to org.netbeans.spi.project.ui.support
247: */
248: public static class Actions {
249:
250: private Actions() {
251: } // This is a factory
252:
253: public static Action createAction(String key, String name,
254: boolean global) {
255: return new ActionImpl(key, name, global ? Utilities
256: .actionsGlobalContext() : null);
257: }
258:
259: private static class ActionImpl extends AbstractAction
260: implements ContextAwareAction {
261:
262: Lookup context;
263: String name;
264: String command;
265:
266: public ActionImpl(String command, String name,
267: Lookup context) {
268: super (name);
269: this .context = context;
270: this .command = command;
271: this .name = name;
272: }
273:
274: public void actionPerformed(ActionEvent e) {
275:
276: Project project = (Project) context
277: .lookup(Project.class);
278: ActionProvider ap = (ActionProvider) project
279: .getLookup().lookup(ActionProvider.class);
280:
281: ap.invokeAction(command, context);
282:
283: }
284:
285: public Action createContextAwareInstance(Lookup lookup) {
286: return new ActionImpl(command, name, lookup);
287: }
288: }
289:
290: }
291:
292: }
|