MoveDownAction.java :  » Content-Management-System » contelligent » de » finix » contelligent » client » gui » explorer » Java Open Source

Java Open Source » Content Management System » contelligent 
contelligent » de » finix » contelligent » client » gui » explorer » MoveDownAction.java
/*
 * Copyright 2001-2006 C:1 Financial Services GmbH
 *
 * This software is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License Version 2.1, as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
 */

package de.finix.contelligent.client.gui.explorer;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

import de.finix.contelligent.client.base.ComponentNotFoundException;
import de.finix.contelligent.client.base.ComponentReference;
import de.finix.contelligent.client.base.ContelligentComponent;
import de.finix.contelligent.client.gui.ContelligentAction;
import de.finix.contelligent.client.i18n.Resources;
import de.finix.contelligent.client.remote.ActionResult;
import de.finix.contelligent.client.remote.Actions;
import de.finix.contelligent.client.remote.RemoteActionException;
import de.finix.contelligent.client.util.ExceptionDialog;

public class MoveDownAction extends AbstractAction implements ContelligentAction {
    /**
     * 
     */
    private final ExplorerEditor editor;

    public MoveDownAction(ExplorerEditor editor) {
        super("move_down_action", Resources.moveDownIcon);
        this.editor = editor;
        putValue(ROLLOVER_ICON, Resources.moveDownIconRollOver);
        putValue(TYPE, PUSH_ACTION);
        putValue(ACTION_TYPE, EDIT_ACTION);
        putValue(ACTION_GROUP, EDIT_MOVE_GROUP);
        putValue(ACTION_POS, EDIT_MOVE_DOWN);
        putValue(MENU_TARGET, MENU);
        putValue(BUTTON_TARGET, TOOLBAR);
        putValue(POPUP_TARGET, POPUP_SUBMENU);
        putValue(POPUP_PARENT_ACTION, this.editor.moveAction);
    }

    public void actionPerformed(ActionEvent e) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.editor.tree.getLastSelectedPathComponent();
        if (node != null && node.getUserObject() instanceof ComponentReference) {
            try {
                ContelligentComponent component = ((ComponentReference) node.getUserObject()).getComponent();
                ActionResult response = Actions.sort(editor.getView().getEnvironment(), component.getPath(),
                        Actions.DOWN);
                response.showErrors();
            } catch (RemoteActionException rae) {
                ExceptionDialog.show(rae);
            } catch (ComponentNotFoundException cnfe) {
                ExceptionDialog.show(cnfe);
            }
        }
    }

    public void update() {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.editor.tree.getLastSelectedPathComponent();
        if (node != null && node.getUserObject() instanceof ComponentReference) {
            TreePath selectionPath = this.editor.tree.getSelectionPath();
            if (selectionPath != null) {
                DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                if (parent != null) {
                    int index = parent.getIndex(node);
                    int childCount = parent.getChildCount();
                    if (index < childCount - 1) {
                        setEnabled(true);
                        return;
                    }
                }
            }
        }
        setEnabled(false);
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.