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: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.cnd.highlight.error.includes;
029:
030: import java.util.ArrayList;
031: import java.util.HashSet;
032: import java.util.List;
033: import java.util.Set;
034: import org.netbeans.api.project.Project;
035: import org.netbeans.modules.cnd.api.model.CsmFile;
036: import org.netbeans.modules.cnd.api.model.CsmUID;
037: import org.netbeans.modules.cnd.api.project.NativeProject;
038: import org.netbeans.modules.cnd.highlight.error.BadgeProvider;
039: import org.openide.nodes.Node;
040: import org.openide.util.HelpCtx;
041: import org.openide.util.NbBundle;
042: import org.openide.util.actions.NodeAction;
043:
044: /**
045: *
046: * @author Alexander Simon
047: */
048: public class FailedIncludesAction extends NodeAction {
049:
050: public FailedIncludesAction() {
051: putValue("noIconInMenu", Boolean.TRUE); // NOI18N
052: }
053:
054: private String i18n(String id) {
055: return NbBundle.getMessage(FailedIncludesAction.class, id);
056: }
057:
058: protected void performAction(Node[] activatedNodes) {
059: List<NativeProject> projects = getNativeProjects(activatedNodes);
060: if (projects == null || projects.size() != 1) {
061: return;
062: }
063: NativeProject nativeProject = projects.get(0);
064: Set<CsmFile> list = new HashSet<CsmFile>();
065: Set<CsmUID<CsmFile>> set = BadgeProvider.getInstance()
066: .getFailedFiles(nativeProject);
067: if (set != null) {
068: for (CsmUID<CsmFile> fileUID : set) {
069: CsmFile csmFile = fileUID.getObject();
070: assert csmFile != null;
071: if (csmFile != null) {
072: list.add(csmFile);
073: }
074: }
075: }
076: ErrorIncludeDialog.showErrorIncludeDialog(list);
077: }
078:
079: protected boolean enable(Node[] activatedNodes) {
080: List<NativeProject> projects = getNativeProjects(activatedNodes);
081: if (projects == null || projects.size() != 1) {
082: return false;
083: }
084: return BadgeProvider.getInstance().hasFailedFiles(
085: projects.get(0));
086: }
087:
088: private List<NativeProject> getNativeProjects(Node[] nodes) {
089: List<NativeProject> projects = new ArrayList<NativeProject>();
090: for (int i = 0; i < nodes.length; i++) {
091: Project project = nodes[i].getLookup()
092: .lookup(Project.class);
093: if (project == null) {
094: return null;
095: }
096: NativeProject nativeProject = project.getLookup().lookup(
097: NativeProject.class);
098: if (nativeProject == null) {
099: return null;
100: }
101: projects.add(nativeProject);
102: }
103: return projects;
104: }
105:
106: @Override
107: protected boolean asynchronous() {
108: return false;
109: }
110:
111: public String getName() {
112: return i18n("ErrorIncludeMenu_Title"); // NOI18N
113: }
114:
115: public HelpCtx getHelpCtx() {
116: return HelpCtx.DEFAULT_HELP;
117: }
118: }
|