// Copyright 2011 Denis Stepanov
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package coffeescript.nb.project;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Action;
import org.netbeans.spi.project.ui.LogicalViewProvider;
import org.netbeans.spi.project.ui.support.CommonProjectActions;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;
import org.openide.util.Utilities;
import org.openide.util.lookup.Lookups;
import org.openide.util.lookup.ProxyLookup;
/**
*
* @author Denis Stepanov
*/
public class CoffeeScriptLogicalView implements LogicalViewProvider {
private final CoffeeScriptProject project;
public CoffeeScriptLogicalView(CoffeeScriptProject project) {
this.project = project;
}
@Override
public org.openide.nodes.Node createLogicalView() {
try {
FileObject text = project.getConfigFile(true);
DataFolder textDataObject = DataFolder.findFolder(text.getParent());
return new TextNode(textDataObject.getNodeDelegate(), project);
} catch (DataObjectNotFoundException donfe) {
Exceptions.printStackTrace(donfe);
return new AbstractNode(Children.LEAF);
}
}
@Override
public Node findPath(Node root, Object target) {
return null;
}
private static final class TextNode extends FilterNode {
private final CoffeeScriptProject project;
public TextNode(Node node, CoffeeScriptProject project) throws DataObjectNotFoundException {
super(node, new FilterNode.Children(node),
new ProxyLookup(new Lookup[]{
Lookups.singleton(project),
node.getLookup()
}));
this.project = project;
}
@Override
public Action[] getActions(boolean arg0) {
List<Action> actions = new ArrayList<Action>();
actions.add(CommonProjectActions.newFileAction());
actions.add(null);
actions.add(CommonProjectActions.setAsMainProjectAction());
actions.add(CommonProjectActions.closeProjectAction());
actions.add(null);
actions.add(CommonProjectActions.renameProjectAction());
actions.add(CommonProjectActions.moveProjectAction());
actions.add(CommonProjectActions.copyProjectAction());
actions.add(CommonProjectActions.deleteProjectAction());
actions.add(null);
actions.addAll(Utilities.actionsForPath("Projects/Actions")); //NOI18N
actions.add(null);
actions.add(CommonProjectActions.customizeProjectAction());
return actions.toArray(new Action[actions.size()]);
}
@Override
public Image getIcon(int type) {
return ImageUtilities.loadImage("coffeescript/nb/resources/coffeescript-icon.png");
}
@Override
public Image getOpenedIcon(int type) {
return getIcon(type);
}
@Override
public String getDisplayName() {
return project.getProjectDirectory().getName();
}
}
}