1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 15:45:25 +02:00

[141804] Remote Search is not properly disabled for subsystems that do not support it. The select dialog when browsing for folders is now restricted only to systems that have a subsystem that supports search.

This commit is contained in:
Kushal Munir 2006-12-05 02:56:12 +00:00
parent f9210cdc57
commit 8e54965e02
5 changed files with 668 additions and 2 deletions

View file

@ -0,0 +1,465 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.files.ui.internal.search;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.files.ui.ISystemAddFileListener;
import org.eclipse.rse.files.ui.actions.SystemSelectRemoteFolderAction;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.ui.validators.IValidatorRemoteSelection;
import org.eclipse.swt.widgets.Shell;
/**
* This action brings up a select dialog for search.
*/
public class SystemSearchRemoteFolderAction extends SystemSelectRemoteFolderAction {
private String[] systemTypes;
private IHost systemConnection, outputConnection;
private IHost rootFolderConnection;
private IRemoteFile preSelection;
private String rootFolderAbsPath;
private String message, treeTip, dlgTitle;
private String addLabel, addToolTipText;
private int expandDepth = 0;
private boolean showNewConnectionPrompt = true;
private boolean restrictFolders = false;
private boolean showPropertySheet = false;
private boolean showPropertySheetDetailsButtonInitialState;
private boolean showPropertySheetDetailsButton = false;
private boolean multipleSelectionMode = false;
private boolean allowForMultipleParents = false;
private boolean onlyConnection = false;
private ISystemAddFileListener addButtonCallback = null;
private IValidatorRemoteSelection selectionValidator;
/**
* Constructor.
* @param shell the parent shell.
*/
public SystemSearchRemoteFolderAction(Shell shell) {
super(shell);
}
/**
* Constructor.
* @param shell the parent shell.
* @param label the label to display.
* @param tooltip the tooltip to display.
*/
public SystemSearchRemoteFolderAction(Shell shell, String label, String tooltip) {
super(shell, label, tooltip);
}
// ------------------------
// CONFIGURATION METHODS...
// ------------------------
/**
* Set the title for the dialog. The default is "Browse for Folder"
*/
public void setDialogTitle(String title)
{
this.dlgTitle = title;
}
/**
* Set the message shown at the top of the form
*/
public void setMessage(String message)
{
this.message = message;
}
/**
* Set the tooltip text for the remote systems tree from which an item is selected.
*/
public void setSelectionTreeToolTipText(String tip)
{
this.treeTip = tip;
}
/**
* Set the system connection to restrict the user to seeing in the tree.
*
* @see #setRootFolder(IHost, String)
*/
public void setHost(IHost conn)
{
systemConnection = conn;
onlyConnection = true;
}
/**
* Set the connection to default the selection to
*/
public void setDefaultConnection(IHost conn)
{
systemConnection = conn;
onlyConnection = false;
}
/**
* Set the system types to restrict what connections the user sees, and what types of
* connections they can create.
* @param systemTypes An array of system type names
*
* @see org.eclipse.rse.core.IRSESystemType
*/
public void setSystemTypes(String[] systemTypes)
{
this.systemTypes = systemTypes;
}
/**
* Convenience method to restrict to a single system type.
* Same as setSystemTypes(new String[] {systemType})
*
* @param systemType The name of the system type to restrict to
*
* @see org.eclipse.rse.core.IRSESystemType
*/
public void setSystemType(String systemType)
{
if (systemType == null)
setSystemTypes(null);
else
setSystemTypes(new String[] {systemType});
}
/**
* Set to true if a "New Connection..." special connection is to be shown for creating new connections
*/
public void setShowNewConnectionPrompt(boolean show)
{
this.showNewConnectionPrompt = show;
}
/**
* Specify the zero-based auto-expand level for the tree. The default is zero, meaning
* only show the connections.
*/
public void setAutoExpandDepth(int depth)
{
this.expandDepth = depth;
}
/**
* Set the root folder from which to start listing files.
* This version identifies the folder via a connection object and absolute path.
* There is another overload that identifies the folder via a single IRemoteFile object.
* <p>
* This call effectively transforms the select dialog by:
* <ul>
* <li>Preventing the user from selecting other connections
* <li>Preventing the user from selecting other filter strings
* </ul>
*
* @param connection The connection to the remote system containing the root folder
* @param folderAbsolutePath The fully qualified folder to start listing from (eg: "\folder1\folder2")
*
* @see org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString
*/
public void setRootFolder(IHost connection, String folderAbsolutePath)
{
rootFolderConnection = connection;
rootFolderAbsPath = folderAbsolutePath;
}
/**
* Set the root folder from which to start listing folders.
* This version identifies the folder via an IRemoteFile object.
* There is another overload that identifies the folder via a connection and folder path.
* <p>
* This call effectively transforms the select dialog by:
* <ul>
* <li>Preventing the user from selecting other connections
* <li>Preventing the user from selecting other filter strings
* </ul>
*
* @param rootFolder The IRemoteFile object representing the remote folder to start the list from
*
* @see org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString
*/
public void setRootFolder(IRemoteFile rootFolder)
{
setRootFolder(rootFolder.getSystemConnection(),rootFolder.getAbsolutePath());
}
/**
* Set a file or folder to preselect. This will:
* <ul>
* <li>Set the parent folder as the root folder
* <li>Pre-expand the parent folder
* <li>Pre-select the given file or folder after expansion
* </ul>
* If there is no parent, then we were given a root. In which case we will
* <ul>
* <li>Force setRestrictFolders to false
* <li>Pre-expand the root drives (Windows) or root files (Unix)
* <li>Pre-select the given root drive (Windows only)
* </ul>
*/
public void setPreSelection(IRemoteFile selection)
{
preSelection = selection;
}
/**
* Specify whether setRootFolder should prevent the user from being able to see or select
* any other folder. This causes this effect:
* <ol>
* <li>The special filter for root/drives is not shown
* </ol>
*/
public void setRestrictFolders(boolean restrict)
{
restrictFolders = true;
}
/**
* Enable Add mode. This means the OK button is replaced with an Add button, and
* the Cancel with a Close button. When Add is pressed, the caller is called back.
* The dialog is not exited until Close is pressed.
* <p>
* When a library is selected, the caller is called back to decide to enable the Add
* button or not.
*/
public void enableAddMode(ISystemAddFileListener caller)
{
this.addButtonCallback = caller;
}
/**
* Overloaded method that allows setting the label and tooltip text of the Add button.
* If you pass null for the label, the default is used ("Add").
*/
public void enableAddMode(ISystemAddFileListener caller, String addLabel, String addToolTipText)
{
enableAddMode(caller);
this.addLabel = addLabel;
this.addToolTipText = addToolTipText;
}
/**
* Show the property sheet on the right hand side, to show the properties of the
* selected object.
* <p>
* Default is false
*/
public void setShowPropertySheet(boolean show)
{
this.showPropertySheet = show;
}
/**
* Show the property sheet on the right hand side, to show the properties of the
* selected object.
* <p>
* This overload shows a Details>>> button so the user can decide if they want to see the
* property sheet.
* <p>
* @param show True if to show the property sheet within the dialog
* @param initialState True if the property is to be initially displayed, false if it is not
* to be displayed until the user presses the Details button.
*/
public void setShowPropertySheet(boolean show, boolean initialState)
{
setShowPropertySheet(show);
if (show)
{
this.showPropertySheetDetailsButton = true;
this.showPropertySheetDetailsButtonInitialState = initialState;
}
}
/**
* Set multiple selection mode. Default is single selection mode
* <p>
* If you turn on multiple selection mode, you must use the getSelectedObjects()
* method to retrieve the list of selected objects.
*
* @see #getSelectedObjects()
*/
public void setMultipleSelectionMode(boolean multiple)
{
this.multipleSelectionMode = multiple;
}
/*
* Indicates whether to allow selection of objects from differnet parents
*/
public void setAllowForMultipleParents(boolean multiple)
{
this.allowForMultipleParents = multiple;
}
/**
* Specify a validator to use when the user selects a remote file or folder.
* This allows you to decide if OK should be enabled or not for that remote file or folder.
*/
public void setSelectionValidator(IValidatorRemoteSelection selectionValidator)
{
this.selectionValidator = selectionValidator;
}
// -----------------
// OUTPUT METHODS...
// -----------------
/**
* Retrieve selected folder object. If multiple folders selected, returns the first.
*/
public IRemoteFile getSelectedFolder()
{
Object o = getValue();
if (o instanceof IRemoteFile[])
return ((IRemoteFile[])o)[0];
else if (o instanceof IRemoteFile)
return (IRemoteFile)o;
else
return null;
}
/**
* Retrieve selected folder objects. If no folders selected, returns an array of zero.
* If one folder selected returns an array of one.
*/
public IRemoteFile[] getSelectedFolders()
{
Object o = getValue();
if (o instanceof Object[]) {
Object[] temp = (Object[])o;
IRemoteFile[] files = new IRemoteFile[temp.length];
// ensure all objects are IRemoteFiles
for (int i = 0; i < temp.length; i++) {
if (temp[i] instanceof IRemoteFile) {
files[i] = (IRemoteFile)temp[i];
}
// should never happen
else {
return new IRemoteFile[0];
}
}
return files;
}
if (o instanceof IRemoteFile[])
return (IRemoteFile[])o;
else if (o instanceof IRemoteFile)
return new IRemoteFile[] {(IRemoteFile)o};
else
return new IRemoteFile[0];
}
/**
* Return all selected objects. This method will return an array of one
* unless you have called setMultipleSelectionMode(true)!
* <p>
* It will always return null if the user cancelled the dialog.
*
* @see #setMultipleSelectionMode(boolean)
*/
public Object[] getSelectedObjects()
{
Object remoteObject = getValue();
if (remoteObject == null)
return null;
else if (remoteObject instanceof Object[])
return (Object[])remoteObject;
else if (remoteObject instanceof IRemoteFile[])
return (Object[])remoteObject;
else
return new Object[] {remoteObject};
}
/**
* Return selected connection
*/
public IHost getSelectedConnection()
{
return outputConnection;
}
// -------------------
// INTERNAL METHODS...
// -------------------
/**
* Creates an instance of the select dialog for search {@link SystemSearchRemoteFolderDialog}.
* @return the dialog to select remote resource from.
*/
protected Dialog createDialog(Shell shell)
{
SystemSearchRemoteFolderDialog dlg = null;
if (dlgTitle == null)
dlg = new SystemSearchRemoteFolderDialog(shell);
else
dlg = new SystemSearchRemoteFolderDialog(shell, dlgTitle);
dlg.setShowNewConnectionPrompt(showNewConnectionPrompt);
dlg.setMultipleSelectionMode(multipleSelectionMode);
dlg.setAllowForMultipleParents(allowForMultipleParents);
if (restrictFolders)
dlg.setRestrictFolders(true);
if (message != null)
dlg.setMessage(message);
if (treeTip != null)
dlg.setSelectionTreeToolTipText(treeTip);
if (systemConnection != null)
{
if (onlyConnection)
dlg.setSystemConnection(systemConnection);
else
dlg.setDefaultConnection(systemConnection);
}
if (systemTypes != null)
dlg.setSystemTypes(systemTypes);
if (expandDepth != 0)
dlg.setAutoExpandDepth(expandDepth);
if (preSelection != null)
dlg.setPreSelection(preSelection);
else if (rootFolderConnection != null)
dlg.setRootFolder(rootFolderConnection, rootFolderAbsPath);
if (showPropertySheet)
if (showPropertySheetDetailsButton)
dlg.setShowPropertySheet(true, showPropertySheetDetailsButtonInitialState);
else
dlg.setShowPropertySheet(true);
if (addButtonCallback != null)
if ((addLabel!=null) || (addToolTipText!=null))
dlg.enableAddMode(addButtonCallback, addLabel, addToolTipText);
else
dlg.enableAddMode(addButtonCallback);
if (selectionValidator != null)
dlg.setSelectionValidator(selectionValidator);
return dlg;
}
/**
* Required by parent. We return the selected object
*/
protected Object getDialogValue(Dialog dlg)
{
SystemSearchRemoteFolderDialog ourDlg = (SystemSearchRemoteFolderDialog)dlg;
Object outputObject = null;
outputConnection = null;
if (!ourDlg.wasCancelled())
{
if (multipleSelectionMode)
outputObject = ourDlg.getSelectedObjects();
else
outputObject = ourDlg.getSelectedObject();
outputConnection = ourDlg.getSelectedConnection();
}
return outputObject; // parent class calls setValue on what we return
}
}

