alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

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.vcscore.actions;

import org.openide.awt.SplittedPanel;
import org.openide.explorer.ExplorerPanel;
import org.openide.explorer.propertysheet.PropertySheetView;
import org.openide.explorer.view.BeanTreeView;
import org.openide.nodes.BeanNode;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.SharedClassObject;
import org.openide.util.actions.CallableSystemAction;
import org.openide.filesystems.*;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.loaders.InstanceDataObject;
import org.openide.cookies.InstanceCookie;
import org.openide.windows.Mode;
import org.openide.windows.TopComponent;
import org.openide.windows.Workspace;

import org.netbeans.modules.vcscore.settings.GeneralVcsSettings;
import org.openide.windows.WindowManager;

/**
 * The action, that will present VCS global options.
 * @author  Martin Entlicher
 */
public class VcsSettingsAction extends CallableSystemAction {

    private static final String MODE_NAME = "VersioningSettingsMode"; //NOI18N
    
    static final long serialVersionUID = 2267347903850705340L;
    
    /** Getter for help.
     */
    public HelpCtx getHelpCtx () {
        return null;
    }

    /** Getter for name
     */
    public String getName () {
        return org.openide.util.NbBundle.getBundle(VcsSettingsAction.class).getString("CTL_VcsSettingsActionName");
    }
    
    /**
     * @return false to run in AWT thread.
     */
    protected boolean asynchronous() {
        return false;
    }
    
    /**
     * Open VCS global options
     */
    public void performAction() {
        Workspace curr = WindowManager.getDefault().getCurrentWorkspace();
        Mode reMode = curr.findMode(MODE_NAME);
        if (reMode != null) {
            TopComponent[] components = reMode.getTopComponents();
            if (components.length > 0) {
                if (components[0].isOpened()) {
                    components[0].requestActive();
                } else {
                    components[0].open();
                }
                return ;
            }
        }
        Node root = null;
        FileSystem defFs = org.openide.filesystems.Repository.getDefault().getDefaultFileSystem();
        FileObject fo = defFs.findResource("Services/org-netbeans-modules-vcscore-settings-GeneralVcsSettingsNode.instance"); //NOI18N
        if (fo != null) {
            DataObject dobj;
            try {
                dobj = DataObject.find(fo);
            } catch (DataObjectNotFoundException exc) {
                dobj = null;
            }
            if (dobj != null && dobj instanceof InstanceDataObject) {
               InstanceDataObject ido = (InstanceDataObject)dobj;
               InstanceCookie cook = (InstanceCookie)ido.getCookie(InstanceCookie.class);
               root = ido.getNodeDelegate();
            }
        } 
        if (root == null) {
            return;
        }
        final String modeName = root.getDisplayName();
        ExplorerPanel panel = new ExplorerPanel() {
            
            public void open(Workspace workspace) {
                Mode myMode = workspace.findMode(this);
                if (myMode == null) {
                    // create new mode for CI and set the bounds properly
                    //String modeName = org.openide.util.NbBundle.getMessage(RevisionExplorer.class, "CTL_Explorer.title");
                    myMode = workspace.createMode(MODE_NAME, modeName, null); //NOI18N
                    myMode.dockInto(this);
                }
                super.open(workspace);
            }
            /** Called when the explored context changes.
             * Overriden - we don't want the title to chnage. */
            protected void updateTitle() {
                // empty to keep the title unchanged
            }
        };
        panel.getExplorerManager().setRootContext(root);
        PropertySheetView propertySheetView = new PropertySheetView();
        org.openide.awt.SplittedPanel split = new org.openide.awt.SplittedPanel();
        split.setSplitType(org.openide.awt.SplittedPanel.HORIZONTAL);
        split.add(new BeanTreeView(), org.openide.awt.SplittedPanel.ADD_LEFT);
        split.add(propertySheetView, org.openide.awt.SplittedPanel.ADD_RIGHT);
        panel.add(split);
        panel.setName(org.openide.util.NbBundle.getBundle(VcsSettingsAction.class).getString("CTL_VcsSettingsName"));
        panel.open();
        panel.setActivatedNodes(new Node[] { root });
    }

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.