|
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.cvsclient.actions; import javax.swing.*; import org.openide.util.*; import org.openide.*; import java.awt.event.*; import java.awt.*; import java.util.*; import java.io.*; import java.beans.*; import java.lang.reflect.*; import org.netbeans.modules.javacvs.events.*; import org.netbeans.modules.javacvs.commands.*; import org.netbeans.modules.javacvs.FsGlobalOptions; import org.netbeans.modules.vcscore.settings.GeneralVcsSettings; import javax.accessibility.*; //import org.netbeans.modules.javacvs.*; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileStateInvalidException; import org.openide.*; import org.openide.windows.*; import org.netbeans.modules.cvsclient.NbJavaCvsFileSystem; import org.netbeans.modules.cvsclient.NbJavaCvsStatusManager; import org.netbeans.modules.javacvs.customizers.CustomizerPropChangeSupport; import org.netbeans.modules.javacvs.customizers.GlobalOptionsCustomizer; import org.netbeans.modules.cvsclient.*; import org.netbeans.modules.cvsclient.commands.add.*; import org.netbeans.modules.cvsclient.commands.*; import org.netbeans.modules.cvsclient.commands.annotate.*; import org.netbeans.modules.cvsclient.commands.commit.*; import org.netbeans.modules.cvsclient.commands.remove.*; import org.netbeans.modules.cvsclient.commands.checkout.*; import org.netbeans.modules.cvsclient.commands.diff.*; import org.netbeans.modules.cvsclient.commands.log.*; import org.netbeans.modules.cvsclient.commands.tag.*; import org.netbeans.modules.cvsclient.commands.grouping.*; import org.netbeans.modules.javacvs.commands.*; import org.netbeans.modules.vcscore.actions.*; import org.netbeans.modules.vcscore.VcsAttributes; import org.netbeans.modules.vcscore.grouping.*; import org.netbeans.modules.cvsclient.commands.status.*; import org.netbeans.modules.cvsclient.commands.update.*; import org.netbeans.lib.cvsclient.commandLine.GetOpt; import org.netbeans.lib.cvsclient.command.*; import org.openide.util.SharedClassObject; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; public class JavaCvsActionSupporter extends CommandActionSupporter { /******************************************************************** * ********************************************************************/ /* public static final String DO_CHECKOUT = "doCheckout"; //NOI18N public static final String DO_IMPORT = "doImport"; //NOI18N public static final String DO_EXPORT = "doExport"; //NOI18N public static final String DO_HISTORY = "doHistory"; //NOI18N public static final String DO_REFRESH = "doRefresh";//NOI18N public static final String DO_REFRESH_RECURS = "doRecursiveRefresh";//NOI18N public static final String DO_LIST_MODULES = "doListModules"; //NOI18N */ public static final String DO_REV_EXPLORER = "doRevisionExplorer"; //NOI18N public static final String DO_CVS_CLIENT = "doCvsClientAction"; //NOI18N public static final String DO_VERIFY = "doVerify"; //NOI18N private transient java.util.HashMap commandMap; // private transient FileObject[] convertedFileObjects; private transient String LOG_NAME = NbBundle.getBundle(org.netbeans.modules.javacvs.commands.CvsLog.class).getString("CvsLog.BeanName"); //NOI18N;; private transient String COMMIT_NAME = NbBundle.getBundle(org.netbeans.modules.javacvs.commands.CvsCommit.class).getString("CvsCommit.BeanName"); //NOI18N;; private transient String UPDATE_NAME = NbBundle.getBundle(org.netbeans.modules.javacvs.commands.CvsUpdate.class).getString("CvsUpdate.BeanName"); //NOI18N;; private transient String ADD_NAME = NbBundle.getBundle(org.netbeans.modules.javacvs.commands.CvsAdd.class).getString("CvsAdd.BeanName"); //NOI18N;; private transient String REMOVE_NAME = NbBundle.getBundle(org.netbeans.modules.javacvs.commands.CvsRemove.class).getString("CvsRemove.BeanName"); //NOI18N; private transient String DIFF_NAME = NbBundle.getBundle(org.netbeans.modules.javacvs.commands.CvsDiff.class).getString("CvsDiff.BeanName"); //NOI18N; private transient String GENERAL = NbBundle.getBundle(JavaCvsActionSupporter.class).getString("JavaCvsActionSupporter.tooltipVCSName") + " "; //NOI18N // private boolean ctrl_down; public JavaCvsActionSupporter() { commandMap = new java.util.HashMap(); commandMap.put(UpdateCommandAction.class, JUpdateCommandAction.class); commandMap.put(CommitCommandAction.class, JCommitCommandAction.class); commandMap.put(AddCommandAction.class, JAddCommandAction.class); commandMap.put(DiffCommandAction.class, JDiffCommandAction.class); commandMap.put(RemoveCommandAction.class, JRemoveCommandAction.class); commandMap.put(HistoryCommandAction.class, JLogCommandAction.class); commandMap.put(VersioningExplorerAction.class, DO_REV_EXPLORER); commandMap.put(CollectingAction.class, DO_CVS_CLIENT); commandMap.put(VerifyGroupAction.class, JVerifyCommandAction.class); } /* public void addSupportForAction(Class actionClass, String commandName) { commandMap.put(actionClass, commandName); } public void removeSupportForAction(Class actionClass) { commandMap.remove(actionClass); } */ public boolean isEnabled(GeneralCommandAction action, FileObject[] fileObjects) { FileObject[] convertedFileObjects = convertFileObjects(fileObjects); boolean isOnFiles = isOnFiles(convertedFileObjects); boolean isOnDirs = isOnDirectories(convertedFileObjects); boolean isOnRoot = isOnRoot(convertedFileObjects); Object value = commandMap.get(action.getClass()); if (action instanceof CallBackCommandAction) { CallBackCommandAction callAction = (CallBackCommandAction)action; return callAction.isEnabledShortcut(convertedFileObjects, isOnDirs, isOnRoot, isOnFiles); } if (value != null) { if (value instanceof java.lang.Class) { Class classa = (Class)value; CallBackCommandAction callAction = (CallBackCommandAction)SharedClassObject.findObject(classa, true); return callAction.isEnabledShortcut(convertedFileObjects, isOnDirs, isOnRoot, isOnFiles); } return true; } //DEBUG message System.out.println("didn't find value:" + action.getClass() + " in the supported actions.."); Thread.dumpStack(); return false; } /*** * Performs the conversion from the Fileobjects retrieved from nodes to the real * underlying versioning filesystem's fileobjects. Should be used in the action's code whenever * the action needs to work with the fileobjects of the versioning fs. * That is nessesary when the nodes come from the MultiFilesystem layer, * otherwise we'll get the wrong set of fileobjects and commands will behave strangely. */ public FileObject[] convertFileObjects(FileObject[] originals) { if (originals == null || originals.length == 0) { return originals; } FileObject[] toReturn = new FileObject[originals.length]; for (int i = 0; i < originals.length; i++) { toReturn[i] = originals[i]; FileObject fo = originals[i]; FileSystem fs = (FileSystem)fo.getAttribute(VcsAttributes.VCS_NATIVE_FS); if (fs != null) { try { FileSystem fileSys = fo.getFileSystem(); // System.out.println("fs=" + fileSys.getClass().getName()); // System.out.println("my fs root=" + fs.getDisplayName()); // System.out.println("orig fo path=" + fo.getPackageNameExt('/','.')); if (!fileSys.equals(fs)) { String nativePath = (String)fo.getAttribute(VcsAttributes.VCS_NATIVE_PACKAGE_NAME_EXT); // System.out.println("path=" + nativePath); toReturn[i] = fs.findResource(nativePath); } } catch (FileStateInvalidException exc) { continue; } } else { continue; } } return toReturn; } public void performAction(GeneralCommandAction action, FileObject[] fileObjects) { java.util.List impList; HashMap map = new HashMap(); NbJavaCvsFileSystem fs = null; FileObject[] convertedFileObjects = convertFileObjects(fileObjects); // instead of using the passed set of fos, use the cached, converted set created at enabled() method for (int i = 0; i < convertedFileObjects.length; i++) { FileObject fo = convertedFileObjects[i]; Object nativeFS = fo.getAttribute(org.netbeans.modules.vcscore.VcsAttributes.VCS_NATIVE_FS); if (nativeFS instanceof NbJavaCvsFileSystem) { fs = (NbJavaCvsFileSystem) nativeFS; } if (fs == null) { /* org.openide.ErrorManager errMan = org.openide.TopManager.getDefault().getErrorManager(); System.err.println("ERROR: please add a comment to bug #17264 assigned to mkleint@netbeans.org"); errMan.log("ERROR: please add a comment to bug #17264 assigned to mkleint@netbeans.org"); System.err.println("fo=" + fo.getPackageNameExt('/','.')); errMan.log("fo=" + fo.getPackageNameExt('/','.')); System.err.println("isValid=" + fo.isValid()); errMan.log("isValid=" + fo.isValid()); try { System.err.println("of fs=" + fo.getFileSystem().getDisplayName()); errMan.log("of fs=" + fo.getFileSystem().getDisplayName()); System.err.println("it's system name=" + fo.getFileSystem().getSystemName()); errMan.log("it's system name=" + fo.getFileSystem().getSystemName()); } catch (FileStateInvalidException exc) { System.err.println("fs is invalid.."); errMan.log("fs is invalid.."); } */ } if (fs != null && nativeFS != null) { if (fs.isProcessAllFiles() || fs.isImportant(fo.getPackageNameExt('/', '.'))) { impList = (java.util.List)map.get(fs); if (impList == null) { impList = new LinkedList(); map.put(fs, impList); } impList.add(fo); } } } CallBackCommandAction myAction = null; Object value = commandMap.get(action.getClass()); if (value != null && value instanceof Class) { // for general actions defined in vcscore, substitute them with // my own callback classes. myAction = (CallBackCommandAction)SharedClassObject.findObject((Class)value, true); myAction.putValue(GeneralCommandAction.GROUP_NAME_PROP, action.getValue(GeneralCommandAction.GROUP_NAME_PROP)); myAction.putValue(GeneralCommandAction.GROUP_DESCRIPTION_PROP, action.getValue(GeneralCommandAction.GROUP_DESCRIPTION_PROP)); } if (value == null && action instanceof CallBackCommandAction) { // for CallBackActions use their own value; myAction = (CallBackCommandAction)action; } if (myAction == null) { Thread.dumpStack(); return; } myAction.initCallBack(this); Iterator it = map.keySet().iterator(); while (it.hasNext()) { fs = (NbJavaCvsFileSystem)it.next(); impList = (java.util.List)map.get(fs); FileObject[] fos = new FileObject[impList.size()]; fos = (FileObject[])impList.toArray(fos); // if (fs.checkOffLine()) continue; myAction.performCallBack(fs, fos); } myAction.finishCallBack(); } /** * Test if any of the selected nodes are directories. * the fileobjects should be already processed by convertFileObjects. * @return |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.