View file

@ -0,0 +1,54 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.files.ui.internal.search;
import org.eclipse.rse.files.ui.dialogs.SystemSelectRemoteFileOrFolderDialog;
import org.eclipse.rse.files.ui.widgets.SystemSelectRemoteFileOrFolderForm;
import org.eclipse.swt.widgets.Shell;
/**
* Select dialog for search.
*/
public class SystemSearchRemoteFolderDialog extends SystemSelectRemoteFileOrFolderDialog {
/**
* Constructor.
* @param shell the parent shell.
*/
public SystemSearchRemoteFolderDialog(Shell shell) {
super(shell, false);
}
/**
* Contructor.
* @param shell the parent shell.
* @param title the the title of the dialog.
*/
public SystemSearchRemoteFolderDialog(Shell shell, String title) {
super(shell, title, false);
}
/**
* Creates an instance of the select form for search {@link SystemSearchRemoteFolderForm}
* @see org.eclipse.rse.files.ui.dialogs.SystemSelectRemoteFileOrFolderDialog#getForm(boolean)
*/
protected SystemSelectRemoteFileOrFolderForm getForm(boolean fileMode) {
form = new SystemSearchRemoteFolderForm(getMessageLine(), this);
setOutputObject(null);
outputConnection = null;
return form;
}
}

