001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.explorer;
019:
020: import java.awt.event.ActionEvent;
021: import java.util.logging.Level;
022: import java.util.logging.Logger;
023:
024: import javax.swing.AbstractAction;
025:
026: import de.finix.contelligent.client.base.TypeFactory;
027: import de.finix.contelligent.client.base.TypeNotFoundException;
028: import de.finix.contelligent.client.gui.ContelligentAction;
029: import de.finix.contelligent.client.i18n.Resources;
030: import de.finix.contelligent.client.util.bookmark.Bookmark;
031:
032: /**
033: * Show a bookmark of a user in menue. For the case, that a user has several bookmarks, this action has a param that
034: * indicates the position of a bookamrk in menue.
035: */
036: public class GoToBookmarkAction extends AbstractAction implements
037: ContelligentAction {
038:
039: static Logger log = Logger.getLogger(GoToBookmarkAction.class
040: .getName());
041:
042: private final Bookmark bookmark;
043:
044: private final ExplorerEditor editor;
045:
046: /**
047: * @param editor
048: * @param menuePosition
049: * @param bookmark
050: * @param menuTarget
051: * @param menuParentAction
052: */
053: public GoToBookmarkAction(ExplorerEditor editor, int menuePosition,
054: Bookmark bookmark, Integer menuTarget,
055: BookmarkFolderAction menuParentAction) {
056:
057: super (bookmark.getName());
058: this .bookmark = bookmark;
059: this .editor = editor;
060:
061: String type = bookmark.getType();
062: try {
063: putValue(SMALL_ICON, TypeFactory.getInstance()
064: .getType(type).getIcon());
065: } catch (TypeNotFoundException e) {
066: putValue(SMALL_ICON, Resources.getIcon("error"));
067:
068: log.log(Level.WARNING, "Could not get icon for type '"
069: + type + "'.");
070: }
071:
072: putValue(TYPE, PUSH_ACTION);
073: putValue(ACTION_TYPE, BOOKMARK_ACTION);
074: putValue(ACTION_GROUP, BOOKMARKS_SHOW_BOOKMARKS_GROUP);
075: putValue(ACTION_POS, new Integer(menuePosition));
076: putValue(BUTTON_TARGET, NO_BUTTON);
077: // to build a hierarchical structure, we need
078: putValue(MENU_TARGET, menuTarget); // menuTarget can be MENU or SUBMENU
079: if (menuTarget.equals(SUBMENU) && menuParentAction != null) {
080: putValue(MENU_PARENT_ACTION, menuParentAction); // the parent BookmarkFolderAction below which this action will appear.
081: }
082: }
083:
084: /* (non-Javadoc)
085: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
086: */
087: public void actionPerformed(ActionEvent e) {
088:
089: String path = bookmark.getComponentPath();
090:
091: // go to selected bookmark.
092: this .editor.tree.clearSelection();
093: this .editor.selectComponent(path);
094: // any editor open?
095: if (!this .editor.getView().isEditInProgress()) {
096: // if no editor is open, open component editor of selected component.
097: this.editor.guiContainer.renderSelectedComponent();
098: }
099: }
100: }
|