Example usage for javax.swing Action actionPerformed

List of usage examples for javax.swing Action actionPerformed

Introduction

In this page you can find the example usage for javax.swing Action actionPerformed.

Prototype

public void actionPerformed(ActionEvent e);

Source Link

Document

Invoked when an action occurs.

Usage

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

/**
 * Setup the JTable with its desired characteristics
 *//*w  ww . ja v a 2  s.  c  o m*/
private void setupTable() {
    table = new CustomTable(spreadsheetModel);
    table.setShowGrid(true);
    table.setGridColor(Color.BLACK);
    table.setShowVerticalLines(true);
    table.setShowHorizontalLines(true);
    table.setGridColor(UIHelper.LIGHT_GREEN_COLOR);
    table.setRowSelectionAllowed(true);
    table.setColumnSelectionAllowed(true);
    table.setAutoCreateColumnsFromModel(false);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.getSelectionModel().addListSelectionListener(this);
    table.getColumnModel().getSelectionModel().addListSelectionListener(this);
    table.getTableHeader().setReorderingAllowed(true);
    table.getColumnModel().addColumnModelListener(this);
    try {
        table.setDefaultRenderer(Class.forName("java.lang.Object"), new SpreadsheetCellRenderer());
    } catch (ClassNotFoundException e) {
        // ignore this error
    }

    table.addMouseListener(this);
    table.getTableHeader().addMouseMotionListener(new MouseMotionListener() {
        public void mouseDragged(MouseEvent event) {
        }

        public void mouseMoved(MouseEvent event) {
            // display a tooltip when user hovers over a column. tooltip is derived
            // from the description of a field from the TableReferenceObject.
            JTable table = ((JTableHeader) event.getSource()).getTable();
            TableColumnModel colModel = table.getColumnModel();
            int colIndex = colModel.getColumnIndexAtX(event.getX());

            // greater than 1 to account for the row no. being the first col
            if (colIndex >= 1) {
                TableColumn tc = colModel.getColumn(colIndex);
                if (tc != null) {
                    try {
                        table.getTableHeader().setToolTipText(getFieldDescription(tc));
                    } catch (Exception e) {
                        // ignore this error
                    }
                }
            }
        }
    });

    //table.getColumnModel().addColumnModelListener(this);
    InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);

    //  Override the default tab behaviour
    //  Tab to the next editable cell. When no editable cells goto next cell.
    final Action previousTabAction = table.getActionMap().get(im.get(tab));
    Action newTabAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            // maintain previous tab action procedure
            previousTabAction.actionPerformed(e);

            JTable table = (JTable) e.getSource();
            int row = table.getSelectedRow();
            int originalRow = row;
            int column = table.getSelectedColumn();
            int originalColumn = column;

            while (!table.isCellEditable(row, column)) {
                previousTabAction.actionPerformed(e);
                row = table.getSelectedRow();
                column = table.getSelectedColumn();

                //  Back to where we started, get out.
                if ((row == originalRow) && (column == originalColumn)) {
                    break;
                }
            }

            if (table.editCellAt(row, column)) {
                table.getEditorComponent().requestFocusInWindow();
            }
        }
    };

    table.getActionMap().put(im.get(tab), newTabAction);
    TableColumnModel model = table.getColumnModel();

    String previousColumnName = null;
    for (int columnIndex = 0; columnIndex < tableReferenceObject.getHeaders().size(); columnIndex++) {
        if (!model.getColumn(columnIndex).getHeaderValue().toString()
                .equals(TableReferenceObject.ROW_NO_TEXT)) {
            model.getColumn(columnIndex).setHeaderRenderer(columnRenderer);
            model.getColumn(columnIndex).setPreferredWidth(spreadsheetFunctions
                    .calcColWidths(model.getColumn(columnIndex).getHeaderValue().toString()));
            // add appropriate cell editor for cell.
            spreadsheetFunctions.addCellEditor(model.getColumn(columnIndex), previousColumnName);
            previousColumnName = model.getColumn(columnIndex).getHeaderValue().toString();
        } else {
            model.getColumn(columnIndex).setHeaderRenderer(new RowNumberCellRenderer());
        }
    }

    JTableHeader header = table.getTableHeader();
    header.setBackground(UIHelper.BG_COLOR);
    header.addMouseListener(new HeaderListener(header, columnRenderer));

    table.addNotify();
}

From source file:org.nuclos.client.common.NuclosCollectController.java

