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.Collection;
022:
023: import javax.swing.AbstractAction;
024: import javax.swing.Action;
025: import javax.swing.JOptionPane;
026: import javax.swing.tree.DefaultMutableTreeNode;
027: import javax.swing.tree.TreePath;
028:
029: import de.finix.contelligent.client.base.ComponentNotFoundException;
030: import de.finix.contelligent.client.base.ComponentReference;
031: import de.finix.contelligent.client.base.ContelligentComponent;
032: import de.finix.contelligent.client.gui.ContelligentAction;
033: import de.finix.contelligent.client.gui.directory.FindOptionPane;
034: import de.finix.contelligent.client.gui.text.ContelligentEditorKit;
035: import de.finix.contelligent.client.gui.text.ReplaceDialog;
036: import de.finix.contelligent.client.i18n.Resources;
037: import de.finix.contelligent.client.remote.ActionResult;
038: import de.finix.contelligent.client.remote.Actions;
039: import de.finix.contelligent.client.remote.RemoteActionException;
040: import de.finix.contelligent.client.util.ExceptionDialog;
041:
042: public class FindNameAction extends AbstractAction implements
043: ContelligentAction {
044: /**
045: *
046: */
047: private final ExplorerEditor editor;
048:
049: public FindNameAction(ExplorerEditor editor) {
050: super ("find_name_action", Resources.findIcon);
051: this .editor = editor;
052: putValue(TYPE, PUSH_ACTION);
053: putValue(ACTION_TYPE, EDIT_ACTION);
054: putValue(ACTION_GROUP, EDIT_SEARCH_GROUP);
055: putValue(ACTION_POS, EDIT_SEARCH_NAME);
056: putValue(MENU_TARGET, MENU);
057: putValue(BUTTON_TARGET, NO_BUTTON);
058: putValue(POPUP_TARGET, POPUP_SUBMENU);
059: putValue(POPUP_PARENT_ACTION, this .editor.findAction);
060: }
061:
062: public void actionPerformed(ActionEvent e) {
063: final TreePath[] selectionPaths = this .editor.tree
064: .getSelectionPaths();
065: String findPath = null;
066: if (selectionPaths != null) {
067: if (selectionPaths.length > 0
068: && this .editor.guiContainer != null) {
069: DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0]
070: .getLastPathComponent());
071: if (firstNode != null
072: && firstNode.getUserObject() instanceof ComponentReference) {
073: try {
074: ContelligentComponent component = ((ComponentReference) firstNode
075: .getUserObject()).getComponent();
076: findPath = component.getPath();
077: } catch (ComponentNotFoundException cnfe) {
078: ExceptionDialog.show(cnfe);
079: }
080: }
081: }
082: }
083: FindOptionPane findOptionPane = new FindOptionPane();
084: if (findOptionPane.showFindDialog(this .editor.searchTerm,
085: findPath, true) == JOptionPane.OK_OPTION) {
086: try {
087: this .editor.searchTerm = findOptionPane.getSearchText();
088: if (findOptionPane.searchAll()) {
089: findPath = "/";
090: } else {
091: findPath = findOptionPane.getPath();
092: }
093: ActionResult response = Actions.nameFind(
094: this .editor.searchTerm, findPath);
095: final Collection paths = response.getPaths();
096: if (this .editor.pathSelectionManager != null) {
097: this .editor.pathSelectionManager.setPaths(Resources
098: .getLocalString("search_results"), paths,
099: new Action[0]);
100: this .editor.pathSelectionManager.showPaths();
101: }
102: } catch (RemoteActionException rae) {
103: ExceptionDialog.show(rae);
104: }
105: }
106: }
107:
108: private boolean getSearchString(ReplaceDialog replaceDialog) {
109: if (replaceDialog == null)
110: return false;
111: ContelligentEditorKit.setSearchString(replaceDialog
112: .getSearchText());
113: ContelligentEditorKit.setReplaceString(replaceDialog
114: .getReplaceText());
115: if (ContelligentEditorKit.getSearchString().length() == 0) {
116: java.awt.Toolkit.getDefaultToolkit().beep();
117: return false;
118: }
119: return true;
120: }
121: }
|