/*
* 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 java.util.Collection;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JOptionPane;
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.gui.directory.FindOptionPane;
import de.finix.contelligent.client.gui.text.ContelligentEditorKit;
import de.finix.contelligent.client.gui.text.ReplaceDialog;
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 FindNameAction extends AbstractAction implements ContelligentAction {
/**
*
*/
private final ExplorerEditor editor;
public FindNameAction(ExplorerEditor editor) {
super("find_name_action", Resources.findIcon);
this.editor = editor;
putValue(TYPE, PUSH_ACTION);
putValue(ACTION_TYPE, EDIT_ACTION);
putValue(ACTION_GROUP, EDIT_SEARCH_GROUP);
putValue(ACTION_POS, EDIT_SEARCH_NAME);
putValue(MENU_TARGET, MENU);
putValue(BUTTON_TARGET, NO_BUTTON);
putValue(POPUP_TARGET, POPUP_SUBMENU);
putValue(POPUP_PARENT_ACTION, this.editor.findAction);
}
public void actionPerformed(ActionEvent e) {
final TreePath[] selectionPaths = this.editor.tree.getSelectionPaths();
String findPath = null;
if (selectionPaths != null) {
if (selectionPaths.length > 0 && this.editor.guiContainer != null) {
DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0].getLastPathComponent());
if (firstNode != null && firstNode.getUserObject() instanceof ComponentReference) {
try {
ContelligentComponent component = ((ComponentReference) firstNode.getUserObject())
.getComponent();
findPath = component.getPath();
} catch (ComponentNotFoundException cnfe) {
ExceptionDialog.show(cnfe);
}
}
}
}
FindOptionPane findOptionPane = new FindOptionPane();
if (findOptionPane.showFindDialog(this.editor.searchTerm, findPath, true) == JOptionPane.OK_OPTION) {
try {
this.editor.searchTerm = findOptionPane.getSearchText();
if (findOptionPane.searchAll()) {
findPath = "/";
} else {
findPath = findOptionPane.getPath();
}
ActionResult response = Actions.nameFind(this.editor.searchTerm, findPath);
final Collection paths = response.getPaths();
if (this.editor.pathSelectionManager != null) {
this.editor.pathSelectionManager.setPaths(Resources.getLocalString("search_results"), paths,
new Action[0]);
this.editor.pathSelectionManager.showPaths();
}
} catch (RemoteActionException rae) {
ExceptionDialog.show(rae);
}
}
}
private boolean getSearchString(ReplaceDialog replaceDialog) {
if (replaceDialog == null)
return false;
ContelligentEditorKit.setSearchString(replaceDialog.getSearchText());
ContelligentEditorKit.setReplaceString(replaceDialog.getReplaceText());
if (ContelligentEditorKit.getSearchString().length() == 0) {
java.awt.Toolkit.getDefaultToolkit().beep();
return false;
}
return true;
}
}
|