View file

@ -0,0 +1,50 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.files.ui.internal.search;
import org.eclipse.rse.files.ui.widgets.SystemSelectRemoteFileOrFolderForm;
import org.eclipse.rse.subsystems.files.core.model.ISystemFileRemoteTypes;
import org.eclipse.rse.ui.messages.ISystemMessageLine;
import org.eclipse.rse.ui.view.SystemSelectRemoteObjectAPIProviderImpl;
/**
* The selection form to use is search selection dialogs.
*/
public class SystemSearchRemoteFolderForm extends SystemSelectRemoteFileOrFolderForm {
/**
* Constructor.
* @param msgLine the message line.
* @param caller the caller of the contructor for callbacks.
*/
public SystemSearchRemoteFolderForm(ISystemMessageLine msgLine, Object caller) {
super(msgLine, caller, false);
}
/**
* Returns an instance of the search input provider {@link SystemSearchRemoteObjectAPIProvider}
* @see org.eclipse.rse.files.ui.widgets.SystemSelectRemoteFileOrFolderForm#getInputProvider()
*/
protected SystemSelectRemoteObjectAPIProviderImpl getInputProvider() {
if (inputProvider == null) {
// create the input provider that drives the contents of the tree
inputProvider = new SystemSearchRemoteObjectAPIProvider(null, ISystemFileRemoteTypes.TYPECATEGORY, true, null); // show new connection prompt, no system type restrictions
}
return inputProvider;
}
}

