|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.refactoring.ui; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.netbeans.jmi.javamodel.Element; import org.netbeans.jmi.javamodel.JavaClass; import org.netbeans.modules.refactoring.api.ui.AbstractRefactoringAction; import org.netbeans.modules.refactoring.api.ui.RefactoringUI; import org.netbeans.modules.java.JavaDataObject; import org.netbeans.modules.javacore.internalapi.JMIElementCookie; import org.openide.nodes.Node; import org.openide.util.NbBundle; public class MoveClassAction extends AbstractRefactoringAction { public MoveClassAction() { super (NbBundle.getMessage(MoveClassAction.class, "LBL_MoveClassAction"), null); } protected boolean enabled(Node[] activatedNodes) { if ((activatedNodes == null) || (activatedNodes.length < 1)) return false; JavaDataObject javaObject = (JavaDataObject) activatedNodes [0].getCookie (JavaDataObject.class); JMIElementCookie cookie = (JMIElementCookie) activatedNodes [0].getCookie (JMIElementCookie.class); if ((javaObject != null) && (cookie == null)) return true; Element elem = cookie != null ? cookie.getElement() : null; if (!(elem instanceof JavaClass)) return false; JavaClass clsElem = (JavaClass) elem; if (clsElem == null) return false; if (clsElem.getDeclaringClass () != null) return false; return true; } protected RefactoringUI createRefactoringUI(Node[] nodes, org.netbeans.jmi.javamodel.Element selectedElement) { if (fromListener) { if (javaDataObjects.size() == 1) { return new MoveClassUI((JavaDataObject) javaDataObjects.iterator().next(), true); } else { return new MoveClassesUI(javaDataObjects, true); } } if (nodes.length>1) { return new MoveClassesUI(getJDOs(nodes)); } JMIElementCookie jmiCookie = (JMIElementCookie)nodes[0].getCookie (JMIElementCookie.class); if (jmiCookie != null) return new MoveClassUI ((JavaClass)jmiCookie.getElement()); else return new MoveClassUI ((JavaDataObject) nodes [0].getCookie (JavaDataObject.class)); } // protected String iconResource () { // return "org/netbeans/modules/refactoring/resources/refactoring.gif"; // NOI18N // } private boolean fromListener = false; private Set javaDataObjects; public void performAction(Set a) { fromListener = true; javaDataObjects = a; super.performAction((Node []) null); } public void performAction() { fromListener = false; super.performAction(); } private Set getJDOs(Node[] nodes) { Set result = new HashSet(nodes.length); for (int i=0; i< nodes.length; i++) { JavaDataObject jdo = (JavaDataObject) nodes[i].getCookie(JavaDataObject.class); if (jdo!=null) result.add(jdo); } return result; } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.