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

import java.text.*;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.*;
import org.openide.awt.JMenuPlus;
import javax.swing.*;
import javax.swing.event.*;

import org.openide.awt.Actions;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.SharedClassObject;
import org.openide.util.actions.*;
import org.openide.nodes.*;
import org.openide.cookies.*;
import org.openide.DialogDescriptor;
import org.openide.*;
import org.openide.loaders.*;
import org.openide.filesystems.*;

import org.netbeans.modules.vcscore.util.Table;
import org.netbeans.modules.vcscore.actions.*;

import org.netbeans.modules.javacvs.util.*;
import org.netbeans.modules.javacvs.*;
import org.netbeans.modules.cvsclient.*;
import org.netbeans.modules.javacvs.commands.*;
import org.openide.DialogDisplayer;

/** 
 * Action that displays a submenu of actions when presented in a menu or popup.
 *
 * @author  mkleint
 */

public class CollectingAction extends org.netbeans.modules.vcscore.actions.ClusteringAction  {

    
    private static final String POPUP_DEFAULT_FOLDER = "vcs/CvsClient/PopupMenu";  //NOI18N

//    private transient boolean firstPopupDialogShown = false;
    private transient boolean isOnDir;
    private transient boolean isOnRoot;
    private transient boolean isOnFile;
    private transient FileObject[] foArray;
    
//    private transient String commandToExecute = null;
//    private transient boolean wasCtrl_down = false;
    private transient int usedUiMode = 0;
    
    static final long serialVersionUID = -627768697097225916L;

    
    public CollectingAction() {
        super();
        putValue(POPUP_DEFINITION_FOLDER, POPUP_DEFAULT_FOLDER);
//        delegateToAbstractAction(false);
    }

    
    public String getName () {
        return NbBundle.getBundle(CollectingAction.class).getString("CollectingAction.displayName"); // NOI18N
    }
    
    protected String iconResource () {
        return null; //"SampleActionIcon.gif";
    }
    

    protected void createPresenter(JMenu menu, String menuPath){
        
/**
 * REDO This part.. the converting of fileobjects should be done for dir/root/file once only..
 * in case there are submenus, this is inneffective, since the method is recursive..
 *
 */     
        usedUiMode = NbJavaCvsFileSystem.MODE_NOVICE;
        isOnDir =  false;
        isOnRoot = false;
        isOnFile = false;
        foArray = null;
        HashMap map = getSupporterMap(getActivatedNodes());
        if (map == null) return;
        
        Iterator it = map.keySet().iterator();
        while (it.hasNext()) {
            // should currently only happen once..
            JavaCvsActionSupporter supp = (JavaCvsActionSupporter)it.next();
            Set foSet = (Set)map.get(supp);
            if (foSet != null) {
                foArray = new FileObject[foSet.size()];
                foArray = (FileObject[])foSet.toArray(foArray);
                foArray = supp.convertFileObjects(foArray);
                isOnRoot = supp.isOnRoot(foArray);
                isOnFile = supp.isOnFiles(foArray);
                isOnDir = supp.isOnDirectories(foArray);
                FileObject fo = foArray[0];
                try {
                    if (fo.getFileSystem() instanceof NbJavaCvsFileSystem) {
                        NbJavaCvsFileSystem fs = (NbJavaCvsFileSystem)fo.getFileSystem();
                        if (fs.getUiMode() == NbJavaCvsFileSystem.MODE_ADVANCED) {
                            usedUiMode = fs.getUiMode();
                        } 
                        else if (usedUiMode != NbJavaCvsFileSystem.MODE_ADVANCED
                             && fs.getUiMode() == NbJavaCvsFileSystem.MODE_COMMAND_LINE) {
                            usedUiMode = fs.getUiMode();
                        }
                    }
                } catch (FileStateInvalidException exc) {
                }
            }
        }
        putValue(this.IS_SWITCHABLE_POPUP, usedUiMode == NbJavaCvsFileSystem.MODE_NOVICE ? Boolean.TRUE : Boolean.FALSE);

        super.createPresenter(menu, menuPath);
        foArray = null;
    }
    
    
    protected boolean checkItemEnable(ClusterItemVisualizer item) {
        if (item instanceof CallBackCommandAction) {
            CallBackCommandAction act = (CallBackCommandAction)item;
            return act.isEnabledShortcut(foArray, isOnDir, isOnRoot, isOnFile);
        }
        return item.isItemEnabled(this);
    }
    

    

