From 684e3b0a7eea0d9893b7bd55c22083fc4cbd27bf Mon Sep 17 00:00:00 2001
From: Uwe Stieber
- * The base adapter class used for all RSE objects supports the following properties
- * by default:
- * null
.
@@ -313,4 +314,17 @@ public class RSESystemTypeAdapter extends RSEAdapter {
return false;
}
+
+
+ /**
+ * Creates a new IHost
object instance. This method is
+ * called from {@link org.eclipse.rse.internal.model.SystemHostPool#createHost(String, String, String, String, String, int)}.
+ *
+ * @param profile The system profile to associate with the host.
+ * @return A new IHost
object instance.
+ */
+ public IHost createNewHostInstance(ISystemProfile profile) {
+ return new Host(profile);
+ }
+
}
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java
index 93323bb73c3..3426ec3fccf 100644
--- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java
+++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java
@@ -474,33 +474,6 @@ public class RSEUIPlugin extends SystemBasePlugin implements ISystemMessageProvi
registerDynamicPopupMenuExtensions();
registerKeystoreProviders();
- // if first time creating the remote systems project, add some default connections...
-// if (SystemResourceManager.isFirstTime()
-// && !dontShowLocalConnection) // new support to allow products to not pre-create a local connection
-// {
- //try
- //{
-
-// registry.createLocalHost(null, SystemResources.TERM_LOCAL, SystemProfileManager.getSystemProfileManager().getDefaultPrivateSystemProfileName()); // profile, name, userId
- /* replaced with re-usable method by Phil, in v5.1.2
- SystemConnection localConn = registry.createConnection(
- //SystemResourceConstants.RESOURCE_TEAMPROFILE_NAME, IRSESystemType.SYSTEMTYPE_LOCAL,
- SystemResourceConstants.RESOURCE_PRIVATEPROFILE_NAME, IRSESystemType.SYSTEMTYPE_LOCAL,
- getString(ISystemConstants.TERM_LOCAL, "Local"), // connection name
- "localhost", // hostname
- "", // description
- // DY: defect 42101, description cannot be null
- // null, // description
- getLocalMachineName(), // userId
- IRSEUserIdConstants.USERID_LOCATION_DEFAULT_SYSTEMTYPE, null);
- */
- //}
- //catch (Exception exc)
- //{
- //logError("Error creating default Local connection", exc);
- //}
-// }
-
// new support to allow products to not pre-create a local connection
if (SystemResourceManager.isFirstTime() && SystemPreferencesManager.getShowLocalConnection()) {
// create the connection only if the local system type is enabled!
diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/AbstractSystemViewAdapter.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/AbstractSystemViewAdapter.java
index 0e965cb0b1f..08a4172699e 100644
--- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/AbstractSystemViewAdapter.java
+++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/AbstractSystemViewAdapter.java
@@ -1,5 +1,5 @@
/********************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
+ * Copyright (c) 2002, 2007 IBM Corporation and others. 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
@@ -11,13 +11,15 @@
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
- * {Name} (company) - description of contribution.
+ * Uwe Stieber (Wind River) - Allow to extend action filter by dynamic system type providers.
********************************************************************************/
package org.eclipse.rse.ui.view;
import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -26,11 +28,17 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IBasicPropertyConstants;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.rse.core.IRSESystemType;
+import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.SystemAdapterHelpers;
import org.eclipse.rse.core.SystemBasePlugin;
+import org.eclipse.rse.core.filters.ISystemFilterPoolReference;
+import org.eclipse.rse.core.filters.ISystemFilterReference;
+import org.eclipse.rse.core.filters.ISystemFilterStringReference;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemMessageObject;
import org.eclipse.rse.core.model.ISystemResourceSet;
@@ -60,12 +68,12 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.IActionFilter;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.progress.IElementCollector;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
-import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
@@ -74,10 +82,20 @@ import org.eclipse.ui.views.properties.PropertyDescriptor;
* It implements the ISystemViewElementAdapter interface.
* @see AbstractSystemRemoteAdapterFactory
*/
-public abstract class AbstractSystemViewAdapter
- implements ISystemViewElementAdapter, IPropertySource, ISystemPropertyConstants, IWorkbenchAdapter,
- ISystemViewActionFilter, IDeferredWorkbenchAdapter
+public abstract class AbstractSystemViewAdapter implements ISystemViewElementAdapter, IWorkbenchAdapter,
+ IDeferredWorkbenchAdapter
{
+ // Static action filter per system type cache. Filled from testAttribute.
+ private final static Map ACTION_FILTER_CACHE = new HashMap();
+
+ // Internal helper class to cache system type -> no action filter relation ships.
+ // Used from testAttribute.
+ private final static class NULL_ACTION_FILTER implements IActionFilter {
+ public boolean testAttribute(Object target, String name, String value) {
+ return false;
+ }
+ }
+
//protected boolean isEditable = false;
protected String filterString = null;
@@ -90,6 +108,7 @@ public abstract class AbstractSystemViewAdapter
* Current input provider. Set by content provider
*/
protected Object propertySourceInput = null;
+
/**
* Current shell, set by the content provider
*/
@@ -161,6 +180,13 @@ public abstract class AbstractSystemViewAdapter
* A variable that can be used to cache last selection, if desired
*/
protected Object _lastSelected = null;
+
+ /**
+ * Static constructor.
+ */
+ static {
+ ACTION_FILTER_CACHE.clear();
+ }
// ------------------------------------------------------------------
// Configuration methods, called by the label and content provider...
@@ -524,11 +550,11 @@ public abstract class AbstractSystemViewAdapter
// The following determine what properties will be displayed in the PropertySheet
// resource type
int idx = 0;
- propertyDescriptorArray[idx++] = createSimplePropertyDescriptor(P_TYPE, SystemPropertyResources.RESID_PROPERTY_TYPE_LABEL, SystemPropertyResources.RESID_PROPERTY_TYPE_TOOLTIP);
+ propertyDescriptorArray[idx++] = createSimplePropertyDescriptor(ISystemPropertyConstants.P_TYPE, SystemPropertyResources.RESID_PROPERTY_TYPE_LABEL, SystemPropertyResources.RESID_PROPERTY_TYPE_TOOLTIP);
// resource name
- propertyDescriptorArray[idx++] = createSimplePropertyDescriptor(P_TEXT, SystemPropertyResources.RESID_PROPERTY_NAME_LABEL, SystemPropertyResources.RESID_PROPERTY_NAME_TOOLTIP);
+ propertyDescriptorArray[idx++] = createSimplePropertyDescriptor(IBasicPropertyConstants.P_TEXT, SystemPropertyResources.RESID_PROPERTY_NAME_LABEL, SystemPropertyResources.RESID_PROPERTY_NAME_TOOLTIP);
// number of children in tree currently
- propertyDescriptorArray[idx++] = createSimplePropertyDescriptor(P_NBRCHILDREN, SystemViewResources.RESID_PROPERTY_NBRCHILDREN_LABEL, SystemViewResources.RESID_PROPERTY_NBRCHILDREN_TOOLTIP);
+ propertyDescriptorArray[idx++] = createSimplePropertyDescriptor(ISystemPropertyConstants.P_NBRCHILDREN, SystemViewResources.RESID_PROPERTY_NBRCHILDREN_LABEL, SystemViewResources.RESID_PROPERTY_NBRCHILDREN_TOOLTIP);
}
//System.out.println("In getDefaultDescriptors() in AbstractSystemViewAdapter");
@@ -698,12 +724,12 @@ public abstract class AbstractSystemViewAdapter
public Object getPropertyValue(Object key)
{
String name = (String)key;
- if (name.equals(P_TEXT))
+ if (name.equals(IBasicPropertyConstants.P_TEXT))
//return getText(propertySourceInput);
return getName(propertySourceInput);
- else if (name.equals(P_TYPE))
+ else if (name.equals(ISystemPropertyConstants.P_TYPE))
return getType(propertySourceInput);
- else if (name.equals(P_NBRCHILDREN))
+ else if (name.equals(ISystemPropertyConstants.P_NBRCHILDREN))
{
ISystemTree tree = getSystemTree();
if (tree != null)
@@ -1458,6 +1484,50 @@ public abstract class AbstractSystemViewAdapter
}
return false;
}
+
+ // Give the ISV's as the element owners/contibutors the chance to extend the standard RSE action
+ // filters for their specific needs. We do this by trying to determine the system type from the
+ // target object and try to adapt the system type to an IActionFilter.
+ //
+ // Note: Everything we do here is performance critical to the menu to show up. Therefor
+ // we cache as much as possible here. The cache is static to all AbstractSystemViewAdapter
+ // instances throughout the whole hierarchy.
+ IHost conn = null;
+ if (target instanceof IHost) {
+ conn = (IHost)target;
+ } else if (target instanceof ISubSystem) {
+ conn = ((ISubSystem)target).getHost();
+ } else if (target instanceof ISystemFilterPoolReference) {
+ ISystemFilterPoolReference modelObject = (ISystemFilterPoolReference)target;
+ if (modelObject.getProvider() != null) conn = ((ISubSystem)modelObject.getProvider()).getHost();
+ } else if (target instanceof ISystemFilterReference) {
+ ISystemFilterReference modelObject = (ISystemFilterReference)target;
+ if (modelObject.getProvider() != null) conn = ((ISubSystem)modelObject.getProvider()).getHost();
+ } else if (target instanceof ISystemFilterStringReference) {
+ ISystemFilterStringReference modelObject = (ISystemFilterStringReference)target;
+ if (modelObject.getProvider() != null) conn = ((ISubSystem)modelObject.getProvider()).getHost();
+ }
+
+ if (conn != null) {
+ IRSESystemType systemType = RSECorePlugin.getDefault().getRegistry().getSystemType(conn.getSystemType());
+ if (systemType != null) {
+ IActionFilter actionFilter = (IActionFilter)ACTION_FILTER_CACHE.get(systemType);
+ if (actionFilter == null) {
+ Object adapter = systemType.getAdapter(IActionFilter.class);
+ if (adapter instanceof IActionFilter && !adapter.equals(this)) {
+ // put the association in the cache
+ ACTION_FILTER_CACHE.put(systemType, adapter);
+ actionFilter = (IActionFilter)adapter;
+ } else if (!(adapter instanceof IActionFilter)) {
+ // put the association in the cache
+ ACTION_FILTER_CACHE.put(systemType, new NULL_ACTION_FILTER());
+ }
+ }
+ if (actionFilter instanceof NULL_ACTION_FILTER) actionFilter = null;
+ if (actionFilter != null) return actionFilter.testAttribute(target, name, value);
+ }
+ }
+
return false;
}
diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/ISystemViewActionFilter.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/ISystemViewActionFilter.java
deleted file mode 100644
index aa5570fff25..00000000000
--- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/ISystemViewActionFilter.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/********************************************************************************
- * Copyright (c) 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.ui.view;
-
-import org.eclipse.ui.IActionFilter;
-
-/**
- * This interface is implemented by the adapters for every object shown in the
- * Remote System Explorer. It enables complex filtering of action and popup menu
- * extensions via the <filter> element, and action extensions
- * via the <visibility> and <enablement>
- * elements.
- *
- *
- */
-public interface ISystemViewActionFilter extends IActionFilter
-{
-
-}
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/ISystemViewElementAdapter.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/ISystemViewElementAdapter.java
index 90004ec64d1..790515ad2fd 100644
--- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/ISystemViewElementAdapter.java
+++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/ISystemViewElementAdapter.java
@@ -29,6 +29,7 @@ import org.eclipse.rse.ui.ISystemContextMenuConstants;
import org.eclipse.rse.ui.SystemMenuManager;
import org.eclipse.rse.ui.validators.ISystemValidator;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionFilter;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
@@ -55,7 +56,7 @@ import org.eclipse.ui.views.properties.IPropertySource;
*
- * What we need to do is delete our entry in the preference store for our default userId. - */ - public void deletingHost() - { - String oldUserId = null; - if (previousUserIdKey != null) - oldUserId = getLocalDefaultUserId(previousUserIdKey); - // if the userId attribute held a preference store key of the form profileName.connectionName, - // we have to delete that key entry from the preference store and re-gen a new keyed entry with the same - // value (the actual user id) the old keyed entry held. - if (oldUserId != null) - { - RSEPreferencesManager.clearUserId(previousUserIdKey); - } - } - /** - * Private method called when this connection's profile is being rename, so - * we can do any pre-death cleanup we need. - *
- * What we need to do is rename our entry in the preference store for our default userId. - */ - public void renamingSystemProfile(String oldName, String newName) - { - String userIdValue = null; - if (previousUserIdKey!=null) - userIdValue = getLocalDefaultUserId(previousUserIdKey); - // if the userId attribute held a preference store key of the form profileName.connectionName, - // we have to delete that key entry from the preference store and re-gen a new keyed entry with the same - // value (the actual user id) the old keyed entry held. - String newKey = getPreferencesKey(newName, getAliasName()); - if ((userIdValue != null) && (userIdValue.length()>0)) - { - RSEPreferencesManager.clearUserId(previousUserIdKey); - RSEPreferencesManager.setUserId(newKey, userIdValue); // store old value with new preference key - } - previousUserIdKey = newKey; - } - - /** - * Return the system profile that owns this connection - */ - public ISystemProfile getSystemProfile() - { - return _profile; - } - /** - * Return the name of system profile that owns this connection - */ - public String getSystemProfileName() - { - if (pool == null) - return null; - else - { - ISystemProfile profile = pool.getSystemProfile(); - if (profile!=null) - return profile.getName(); - else - return null; - } - } - - /** - * Intercept of setAliasName so we can potentially rename the default-user-id key - * for the preferences store. That key is profileName.connectionAliasName so is - * affected when the alias name changes. - */ - public void setAliasName(String newName) - { - String userIdValue = null; - if (previousUserIdKey != null) - userIdValue = getLocalDefaultUserId(previousUserIdKey); - this.setAliasNameGen(newName); // update mof-modelled attribute - // if the userId attribute held a preference store key of the form profileName.connectionAliasName, - // we have to delete that key entry from the preference store and re-gen a new keyed entry with the same - // value (the actual user id) the old keyed entry held. - String newKey = getPreferencesKey(getSystemProfileName(), newName); - if ((userIdValue != null) && (userIdValue.length()>0)) - { - RSEPreferencesManager.clearUserId(previousUserIdKey); - RSEPreferencesManager.setUserId(newKey, userIdValue); // store old value with new preference key - } - previousUserIdKey = newKey; - } - /** - * Intercept of setSystemType so we can decide if the user ID is case sensitive - */ - public void setSystemType(String systemType) - { - // defect 43219 - if (systemType != null) - { - boolean forceUC = systemType.equals(IRSESystemType.SYSTEMTYPE_ISERIES); - boolean caseSensitiveUID = systemType.equals(IRSESystemType.SYSTEMTYPE_UNIX) - || systemType.equals(IRSESystemType.SYSTEMTYPE_LINUX) - || (systemType.equals(IRSESystemType.SYSTEMTYPE_LOCAL) && - !System.getProperty("os.name").toLowerCase().startsWith("windows")); //$NON-NLS-1$ //$NON-NLS-2$ - setForceUserIdToUpperCase(forceUC); - setUserIdCaseSensitive(caseSensitiveUID); - } - this.setSystemTypeGen(systemType); - } - - /** - * Intercept of setHostName so we can force it to uppercase. - * IPv4 host names are case insensitive. Much data is stored using the host - * name as part of the key. Therefore, the host name is capitalized here so that - * these comparisons work naturally. - * However, this must be done using the US locale since IPv4 host names - * use can be compared using this locale. See RFC1035. - */ - public void setHostName(String name) { - if (name != null) { - name = name.toUpperCase(Locale.US); - } - this.setHostNameGen(name); - } - /** - * Intercept of setDefaultUserId so we can force it to uppercase. - * Also, we do not store the user Id per se in the attribute, but rather - * we store it in the preference with a key name unique to this connection. - * We store that key name in this attribute. However, this is all transparent to - * the caller. - */ - public void setDefaultUserId(String newId) - { - if ((newId != null) && ucId) - newId = newId.toUpperCase(); - - if ((newId == null) || (newId.length()==0)) // a "clear" request? - { - clearLocalDefaultUserId(); - } - else - { - String key = getPreferencesKey(); - if (key != null) - { - RSEPreferencesManager.setUserId(key, newId); - } - } - } - /** - * Returns the default UserId for this Host. - * Note that we don't store it directly in - * the model, since we don't want the team to share it. Rather, - * we store the actual it in the preference store keyed by - * (profileName.connectionName). - *
- * Further, it is possible that there is no default UserId. If so, this - * method will go to the preference store and will try to get the default - * UserId for this connection's system type. - *
- * This is all transparent to the caller though. - *
- * @return The value of the DefaultUserId attribute - */ - public String getDefaultUserId() - { - String uid = getLocalDefaultUserId(); - if ((uid == null) || (uid.length()==0)) - { - uid = RSEPreferencesManager.getUserId(getSystemType()); // resolve from preferences - if ((uid != null) && ucId) - uid = uid.toUpperCase(); - } - return uid; - } - /** - * Return the local default user Id without resolving up the food chain. - * @see #getDefaultUserId() - */ - protected static String getLocalDefaultUserId(String key) - { - String uid = null; - if ((key!=null) && (key.length()>0)) - { - uid = RSEPreferencesManager.getUserId(key); // resolve from preferences - } - return uid; - } - /** - * Return the local default user Id without resolving up the food chain. - * @see #getDefaultUserId() - */ - public String getLocalDefaultUserId() - { - return getLocalDefaultUserId(getPreferencesKey()); - } - - /** - * Clear the local default user Id so next query will return the value from - * the preference store. - *
- * Same as calling setDefaultUserId(null)
- * @see #setDefaultUserId(String)
- */
- public void clearLocalDefaultUserId()
- {
- if (previousUserIdKey!=null)
- RSEPreferencesManager.clearUserId(previousUserIdKey);
- }
-
- /**
- * Helper method to compute a unique name for a given subsystem instance
- */
- protected String getPreferencesKey()
- {
- if ((getSystemProfileName()==null) || (getAliasName()==null))
- return null;
- return getPreferencesKey(getSystemProfileName());
- }
- /**
- * Helper method to compute a unique name for a given subsystem instance, given a profile name
- */
- protected String getPreferencesKey(String profileName)
- {
- String connectionName = getAliasName();
- if (connectionName == null)
- return null;
- return getPreferencesKey(profileName, connectionName);
- }
- /**
- * Helper method to compute a unique name for a given subsystem instance, given a profile name and connection name
- */
- protected String getPreferencesKey(String profileName, String connectionName)
- {
- return profileName + "." + connectionName; //$NON-NLS-1$
- }
-
-
- /**
- * Call this with false to turn off the default behaviour of forcing the default userId to uppercase.
- */
- public void setForceUserIdToUpperCase(boolean force)
- {
- this.ucId = force;
- }
- /**
- * Call this to turn off the default behaviour of considering case when comparing userIds
- */
- public void setUserIdCaseSensitive(boolean caseSensitive)
- {
- this.userIdCaseSensitive = caseSensitive;
- }
-
- /**
- * Call this to query whether the default userId is to be uppercased.
- */
- public boolean getForceUserIdToUpperCase()
- {
- return ucId;
- }
- /**
- * Call this to query whether the default userId is case sensitive
- */
- public boolean getUserIdCaseSensitive()
- {
- return userIdCaseSensitive;
- }
- /**
- * Call this to compare two userIds taking case sensitivity
- */
- public boolean compareUserIds(String userId1, String userId2)
- {
- if (userId1 == null)
- userId1 = ""; //$NON-NLS-1$
- if (userId2 == null)
- userId2 = ""; //$NON-NLS-1$
- if (userIdCaseSensitive)
- return userId1.equals(userId2);
- else
- return userId1.equalsIgnoreCase(userId2);
- }
-
- public String toString()
- {
- if (getAliasName() == null)
- return this.toStringGen();
- else
- return getAliasName();
- }
- /**
- * This is the method required by the IAdaptable interface.
- * Given an adapter class type, return an object castable to the type, or
- * null if this is not possible.
- */
- public Object getAdapter(Class adapterType)
- {
- return Platform.getAdapterManager().getAdapter(this, adapterType);
- }
-
-
- /**
- * @generated This field/method will be replaced during code generation
- */
- public String getSystemType()
- {
- return systemType;
- }
-
- /**
- * Returns the alias name for this host
- */
- public String getName()
- {
- return getAliasName();
- }
-
- /**
- * @generated This field/method will be replaced during code generation
- * The unique key for this object. Unique per connection pool
- */
- public String getAliasName()
- {
- return aliasName;
- }
-
- /**
- * @generated This field/method will be replaced during code generation
- */
- public String getHostName()
- {
- return hostName;
- }
-
- /**
- * @generated This field/method will be replaced during code generation
- */
- public String getDescription()
- {
- return description;
- }
-
- /**
- * @generated This field/method will be replaced during code generation.
- */
- public void setDescription(String newDescription)
- {
- setDirty(!compareStrings(description, newDescription));
- description = newDescription;
- }
-
- /**
- * @generated This field/method will be replaced during code generation
- */
- public boolean isPromptable()
- {
- return promptable;
- }
-
- /**
- * @generated This field/method will be replaced during code generation.
- */
- public void setPromptable(boolean newPromptable)
- {
- setDirty(promptable != newPromptable);
- promptable = newPromptable;
- }
-
- /**
- *
- * Query if this connection is offline or not. It is up to each subsystem to honor this
- * flag.
- *
- * @generated
- */
- public boolean isOffline()
- {
- return offline;
- }
-
- /**
- *
- * Specify if this connection is offline or not. It is up to each subsystem to honor this
- * flag.
- *
- * @generated
- */
- public void setOffline(boolean newOffline)
- {
- setDirty(offline != newOffline);
- offline = newOffline;
- }
-
- /**
- * @generated This field/method will be replaced during code generation.
- */
- public void setSystemTypeGen(String newSystemType)
- {
- setDirty(!compareStrings(systemType, newSystemType));
- systemType = newSystemType;
- }
-
- /**
- * @generated This field/method will be replaced during code generation.
- */
- public void setAliasNameGen(String newAliasName)
- {
- setDirty(!compareStrings(aliasName, newAliasName));
- aliasName = newAliasName;
- }
-
- /**
- * @generated This field/method will be replaced during code generation.
- */
- public void setHostNameGen(String newHostName)
- {
- setDirty(!compareStrings(hostName, newHostName));
- hostName = newHostName;
- }
-
- /**
- * @generated This field/method will be replaced during code generation
- */
- public String getDefaultUserIdGen()
- {
- return defaultUserId;
- }
-
- /**
- * @generated This field/method will be replaced during code generation.
- */
- public void setDefaultUserIdGen(String newDefaultUserId)
- {
- setDirty(!compareStrings(defaultUserId, newDefaultUserId));
- defaultUserId = newDefaultUserId;
- }
-
- /**
- * @deprecated This field/method will be replaced during code generation.
- */
- public String toStringGen()
- {
- StringBuffer result = new StringBuffer(super.toString());
- result.append(" (systemType: "); //$NON-NLS-1$
- result.append(systemType);
- result.append(", aliasName: "); //$NON-NLS-1$
- result.append(aliasName);
- result.append(", hostName: "); //$NON-NLS-1$
- result.append(hostName);
- result.append(", description: "); //$NON-NLS-1$
- result.append(description);
- result.append(", defaultUserId: "); //$NON-NLS-1$
- result.append(defaultUserId);
- result.append(", promptable: "); //$NON-NLS-1$
- result.append(promptable);
- result.append(", offline: "); //$NON-NLS-1$
- result.append(offline);
- result.append(')');
- return result.toString();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.rse.core.model.RSEModelObject#setDirty(boolean)
- */
- public void setDirty(boolean flag) {
- super.setDirty(flag);
- ISystemHostPool myPool = getHostPool();
- if (myPool != null && flag) {
- myPool.setDirty(true);
- }
- }
-
- public boolean commit()
- {
- return RSEUIPlugin.getThePersistenceManager().commit(this);
- }
-
-}
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java
index 6a92f8e287a..3c3209c03a5 100644
--- a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java
+++ b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java
@@ -21,6 +21,7 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.IRSEUserIdConstants;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.RSEPreferencesManager;
@@ -29,6 +30,8 @@ import org.eclipse.rse.core.model.ISystemHostPool;
import org.eclipse.rse.core.model.ISystemProfile;
import org.eclipse.rse.core.model.RSEModelObject;
import org.eclipse.rse.core.model.RSEModelResources;
+import org.eclipse.rse.model.Host;
+import org.eclipse.rse.ui.RSESystemTypeAdapter;
/**
@@ -205,7 +208,19 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool
try
{
ISystemProfile profile = getSystemProfile();
- conn = new Host(profile);
+
+ // delegate the creation of the host object instance to the system type provider!!!
+ IRSESystemType systemTypeObject = RSECorePlugin.getDefault().getRegistry().getSystemType(systemType);
+ if (systemTypeObject != null) {
+ Object adapter = systemTypeObject.getAdapter(IRSESystemType.class);
+ if (adapter instanceof RSESystemTypeAdapter) {
+ conn = ((RSESystemTypeAdapter)adapter).createNewHostInstance(profile);
+ }
+ }
+ // Fallback to create host object instance here if failed by system type provider.
+ if (conn == null) conn = new Host(profile);
+ assert conn != null;
+
addHost(conn); // only record internally if saved successfully
conn.setHostPool(this);
conn.setAliasName(aliasName);
diff --git a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/model/Host.java b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/model/Host.java
new file mode 100644
index 00000000000..8d98da3d4f9
--- /dev/null
+++ b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/model/Host.java
@@ -0,0 +1,549 @@
+/********************************************************************************
+ * Copyright (c) 2006, 2007 IBM Corporation and others. 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:
+ * David Dykstal (IBM) - using new API from RSECorePlugin, RSEPreferencesManager
+ * - moved SystemsPreferencesManager to a new plugin
+ * Uwe Stieber (Wind River) - Dynamic system type provider extensions.
+ * - Moved to package org.eclipse.rse.model for being extendable.
+ ********************************************************************************/
+
+package org.eclipse.rse.model;
+
+import java.util.Locale;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.rse.core.IRSESystemType;
+import org.eclipse.rse.core.RSEPreferencesManager;
+import org.eclipse.rse.core.model.IHost;
+import org.eclipse.rse.core.model.ISystemHostPool;
+import org.eclipse.rse.core.model.ISystemProfile;
+import org.eclipse.rse.core.model.RSEModelObject;
+import org.eclipse.rse.core.subsystems.IConnectorService;
+import org.eclipse.rse.core.subsystems.ISubSystem;
+import org.eclipse.rse.ui.RSEUIPlugin;
+
+/**
+ * Default implementation of the IHost
interface.
+ *
+ * Dynamic system type providers may extend this implementation
+ * if needed.
+ */
+public class Host extends RSEModelObject implements IHost {
+
+
+ private boolean ucId = true;
+ private boolean userIdCaseSensitive = true;
+ private ISystemHostPool pool;
+ protected String previousUserIdKey;
+
+ /**
+ * The system type which is associated to this IHost
object.
+ */
+ private String systemType = null;
+
+ /**
+ * The alias name of this IHost
object.
+ */
+ private String aliasName = null;
+
+ /**
+ * The host name of the target which is associated to this IHost
object.
+ */
+ private String hostName = null;
+
+ /**
+ * The description of this IHost
object.
+ */
+ private String description = null;
+
+ /**
+ * The default user id to use to login to the target host.
+ */
+ private String defaultUserId = null;
+
+ /**
+ * Prompt for user id and password.
+ */
+ private boolean promptable = false;
+
+ /**
+ * Offline mode.
+ */
+ private boolean offline = false;
+
+ /**
+ * The system profile associated with this IHost
object.
+ */
+ private ISystemProfile _profile;
+
+ /**
+ * Constructor
+ */
+ public Host(ISystemProfile profile) {
+ super();
+ _profile = profile;
+ }
+
+ /**
+ * Set the parent connection pool this is owned by.
+ * Connection pools are internal management objects, one per profile.
+ */
+ public void setHostPool(ISystemHostPool pool) {
+ this.pool = pool;
+ previousUserIdKey = getPreferencesKey();
+ }
+
+ /**
+ * Set the parent connection pool this is owned by.
+ * Connection pools are internal management objects, one per profile.
+ */
+ public ISystemHostPool getHostPool() {
+ return pool;
+ }
+
+ /**
+ * Return all the connector services provided for this host
+ */
+ public IConnectorService[] getConnectorServices() {
+ return RSEUIPlugin.getTheSystemRegistry().getConnectorServices(this);
+ }
+
+ /**
+ * Return the subsystem instances under this connection.
+ * Just a shortcut to {@link org.eclipse.rse.core.model.ISystemRegistry#getSubSystems(IHost)}
+ */
+ public ISubSystem[] getSubSystems() {
+ return RSEUIPlugin.getTheSystemRegistry().getSubSystems(this);
+ }
+
+ /**
+ * Private method called when this connection is being deleted, so
+ * we can do any pre-death cleanup we need.
+ *
+ * What we need to do is delete our entry in the preference store for our default userId. + */ + public void deletingHost() { + String oldUserId = null; + if (previousUserIdKey != null) oldUserId = getLocalDefaultUserId(previousUserIdKey); + // if the userId attribute held a preference store key of the form profileName.connectionName, + // we have to delete that key entry from the preference store and re-gen a new keyed entry with the same + // value (the actual user id) the old keyed entry held. + if (oldUserId != null) { + RSEPreferencesManager.clearUserId(previousUserIdKey); + } + } + + /** + * Private method called when this connection's profile is being rename, so + * we can do any pre-death cleanup we need. + *
+ * What we need to do is rename our entry in the preference store for our default userId. + */ + public void renamingSystemProfile(String oldName, String newName) { + String userIdValue = null; + if (previousUserIdKey != null) userIdValue = getLocalDefaultUserId(previousUserIdKey); + // if the userId attribute held a preference store key of the form profileName.connectionName, + // we have to delete that key entry from the preference store and re-gen a new keyed entry with the same + // value (the actual user id) the old keyed entry held. + String newKey = getPreferencesKey(newName, getAliasName()); + if ((userIdValue != null) && (userIdValue.length() > 0)) { + RSEPreferencesManager.clearUserId(previousUserIdKey); + RSEPreferencesManager.setUserId(newKey, userIdValue); // store old value with new preference key + } + previousUserIdKey = newKey; + } + + /** + * Return the system profile that owns this connection + */ + public ISystemProfile getSystemProfile() { + return _profile; + } + + /** + * Return the name of system profile that owns this connection + */ + public String getSystemProfileName() { + if (pool == null) + return null; + else { + ISystemProfile profile = pool.getSystemProfile(); + if (profile != null) + return profile.getName(); + else return null; + } + } + + /** + * Intercept of setAliasName so we can potentially rename the default-user-id key + * for the preferences store. That key is profileName.connectionAliasName so is + * affected when the alias name changes. + */ + public void setAliasName(String newName) { + String userIdValue = null; + if (previousUserIdKey != null) userIdValue = getLocalDefaultUserId(previousUserIdKey); + this.setAliasNameGen(newName); // update mof-modelled attribute + // if the userId attribute held a preference store key of the form profileName.connectionAliasName, + // we have to delete that key entry from the preference store and re-gen a new keyed entry with the same + // value (the actual user id) the old keyed entry held. + String newKey = getPreferencesKey(getSystemProfileName(), newName); + if ((userIdValue != null) && (userIdValue.length() > 0)) { + RSEPreferencesManager.clearUserId(previousUserIdKey); + RSEPreferencesManager.setUserId(newKey, userIdValue); // store old value with new preference key + } + previousUserIdKey = newKey; + } + + /** + * Intercept of setSystemType so we can decide if the user ID is case sensitive + */ + public void setSystemType(String systemType) { + // defect 43219 + if (systemType != null) { + boolean forceUC = systemType.equals(IRSESystemType.SYSTEMTYPE_ISERIES); + boolean caseSensitiveUID = systemType.equals(IRSESystemType.SYSTEMTYPE_UNIX) || systemType.equals(IRSESystemType.SYSTEMTYPE_LINUX) + || (systemType.equals(IRSESystemType.SYSTEMTYPE_LOCAL) && !System.getProperty("os.name").toLowerCase().startsWith("windows")); //$NON-NLS-1$ //$NON-NLS-2$ + setForceUserIdToUpperCase(forceUC); + setUserIdCaseSensitive(caseSensitiveUID); + } + this.setSystemTypeGen(systemType); + } + + /** + * Intercept of setHostName so we can force it to uppercase. + * IPv4 host names are case insensitive. Much data is stored using the host + * name as part of the key. Therefore, the host name is capitalized here so that + * these comparisons work naturally. + * However, this must be done using the US locale since IPv4 host names + * use can be compared using this locale. See RFC1035. + */ + public void setHostName(String name) { + if (name != null) { + name = name.toUpperCase(Locale.US); + } + this.setHostNameGen(name); + } + + /** + * Intercept of setDefaultUserId so we can force it to uppercase. + * Also, we do not store the user Id per se in the attribute, but rather + * we store it in the preference with a key name unique to this connection. + * We store that key name in this attribute. However, this is all transparent to + * the caller. + */ + public void setDefaultUserId(String newId) { + if ((newId != null) && ucId) newId = newId.toUpperCase(); + + if ((newId == null) || (newId.length() == 0)) // a "clear" request? + { + clearLocalDefaultUserId(); + } + else { + String key = getPreferencesKey(); + if (key != null) { + RSEPreferencesManager.setUserId(key, newId); + } + } + } + + /** + * Returns the default UserId for this Host. + * Note that we don't store it directly in + * the model, since we don't want the team to share it. Rather, + * we store the actual it in the preference store keyed by + * (profileName.connectionName). + *
+ * Further, it is possible that there is no default UserId. If so, this + * method will go to the preference store and will try to get the default + * UserId for this connection's system type. + *
+ * This is all transparent to the caller though. + *
+ * @return The value of the DefaultUserId attribute + */ + public String getDefaultUserId() { + String uid = getLocalDefaultUserId(); + if ((uid == null) || (uid.length() == 0)) { + uid = RSEPreferencesManager.getUserId(getSystemType()); // resolve from preferences + if ((uid != null) && ucId) uid = uid.toUpperCase(); + } + return uid; + } + + /** + * Return the local default user Id without resolving up the food chain. + * @see #getDefaultUserId() + */ + protected static String getLocalDefaultUserId(String key) { + String uid = null; + if ((key != null) && (key.length() > 0)) { + uid = RSEPreferencesManager.getUserId(key); // resolve from preferences + } + return uid; + } + + /** + * Return the local default user Id without resolving up the food chain. + * @see #getDefaultUserId() + */ + public String getLocalDefaultUserId() { + return getLocalDefaultUserId(getPreferencesKey()); + } + + /** + * Clear the local default user Id so next query will return the value from + * the preference store. + *
+ * Same as calling setDefaultUserId(null) + * @see #setDefaultUserId(String) + */ + public void clearLocalDefaultUserId() { + if (previousUserIdKey != null) RSEPreferencesManager.clearUserId(previousUserIdKey); + } + + /** + * Helper method to compute a unique name for a given subsystem instance + */ + protected String getPreferencesKey() { + if ((getSystemProfileName() == null) || (getAliasName() == null)) return null; + return getPreferencesKey(getSystemProfileName()); + } + + /** + * Helper method to compute a unique name for a given subsystem instance, given a profile name + */ + protected String getPreferencesKey(String profileName) { + String connectionName = getAliasName(); + if (connectionName == null) return null; + return getPreferencesKey(profileName, connectionName); + } + + /** + * Helper method to compute a unique name for a given subsystem instance, given a profile name and connection name + */ + protected String getPreferencesKey(String profileName, String connectionName) { + return profileName + "." + connectionName; //$NON-NLS-1$ + } + + /** + * Call this with false to turn off the default behaviour of forcing the default userId to uppercase. + */ + public void setForceUserIdToUpperCase(boolean force) { + this.ucId = force; + } + + /** + * Call this to turn off the default behaviour of considering case when comparing userIds + */ + public void setUserIdCaseSensitive(boolean caseSensitive) { + this.userIdCaseSensitive = caseSensitive; + } + + /** + * Call this to query whether the default userId is to be uppercased. + */ + public boolean getForceUserIdToUpperCase() { + return ucId; + } + + /** + * Call this to query whether the default userId is case sensitive + */ + public boolean getUserIdCaseSensitive() { + return userIdCaseSensitive; + } + + /** + * Call this to compare two userIds taking case sensitivity + */ + public boolean compareUserIds(String userId1, String userId2) { + if (userId1 == null) userId1 = ""; //$NON-NLS-1$ + if (userId2 == null) userId2 = ""; //$NON-NLS-1$ + if (userIdCaseSensitive) + return userId1.equals(userId2); + else return userId1.equalsIgnoreCase(userId2); + } + + public String toString() { + if (getAliasName() == null) { + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (systemType: "); //$NON-NLS-1$ + result.append(systemType); + result.append(", aliasName: "); //$NON-NLS-1$ + result.append(aliasName); + result.append(", hostName: "); //$NON-NLS-1$ + result.append(hostName); + result.append(", description: "); //$NON-NLS-1$ + result.append(description); + result.append(", defaultUserId: "); //$NON-NLS-1$ + result.append(defaultUserId); + result.append(", promptable: "); //$NON-NLS-1$ + result.append(promptable); + result.append(", offline: "); //$NON-NLS-1$ + result.append(offline); + result.append(')'); + return result.toString(); + } + + return getAliasName(); + } + + /** + * This is the method required by the IAdaptable interface. + * Given an adapter class type, return an object castable to the type, or + * null if this is not possible. + */ + public Object getAdapter(Class adapterType) { + return Platform.getAdapterManager().getAdapter(this, adapterType); + } + + /** + * @generated This field/method will be replaced during code generation + */ + public String getSystemType() { + return systemType; + } + + /** + * Returns the alias name for this host + */ + public String getName() { + return getAliasName(); + } + + /** + * @generated This field/method will be replaced during code generation + * The unique key for this object. Unique per connection pool + */ + public String getAliasName() { + return aliasName; + } + + /** + * @generated This field/method will be replaced during code generation + */ + public String getHostName() { + return hostName; + } + + /** + * @generated This field/method will be replaced during code generation + */ + public String getDescription() { + return description; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setDescription(String newDescription) { + setDirty(!compareStrings(description, newDescription)); + description = newDescription; + } + + /** + * @generated This field/method will be replaced during code generation + */ + public boolean isPromptable() { + return promptable; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setPromptable(boolean newPromptable) { + setDirty(promptable != newPromptable); + promptable = newPromptable; + } + + /** + * + * Query if this connection is offline or not. It is up to each subsystem to honor this + * flag. + * + * @generated + */ + public boolean isOffline() { + return offline; + } + + /** + * + * Specify if this connection is offline or not. It is up to each subsystem to honor this + * flag. + * + * @generated + */ + public void setOffline(boolean newOffline) { + setDirty(offline != newOffline); + offline = newOffline; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setSystemTypeGen(String newSystemType) { + setDirty(!compareStrings(systemType, newSystemType)); + systemType = newSystemType; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setAliasNameGen(String newAliasName) { + setDirty(!compareStrings(aliasName, newAliasName)); + aliasName = newAliasName; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setHostNameGen(String newHostName) { + setDirty(!compareStrings(hostName, newHostName)); + hostName = newHostName; + } + + /** + * @generated This field/method will be replaced during code generation + */ + public String getDefaultUserIdGen() { + return defaultUserId; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setDefaultUserIdGen(String newDefaultUserId) { + setDirty(!compareStrings(defaultUserId, newDefaultUserId)); + defaultUserId = newDefaultUserId; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.RSEModelObject#setDirty(boolean) + */ + public void setDirty(boolean flag) { + super.setDirty(flag); + ISystemHostPool myPool = getHostPool(); + if (myPool != null && flag) { + myPool.setDirty(true); + } + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.IRSEPersistableContainer#commit() + */ + public boolean commit() { + return RSEUIPlugin.getThePersistenceManager().commit(this); + } + +} \ No newline at end of file