/**
 * @todo this method is misused - it sets shortcuts for many things other than tabs...
 * @param frame// www .j  a va 2 s .co  m
 */
@Override
protected void setupShortcutsForTabs(MainFrameTab frame) {
    final CollectPanel<Clct> pnlCollect = this.getCollectPanel();
    final DetailsPanel pnlDetails = this.getDetailsPanel();

    final Action actSelectSearchTab = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            if (pnlCollect.isTabbedPaneEnabledAt(CollectPanel.TAB_SEARCH)) {
                pnlCollect.setTabbedPaneSelectedComponent(getSearchPanel());
            }
        }
    };
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.ACTIVATE_SEARCH_PANEL_1, actSelectSearchTab,
            pnlCollect);
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.ACTIVATE_SEARCH_PANEL_2, actSelectSearchTab,
            pnlCollect);

    //TODO This is a workaround. The detailpanel should keep the focus
    final Action actGrabFocus = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            pnlDetails.grabFocus();
        }
    };

    /**
     * A <code>ChainedAction</code> is an action composed of a primary and a secondary action.
     * It behaves exactly like the primary action, except that additionally, the secondary action is performed
     * after the primary action.
     */
    class ChainedAction implements Action {
        private final Action actPrimary;
        private final Action actSecondary;

        public ChainedAction(Action actPrimary, Action actSecondary) {
            this.actPrimary = actPrimary;
            this.actSecondary = actSecondary;
        }

        @Override
        public void addPropertyChangeListener(PropertyChangeListener listener) {
            actPrimary.addPropertyChangeListener(listener);
        }

        @Override
        public Object getValue(String sKey) {
            return actPrimary.getValue(sKey);
        }

        @Override
        public boolean isEnabled() {
            return actPrimary.isEnabled();
        }

        @Override
        public void putValue(String sKey, Object oValue) {
            actPrimary.putValue(sKey, oValue);
        }

        @Override
        public void removePropertyChangeListener(PropertyChangeListener listener) {
            actPrimary.removePropertyChangeListener(listener);
        }

        @Override
        public void setEnabled(boolean bEnabled) {
            actPrimary.setEnabled(bEnabled);
        }

        @Override
        public void actionPerformed(ActionEvent ev) {
            actPrimary.actionPerformed(ev);
            actSecondary.actionPerformed(ev);
        }
    }

    //final Action actRefresh = new ChainedAction(this.getRefreshCurrentCollectableAction(), actGrabFocus);

    this.getCollectPanel().setTabbedPaneToolTipTextAt(CollectPanel.TAB_SEARCH,
            getSpringLocaleDelegate().getMessage("NuclosCollectController.13", "Suche (F7) (Strg+F)"));
    this.getCollectPanel().setTabbedPaneToolTipTextAt(CollectPanel.TAB_RESULT,
            getSpringLocaleDelegate().getMessage("NuclosCollectController.7", "Ergebnis (F8)"));
    this.getCollectPanel().setTabbedPaneToolTipTextAt(CollectPanel.TAB_DETAILS,
            getSpringLocaleDelegate().getMessage("NuclosCollectController.3", "Details (F2)"));

    // the search action
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.START_SEARCH, this.getSearchAction(),
            pnlCollect);
    KeyBinding keybinding = KeyBindingProvider.REFRESH;

    // the refresh action
    KeyBindingProvider.removeActionFromComponent(keybinding, pnlDetails);
    pnlDetails.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keybinding.getKeystroke(),
            keybinding.getKey());
    pnlDetails.getActionMap().put(keybinding.getKey(), this.getRefreshCurrentCollectableAction());
    KeyBindingProvider.removeActionFromComponent(keybinding, getResultPanel());
    getResultPanel().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keybinding.getKeystroke(),
            keybinding.getKey());
    getResultPanel().getActionMap().put(keybinding.getKey(), getResultPanel().btnRefresh.getAction());

    // the new action
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEW, this.getNewAction(), pnlDetails);

    // the new with search values action
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEW_SEARCHVALUE,
            this.getNewWithSearchValuesAction(), pnlCollect);

    // the save action
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SAVE_1, this.getSaveAction(), pnlCollect);
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SAVE_2, this.getSaveAction(), pnlCollect);

    // first the navigation actions are performed and then the focus is grabbed:
    final Action actFirst = new ChainedAction(this.getFirstAction(), actGrabFocus);
    final Action actLast = new ChainedAction(this.getLastAction(), actGrabFocus);
    final Action actPrevious = new ChainedAction(this.getPreviousAction(), actGrabFocus);
    final Action actNext = new ChainedAction(this.getNextAction(), actGrabFocus);

    // the first action
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.FIRST, actFirst, pnlDetails);
    pnlDetails.btnFirst.setAction(actFirst);

    // the last action
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.LAST, actLast, pnlDetails);
    pnlDetails.btnLast.setAction(actLast);

    // the previous action
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.PREVIOUS_1, actPrevious, pnlDetails);
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.PREVIOUS_2, actPrevious, pnlDetails);
    pnlDetails.btnPrevious.setAction(actPrevious);

    // the next action
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEXT_1, actNext, pnlDetails);
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEXT_2, actNext, pnlDetails);
    pnlDetails.btnNext.setAction(actNext);

    Action actClose = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            getTab().dispose();
        }
    };
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.CLOSE_CHILD, actClose, pnlCollect);

    if (getResultPanel() != null && getResultTable() != null) {
        final JButton btnEdit = getResultPanel().btnEdit;
        KeyBindingProvider.bindActionToComponent(KeyBindingProvider.EDIT_1, btnEdit.getAction(),
                getResultTable());
        if (getResultTable().getActionMap().get(KeyBindingProvider.EDIT_2.getKey()) == null)
            KeyBindingProvider.bindActionToComponent(KeyBindingProvider.EDIT_2, btnEdit.getAction(),
                    getResultTable());
    }
}

