|
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-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.refactoring; import java.util.ArrayList; import java.util.Arrays; import org.netbeans.modules.java.JavaDataLoader; import org.netbeans.modules.refactoring.ui.RSMJavaDOAction; import org.netbeans.modules.refactoring.ui.RefactoringOperationListener; import org.netbeans.modules.refactoring.ui.WhereUsedAction; import org.openide.actions.RenameAction; import org.openide.actions.ToolsAction; import org.openide.loaders.DataFolder; import org.openide.loaders.DataLoader; import org.openide.loaders.DataLoaderPool; import org.openide.modules.ModuleInstall; import org.openide.util.Lookup; import org.openide.util.actions.SystemAction; /** * @author Jan Becicka */ public class RefactoringModule extends ModuleInstall { public void restored() { addFolderAction(); addJDOActions(); RefactoringOperationListener.addOperationalListener(); } public void uninstalled() { removeFolderAction(); } /** add refactoring submenu for data folders * this should be probably done somewhere in layers * anyway - this will be obsolate with the new build system */ private void addFolderAction() { DataLoaderPool dataLoaderPool = (DataLoaderPool) Lookup.getDefault().lookup(DataLoaderPool.class); DataLoader folderLoader = dataLoaderPool.firstProducerOf(DataFolder.class); ArrayList actions = new ArrayList(Arrays.asList(folderLoader.getActions())); int index = actions.indexOf(SystemAction.get(RenameAction.class)); if (index >= 0) { actions.set(index , SystemAction.get(RSMJavaDOAction.class)); folderLoader.setActions((SystemAction[])actions.toArray(new SystemAction[actions.size()])); } } private void addJDOActions() { DataLoader javaLoader = DataLoader.getLoader(JavaDataLoader.class); ArrayList actions = new ArrayList(Arrays.asList(javaLoader.getActions())); actions.remove(SystemAction.get(RenameAction.class)); int index = actions.indexOf(SystemAction.get(ToolsAction.class)); if (index < 0) index = 0; actions.add(index, SystemAction.get(WhereUsedAction.class)); actions.add(index + 1, SystemAction.get(RSMJavaDOAction.class)); actions.add(index + 2, null); javaLoader.setActions((SystemAction[])actions.toArray(new SystemAction[actions.size()])); } private void removeFolderAction() { DataLoaderPool dataLoaderPool = (DataLoaderPool) Lookup.getDefault().lookup(DataLoaderPool.class); DataLoader folderLoader = dataLoaderPool.firstProducerOf(DataFolder.class); ArrayList actions = new ArrayList(Arrays.asList(folderLoader.getActions())); actions.remove(RSMJavaDOAction.findObject(RSMJavaDOAction.class)); folderLoader.setActions((SystemAction[])actions.toArray(new SystemAction[actions.size()])); } } |
... 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.