    public void actionPerformed(java.awt.event.ActionEvent e){
//        System.out.println("performing cvs client action..");
        JavaCvsSettings settings = (JavaCvsSettings)SharedClassObject.findObject(JavaCvsSettings.class, true);
        if (settings.isFirstTimer() && usedUiMode == NbJavaCvsFileSystem.MODE_NOVICE && !isCTRLDown()) {
            if (showFirstTimerDialog(e))
                super.actionPerformed(e);
        }
        else
            super.actionPerformed(e);
        
/*        Object obj = e.getSource();
        if (obj instanceof JMenuItem) {
            JMenuItem item = (JMenuItem)obj;
            CallBackCommandAction action = (CallBackCommandAction)item.getClientProperty(CLIENT_PROP_ACTION);
            action.setSwitched(isCTRLDown());
            action.performAction(getActivatedNodes(), this);
        }
 */
    }
    
    /**
     * Function that shows off the warning About Default Switches
     * dialog and gives the possibility to cancel the command.
     * @return Should we proceed executing a CVS command
     */
    private boolean showFirstTimerDialog(java.awt.event.ActionEvent e) {
        JPanel panel = new JPanel();
        JLabel label1 = new JLabel();
        JTextArea textArea = new JTextArea();
        textArea.setEditable(false);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        final JCheckBox box = new JCheckBox();
        //final JCheckBox uiMode = new JCheckBox();
        panel.setLayout(new java.awt.GridBagLayout());
        StringBuffer buff = new StringBuffer();
        buff.append(NbBundle.getBundle(CollectingAction.class).getString("CollectingAction.firstTimer1.text")); //NOI18N
        buff.append("\n\n");
        buff.append(NbBundle.getBundle(CollectingAction.class).getString("CollectingAction.firstTimer2.text")); //NOI18N
        //buff.append("\n\n");
        //buff.append(NbBundle.getBundle(CollectingAction.class).getString("CollectingAction.firstTimer3.text")); //NOI18N
        //buff.append("\n\n");
        textArea.setText(buff.toString());
        // hack to get the right bg color..
        textArea.setBackground(label1.getBackground());
        textArea.setRows(11);
        textArea.setColumns(50);
        //textArea.setPreferredSize(new Dimension(250, 200));
        //textArea.setMinimumSize(new Dimension(250, 150));

        GridBagConstraints gridBagConstraints1;
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 0;
        gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;//HORIZONTAL;
        gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 11);
        gridBagConstraints1.weighty = 1.0;
        panel.add(textArea, gridBagConstraints1);        
        
        /*
        Actions.setMenuText(uiMode, NbBundle.getMessage(CollectingAction.class, "CollectingAction.interfaceMode.title"), true); //NOI18N
        uiMode.setSelected(false);
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 3;
        gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 11);
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints1.weightx = 1.0;
        gridBagConstraints1.weighty = 0.0;
        panel.add(uiMode, gridBagConstraints1);
         */
        
        Actions.setMenuText(box, NbBundle.getMessage(CollectingAction.class, "CollectingAction.firstTimerBox"), true); //NOI18N
        box.setSelected(false);
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 4;
        gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 11);
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.SOUTHWEST;
        gridBagConstraints1.weightx = 1.0;
        gridBagConstraints1.weighty = 0.0;
        panel.add(box, gridBagConstraints1);        
        
        String title = NbBundle.getBundle(CollectingAction.class).getString("CollectingAction.firstTimer.title"); //NOI18N
      //  panel.setPreferredSize(new Dimension(400, 200));
        DialogDescriptor dd;
        String commandName = null;
        Object obj = e.getSource();
        if (obj instanceof JMenuItem) {
            JMenuItem item = (JMenuItem)obj;
            ClusterItemVisualizer action = (ClusterItemVisualizer)item.getClientProperty(CLIENT_PROP_ACTION);
            commandName = action.getName();
            commandName = Actions.cutAmpersand(commandName); // No mnemonics on the default button
        }
        if (commandName != null) {
            Object[] options = new Object[] { commandName, NotifyDescriptor.CANCEL_OPTION };
            dd = new DialogDescriptor(panel, title, true, options, commandName,
                                      DialogDescriptor.DEFAULT_ALIGN, null, null);
        } else {
            dd = new DialogDescriptor(panel, title, true,
                                      NotifyDescriptor.OK_CANCEL_OPTION,
                                      NotifyDescriptor.OK_OPTION, null);
        }
        final DialogDescriptor ddFin = dd;
        Object retValue = DialogDisplayer.getDefault().notify(ddFin);
        // Assure, that one of the buttons was pressed. If not, do nothing.
        if (commandName == null && !NotifyDescriptor.OK_OPTION.equals(retValue) ||
            commandName != null && !commandName.equals(retValue)) return false;
        if (box.isSelected()) {
            JavaCvsSettings settings = (JavaCvsSettings)SharedClassObject.findObject(JavaCvsSettings.class, true);
            settings.setFirstTimer(false);
        }
        return true;
    }
  
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.