From source file:org.nuclos.client.ui.collect.searcheditor.SearchEditorController.java

/**
 * event: a mouse event occured on a node in the <code>view</code>
 * @param selPath the path of the node where the mouse event occured.
 * @param ev//w w  w . j  a  va2 s. c om
 */
private void mouseEventOnNode(TreePath selPath, MouseEvent ev) {
    final SearchConditionTreeNode node = (SearchConditionTreeNode) selPath.getLastPathComponent();
    final JTree tree = (JTree) ev.getComponent();

    // select the node:
    tree.setSelectionPath(selPath);

    if (ev.isPopupTrigger()) {
        // show popup menu:
        final JPopupMenu popupMenu = this.getPopupMenu(node, tree);
        if (popupMenu != null) {
            popupMenu.show(ev.getComponent(), ev.getX(), ev.getY());
        }
    } else if (ev.getID() == MouseEvent.MOUSE_CLICKED) {
        if (ev.getButton() == MouseEvent.BUTTON1) {
            if (ev.getClickCount() == 2) {
                if (this.clctfproviderfactory == null) {
                    throw new IllegalStateException(
                            "No CollectableFieldsProviderFactory was defined for the search editor.");
                }
                // perform the node's default action:
                final Action actDefault = node.getDefaultTreeNodeAction(tree, this.clcteRoot,
                        this.clctfproviderfactory, this.additionalFields);
                if (actDefault != null) {
                    actDefault.actionPerformed(null);
                }
            }
        }
    }
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterControl.java

/**
 * Handles a PropertyChangedEvent/*from   w w w.  ja  va2 s  .  c  om*/
 * @param evt The event
 */
private void handlePropertyChangedEvent(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (ImportDialog.IMPORT_PROPERTY.equals(name)) {
        actionsMap.get(CANCEL_BUTTON).setEnabled(true);
        model.importData((ImportableObject) evt.getNewValue());
    } else if (ImportDialog.LOAD_TAGS_PROPERTY.equals(name)) {
        model.loadExistingTags();
    } else if (ImportDialog.CANCEL_SELECTION_PROPERTY.equals(name)) {
        model.close();
    } else if (ClosableTabbedPane.CLOSE_TAB_PROPERTY.equals(name)) {
        model.removeImportElement(evt.getNewValue());
    } else if (FileImportComponent.SUBMIT_ERROR_PROPERTY.equals(name)) {
        submitFiles((FileImportComponent) evt.getNewValue());
    } else if (ImportDialog.REFRESH_LOCATION_PROPERTY.equals(name)) {
        model.refreshContainers((ImportLocationDetails) evt.getNewValue());
    } else if (ImportDialog.CREATE_OBJECT_PROPERTY.equals(name)) {
        ObjectToCreate l = (ObjectToCreate) evt.getNewValue();
        model.createDataObject(l);
    } else if (StatusLabel.DEBUG_TEXT_PROPERTY.equals(name)) {
        view.appendDebugText((String) evt.getNewValue());
    } else if (MacOSMenuHandler.QUIT_APPLICATION_PROPERTY.equals(name)) {
        Action a = getAction(EXIT);
        ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "");
        a.actionPerformed(event);
    } else if (ImportDialog.PROPERTY_GROUP_CHANGED.equals(name)) {
        GroupData newGroup = (GroupData) evt.getNewValue();
        model.setUserGroup(newGroup);
    } else if (StatusLabel.FILE_IMPORT_STARTED_PROPERTY.equals(name)
            || FileImportComponent.CANCEL_IMPORT_PROPERTY.equals(name)) {
        checkDisableCancelAllButtons();
    } else if (StatusLabel.IMPORT_DONE_PROPERTY.equals(name)) {
        model.onImportComplete((FileImportComponent) evt.getNewValue());
    } else if (StatusLabel.UPLOAD_DONE_PROPERTY.equals(name)) {
        model.onUploadComplete((FileImportComponent) evt.getNewValue());
    }
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewerControl.java

/**
 * Reacts to property changed. /*from   w ww .  j  a v  a 2s .  com*/
 * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
 */
public void propertyChange(PropertyChangeEvent pce) {
    String name = pce.getPropertyName();
    if (name == null)
        return;
    if (TreeViewer.CANCEL_LOADING_PROPERTY.equals(name)) {
        Browser browser = model.getSelectedBrowser();
        if (browser != null)
            browser.cancel();
    } else if (Browser.POPUP_MENU_PROPERTY.equals(name)) {
        Integer c = (Integer) pce.getNewValue();
        Browser browser = model.getSelectedBrowser();
        if (browser != null)
            view.showPopup(c.intValue(), browser.getClickComponent(), browser.getClickPoint());
    } else if (Browser.CLOSE_PROPERTY.equals(name)) {
        Browser browser = (Browser) pce.getNewValue();
        if (browser != null)
            view.removeBrowser(browser);
    } else if (TreeViewer.FINDER_VISIBLE_PROPERTY.equals(name)) {
        Boolean b = (Boolean) pce.getNewValue();
        if (!b.booleanValue()) {
            model.clearFoundResults();
            model.onComponentStateChange(true);
        }
    } else if (TreeViewer.SELECTED_BROWSER_PROPERTY.equals(name)) {
        Browser b = model.getSelectedBrowser();
        Iterator i = model.getBrowsers().values().iterator();
        Browser browser;
        while (i.hasNext()) {
            browser = (Browser) i.next();
            browser.setSelected(browser.equals(b));
        }
    } else if (Browser.SELECTED_TREE_NODE_DISPLAY_PROPERTY.equals(name)) {
        model.onSelectedDisplay();
        view.updateMenuItems();
    } else if (TreeViewer.HIERARCHY_ROOT_PROPERTY.equals(name)) {
        /*
         Map browsers = model.getBrowsers();
         Iterator i = browsers.values().iterator();
         Browser browser;
         while (i.hasNext()) {
            browser = (Browser) i.next();
            //browser.cleanFilteredNodes();
            //browser.switchUser();
         }
         */
    } else if (AddExistingObjectsDialog.EXISTING_ADD_PROPERTY.equals(name)) {
        model.addExistingObjects((Set) pce.getNewValue());
    } else if (UserManagerDialog.USER_SWITCH_PROPERTY.equals(name)) {
        Map m = (Map) pce.getNewValue();
        Iterator i = m.entrySet().iterator();
        Long groupID;
        List<ExperimenterData> users;
        Entry entry;
        while (i.hasNext()) {
            entry = (Entry) i.next();
            groupID = (Long) entry.getKey();
            users = (List<ExperimenterData>) entry.getValue();
            model.setHierarchyRoot(groupID, users);
        }
    } else if (UserManagerDialog.NO_USER_SWITCH_PROPERTY.equals(name)) {
        UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
        un.notifyInfo("User Selection", "Please select a user first.");
    } else if (EditorDialog.CREATE_PROPERTY.equals(name)) {
        DataObject data = (DataObject) pce.getNewValue();
        model.createObject(data, true);
    } else if (EditorDialog.CREATE_NO_PARENT_PROPERTY.equals(name)) {
        DataObject data = (DataObject) pce.getNewValue();
        model.createObject(data, false);
    } else if (MetadataViewer.ON_DATA_SAVE_PROPERTY.equals(name)) {
        Object object = pce.getNewValue();
        if (object != null) {
            if (object instanceof DataObject)
                model.onDataObjectSave((DataObject) object, TreeViewer.UPDATE_OBJECT);
            else
                model.onDataObjectSave((List) object, TreeViewer.UPDATE_OBJECT);
        }
    } else if (DataBrowser.SELECTED_NODE_DISPLAY_PROPERTY.equals(name)) {
        model.setSelectedNode(pce.getNewValue());
    } else if (DataBrowser.UNSELECTED_NODE_DISPLAY_PROPERTY.equals(name)) {
        model.setUnselectedNode(pce.getNewValue());
    } else if (DataBrowser.DATA_OBJECT_CREATED_PROPERTY.equals(name)) {
        Map map = (Map) pce.getNewValue();
        if (map != null && map.size() == 1) {
            DataObject data = null;
            Set set = map.entrySet();
            Entry entry;
            Iterator i = set.iterator();
            Object o;
            DataObject parent = null;
            while (i.hasNext()) {
                entry = (Entry) i.next();
                data = (DataObject) entry.getKey();
                o = entry.getValue();
                if (o != null)
                    parent = (DataObject) o;
                break;
            }
            if (parent == null)
                model.onOrphanDataObjectCreated(data);
            else
                model.onDataObjectSave(data, parent, TreeViewer.CREATE_OBJECT);
        }
    } else if (DataBrowser.ADDED_TO_DATA_OBJECT_PROPERTY.equals(name)) {
        //Browser browser =  model.getSelectedBrowser();
        //if (browser != null) browser.refreshLoggedExperimenterData();
        model.refreshTree();
    } else if (DataBrowser.COPY_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        if (data != null)
            model.copyRndSettings((ImageData) data);
        else
            model.copyRndSettings(null);
    } else if (DataBrowser.PASTE_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.PASTE, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.PASTE);
        cmd.execute();
    } else if (DataBrowser.RESET_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.RESET, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.RESET);
        cmd.execute();
    } else if (DataBrowser.SET__ORIGINAL_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_MIN_MAX, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_MIN_MAX);
        cmd.execute();
    } else if (DataBrowser.SET__ORIGINAL_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_OWNER, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_OWNER);
        cmd.execute();
    } else if (DataBrowser.CUT_ITEMS_PROPERTY.equals(name)) {
        CutCmd cmd = new CutCmd(model);
        cmd.execute();
    } else if (DataBrowser.COPY_ITEMS_PROPERTY.equals(name)) {
        CopyCmd cmd = new CopyCmd(model);
        cmd.execute();
    } else if (DataBrowser.PASTE_ITEMS_PROPERTY.equals(name)) {
        PasteCmd cmd = new PasteCmd(model);
        cmd.execute();
    } else if (DataBrowser.REMOVE_ITEMS_PROPERTY.equals(name)) {
        DeleteCmd cmd = new DeleteCmd(model.getSelectedBrowser());
        cmd.execute();
    } else if (DataBrowser.VIEW_IMAGE_NODE_PROPERTY.equals(name)) {
        //view.get
        Browser browser = model.getSelectedBrowser();
        if (browser != null) {
            TreeImageDisplay node = browser.getLastSelectedDisplay();
            model.browse(node, (DataObject) pce.getNewValue(), false);
        }
    } else if (DataBrowser.INTERNAL_VIEW_NODE_PROPERTY.equals(name)) {
        ViewCmd cmd = new ViewCmd(model, true);
        cmd.execute();
    } else if (Finder.RESULTS_FOUND_PROPERTY.equals(name)) {
        model.setSearchResult(pce.getNewValue());
    } else if (GenericDialog.SAVE_GENERIC_PROPERTY.equals(name)) {
        Object parent = pce.getNewValue();
        if (parent instanceof MetadataViewer) {
            MetadataViewer mv = (MetadataViewer) parent;
            mv.saveData();
        }
    } else if (Browser.DATA_REFRESHED_PROPERTY.equals(name)) {
        model.onSelectedDisplay();
    } else if (MetadataViewer.ADMIN_UPDATED_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        Map browsers = model.getBrowsers();
        Set set = browsers.entrySet();
        Entry entry;
        Iterator i = set.iterator();
        Browser browser;
        while (i.hasNext()) {
            entry = (Entry) i.next();
            browser = (Browser) entry.getValue();
            browser.refreshAdmin(data);
        }
        view.createTitle();
    } else if (DataBrowser.TAG_WIZARD_PROPERTY.equals(name)) {
        model.showTagWizard();
    } else if (DataBrowser.FIELD_SELECTED_PROPERTY.equals(name)) {
        model.setSelectedField(pce.getNewValue());
    } else if (MetadataViewer.RENDER_THUMBNAIL_PROPERTY.equals(name)) {
        long imageID = ((Long) pce.getNewValue()).longValue();
        List<Long> ids = new ArrayList<Long>(1);
        ids.add(imageID);
        view.reloadThumbnails(ids);
    } else if (MetadataViewer.APPLY_SETTINGS_PROPERTY.equals(name)) {
        Object object = pce.getNewValue();
        if (object instanceof ImageData) {
            ImageData img = (ImageData) object;
            model.copyRndSettings((ImageData) object);
            List<Long> ids = new ArrayList<Long>(1);
            ids.add(img.getId());
            view.reloadThumbnails(ids);

            //improve code to speed it up
            List l = model.getSelectedBrowser().getSelectedDataObjects();
            Collection toUpdate;
            if (l.size() > 1)
                toUpdate = l;
            else
                toUpdate = model.getDisplayedImages();
            if (toUpdate != null) {
                PasteRndSettingsCmd cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.PASTE, toUpdate);
                cmd.execute();
            }
        } else if (object instanceof Object[]) {
            Object[] objects = (Object[]) object;
            WellSampleData wsd = (WellSampleData) objects[0];
            WellData well = (WellData) objects[1];
            ImageData img = wsd.getImage();
            model.copyRndSettings(img);
            List<Long> ids = new ArrayList<Long>(1);
            ids.add(img.getId());
            view.reloadThumbnails(ids);
            ids = new ArrayList<Long>(1);
            ids.add(well.getPlate().getId());
            model.pasteRndSettings(ids, PlateData.class);
        }
    } else if (JXTaskPaneContainerSingle.SELECTED_TASKPANE_PROPERTY.equals(name)) {
        handleTaskPaneSelection((JXTaskPane) pce.getNewValue());
    } else if (MetadataViewer.GENERATE_FIGURE_PROPERTY.equals(name)) {
        Object object = pce.getNewValue();
        if (!(object instanceof FigureParam))
            return;
        UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
        IconManager icons = IconManager.getInstance();
        Icon icon = icons.getIcon(IconManager.SPLIT_VIEW_FIGURE_22);
        FigureActivityParam activity;
        List<Long> ids = new ArrayList<Long>();
        Iterator i;
        DataObject obj;
        FigureParam param = (FigureParam) object;
        Collection l;
        if (param.isSelectedObjects()) {
            Browser b = model.getSelectedBrowser();
            if (b != null)
                l = b.getSelectedDataObjects();
            else {
                l = new ArrayList<DataObject>();
                Collection<DataObject> nodes = model.getSelectedObjectsFromBrowser();
                if (nodes != null) {
                    l.addAll(nodes);
                }
            }
        } else {
            l = model.getDisplayedImages();
        }
        if (CollectionUtils.isEmpty(l))
            return;
        Class klass = null;
        Object p = null;
        if (param.getIndex() == FigureParam.THUMBNAILS) {
            Browser browser = model.getSelectedBrowser();
            if (browser != null) {
                TreeImageDisplay[] nodes = browser.getSelectedDisplays();
                if (nodes != null && nodes.length > 0) {
                    TreeImageDisplay node = nodes[0];
                    Object ho = node.getUserObject();
                    TreeImageDisplay pNode;
                    if (ho instanceof DatasetData) {
                        klass = ho.getClass();
                        p = ho;
                    } else if (ho instanceof ImageData) {
                        klass = ho.getClass();
                        pNode = node.getParentDisplay();
                        if (pNode != null) {
                            p = pNode.getUserObject();
                            if (!(p instanceof DatasetData))
                                p = null;
                        }
                        if (p == null)
                            p = ho;
                    }
                    if (p != null)
                        param.setAnchor((DataObject) p);
                }
            }
        }

        i = l.iterator();
        int n = 0;
        List<Long> groupIds = new ArrayList<Long>();
        boolean canRun = true;
        while (i.hasNext()) {
            obj = (DataObject) i.next();
            if (groupIds.size() == 0)
                groupIds.add(obj.getGroupId());
            if (groupIds.contains(obj.getGroupId())) {
                ids.add(obj.getId());
                if (n == 0)
                    p = obj;
                n++;
            } else {
                canRun = false;
                break;
            }
        }
        if (!canRun) {
            un.notifyInfo("Script", "You can run the script only\non " + "objects from the same group");
            return;
        }
        if (ids.size() == 0)
            return;
        // not set
        if (param.getIndex() != FigureParam.THUMBNAILS)
            param.setAnchor((DataObject) p);

        activity = new FigureActivityParam(object, ids, klass, FigureActivityParam.SPLIT_VIEW_FIGURE);
        activity.setIcon(icon);
        un.notifyActivity(new SecurityContext(groupIds.get(0)), activity);
    } else if (MetadataViewer.HANDLE_SCRIPT_PROPERTY.equals(name)) {
        UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
        ScriptActivityParam p = (ScriptActivityParam) pce.getNewValue();
        int index = p.getIndex();
        ScriptObject script = p.getScript();
        if (index == ScriptActivityParam.VIEW) {
            Environment env = (Environment) TreeViewerAgent.getRegistry().lookup(LookupNames.ENV);
            String path = env.getOmeroFilesHome();
            path += File.separator + script.getName();
            File f = new File(path);
            DownloadAndLaunchActivityParam activity = new DownloadAndLaunchActivityParam(
                    p.getScript().getScriptID(), DownloadAndLaunchActivityParam.ORIGINAL_FILE, f, null);

            un.notifyActivity(model.getSecurityContext(), activity);
        } else if (index == ScriptActivityParam.DOWNLOAD) {
            downloadScript(p);
        }
    } else if (OpenWithDialog.OPEN_DOCUMENT_PROPERTY.equals(name)) {
        ApplicationData data = (ApplicationData) pce.getNewValue();
        //Register 
        if (data == null)
            return;
        String format = view.getObjectMimeType();
        //if (format == null) return;
        if (format != null)
            TreeViewerFactory.register(data, format);
        model.openWith(data);
    } else if (DataBrowser.OPEN_EXTERNAL_APPLICATION_PROPERTY.equals(name)) {
        model.openWith((ApplicationData) pce.getNewValue());
    } else if (AdminDialog.CREATE_ADMIN_PROPERTY.equals(name)) {
        AdminObject object = (AdminObject) pce.getNewValue();
        model.administrate(object);
    } else if (MetadataViewer.REGISTER_PROPERTY.equals(name)) {
        model.register((DataObjectRegistration) pce.getNewValue());
    } else if (MetadataViewer.RESET_PASSWORD_PROPERTY.equals(name)) {
        model.resetPassword((String) pce.getNewValue());
    } else if (MetadataViewer.UPLOAD_SCRIPT_PROPERTY.equals(name)) {
        TreeViewerAction action = getAction(UPLOAD_SCRIPT);
        action.actionPerformed(new ActionEvent(this, 1, ""));
    } else if (SelectionWizard.SELECTED_ITEMS_PROPERTY.equals(name)) {
        Map m = (Map) pce.getNewValue();
        if (m == null || m.size() != 1)
            return;
        Entry entry;
        Iterator i = m.entrySet().iterator();
        Class klass;
        TreeImageDisplay node;
        Collection<ExperimenterData> list;
        Object uo;
        AdminObject object;
        while (i.hasNext()) {
            entry = (Entry) i.next();
            klass = (Class) entry.getKey();
            if (ExperimenterData.class.equals(klass)) {
                list = (Collection<ExperimenterData>) entry.getValue();
                node = model.getSelectedBrowser().getLastSelectedDisplay();
                if (node != null) {
                    uo = node.getUserObject();
                    if (uo instanceof GroupData) {
                        object = new AdminObject((GroupData) uo, list);
                        model.administrate(object);
                    }
                }
            }
        }
    } else if (DataBrowser.SET__OWNER_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_OWNER, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_OWNER);
        cmd.execute();
    } else if (ScriptingDialog.RUN_SELECTED_SCRIPT_PROPERTY.equals(name)) {
        handleScript((ScriptObject) pce.getNewValue(), ScriptActivityParam.RUN);
    } else if (ScriptingDialog.DOWNLOAD_SELECTED_SCRIPT_PROPERTY.equals(name)) {
        Object value = pce.getNewValue();
        if (value instanceof ScriptObject)
            handleScript((ScriptObject) value, ScriptActivityParam.DOWNLOAD);
        else if (value instanceof String) {
            ScriptObject script = view.getScriptFromName((String) value);
            if (script != null)
                handleScript(script, ScriptActivityParam.DOWNLOAD);
        }
    } else if (ScriptingDialog.VIEW_SELECTED_SCRIPT_PROPERTY.equals(name)) {
        Object value = pce.getNewValue();
        if (value instanceof ScriptObject)
            handleScript((ScriptObject) value, ScriptActivityParam.VIEW);
        else if (value instanceof String) {
            ScriptObject script = view.getScriptFromName((String) value);
            if (script != null)
                handleScript(script, ScriptActivityParam.VIEW);
        }
    } else if (TreeViewer.SCRIPTS_LOADING_PROPERTY.equals(name)) {
        view.setScriptsLoadingStatus(true);
    } else if (TreeViewer.SCRIPTS_LOADED_PROPERTY.equals(name)) {
        view.setScriptsLoadingStatus(false);
    } else if (DataBrowser.SELECTED_DATA_BROWSER_NODES_DISPLAY_PROPERTY.equals(name)) {
        model.setSelectedNodes(pce.getNewValue());
    } else if (TreeViewer.GROUP_CHANGED_PROPERTY.equals(name)) {
        view.setPermissions();
    } else if (MacOSMenuHandler.QUIT_APPLICATION_PROPERTY.equals(name)) {
        Action a = getAction(EXIT);
        ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "");
        a.actionPerformed(event);
    } else if (GroupManagerDialog.GROUP_SWITCH_PROPERTY.equals(name)) {
        List<GroupData> groups = (List<GroupData>) pce.getNewValue();
        if (groups.size() == 0) {
            UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
            un.notifyInfo(GroupManagerDialog.TITLE, "At least one group " + "must be selected.");
            return;
        }
        model.setUserGroup(groups);
    } else if (DataBrowser.ACTIVATE_USER_PROPERTY.equals(name)) {
        ExperimenterData exp = (ExperimenterData) pce.getNewValue();
        if (exp != null)
            model.activateUser(exp);
    } else if (DataBrowser.RESET_PASSWORD_PROPERTY.equals(name)) {
        getAction(RESET_PASSWORD).actionPerformed(new ActionEvent(pce.getNewValue(), 0, "Reset Password"));
    }
}