View file

@ -0,0 +1,97 @@
/********************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.files.ui.internal.search;
import java.util.List;
import java.util.Vector;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.services.search.ISearchService;
import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem;
import org.eclipse.rse.ui.view.SystemSelectRemoteObjectAPIProviderImpl;
/**
* This is the input provider for selection dialogs related to search.
*/
public class SystemSearchRemoteObjectAPIProvider extends SystemSelectRemoteObjectAPIProviderImpl {
/**
* Constructor.
* @param factoryId the subsystem factory id.
* @param factoryCategory the subsystem facory category.
* @param showNewConnectionPrompt whether to show new connection prompt.
* @param systemTypes the system types to restrict to.
*/
public SystemSearchRemoteObjectAPIProvider(String factoryId, String factoryCategory, boolean showNewConnectionPrompt, String[] systemTypes) {
super(factoryId, factoryCategory, showNewConnectionPrompt, systemTypes);
}
/**
* Constructor.
* @param subsystem the subsystem.
*/
public SystemSearchRemoteObjectAPIProvider(ISubSystem subsystem) {
super(subsystem);
}
/**
* Contrcutor.
*/
public SystemSearchRemoteObjectAPIProvider() {
super();
}
/**
* @see org.eclipse.rse.ui.view.SystemSelectRemoteObjectAPIProviderImpl#getConnections()
*/
protected Object[] getConnections() {
Object[] objs = super.getConnections();
List l = new Vector();
for (int i = 0; i < objs.length; i++) {
Object obj = objs[i];
if (obj instanceof IHost) {
IHost host = (IHost)obj;
ISubSystem[] subsystems = sr.getSubSystems(host);
for (int j = 0; j < subsystems.length; j++) {
ISubSystem subsystem = subsystems[j];
if (subsystem instanceof FileServiceSubSystem) {
FileServiceSubSystem fileSubSystem = (FileServiceSubSystem)subsystem;
ISearchService searchService = fileSubSystem.getSearchService();
if (searchService != null) {
l.add(obj);
break;
}
}
}
}
else {
l.add(obj);
}
}
return l.toArray();
}
}

View file

@ -33,7 +33,7 @@ import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemProfile;
import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.files.ui.FileResources;
import org.eclipse.rse.files.ui.actions.SystemSelectRemoteFolderAction;
import org.eclipse.rse.files.ui.internal.search.SystemSearchRemoteFolderAction;
import org.eclipse.rse.services.clientserver.SystemSearchString;
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
@ -363,7 +363,7 @@ public class SystemSearchPage extends DialogPage implements ISearchPage {
Shell shell = SystemSearchPage.this.getShell();
// create select folder action which opens the select folder dialog
SystemSelectRemoteFolderAction selectFolderAction = new SystemSelectRemoteFolderAction(shell);
SystemSearchRemoteFolderAction selectFolderAction = new SystemSearchRemoteFolderAction(shell);
selectFolderAction.setShowNewConnectionPrompt(true);
selectFolderAction.setShowPropertySheet(true, false);
selectFolderAction.setNeedsProgressMonitor(true);