From source file:org.wings.SComponent.java

/**
 * Internal method to trigger firing of key events.
 *//*from  w w w . ja  v  a2  s  . c  o m*/
protected void fireKeyEvents() {
    if (actionEvents != null) {
        for (Map.Entry<Action, ActionEvent> entry : actionEvents.entrySet()) {
            Action action = entry.getKey();
            ActionEvent event = entry.getValue();
            action.actionPerformed(event);
        }
        actionEvents.clear();
    }
}

From source file:plugin.notes.gui.NotesView.java

/**
 *  Performs an action of a particular name on the man editor.
 *
 *@param  name  name of the action to perform.
 *@param  evt   ActionEvent that sparked the calling of this function.
 *///from   www.java2s  . c o m
private void performTextPaneAction(String name, java.awt.event.ActionEvent evt) {
    Action action = getActionByName(editor, name);
    action.actionPerformed(evt);
    editor.grabFocus();

    int cp = editor.getCaretPosition();
    updateButtons(editor, cp);
}

From source file:plugin.notes.gui.NotesView.java

private void leftJustifyButtonActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_leftJustifyButtonActionPerformed
    Action action = new StyledEditorKit.AlignmentAction("Left Justify", StyleConstants.ALIGN_LEFT);
    action.actionPerformed(evt);
    editor.grabFocus();/*  w w  w  . j av  a  2 s  .c o  m*/

    int cp = editor.getCaretPosition();
    updateButtons(editor, cp);
}

From source file:plugin.notes.gui.NotesView.java

private void rightJustifyButtonActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_rightJustifyButtonActionPerformed
    Action action = new StyledEditorKit.AlignmentAction("Right Justify", StyleConstants.ALIGN_RIGHT);
    action.actionPerformed(evt);
    editor.grabFocus();/*  w  w  w. j  a  v  a  2  s .  c om*/

    int cp = editor.getCaretPosition();
    updateButtons(editor, cp);
}

From source file:processing.app.Editor.java

void handleCommentUncomment() {

    Action action = textarea.getActionMap().get(RSyntaxTextAreaEditorKit.rstaToggleCommentAction);
    action.actionPerformed(null);

}