Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2011-12-06 13:33:58 +0000
committerUwe Stieber2011-12-06 13:33:58 +0000
commit69a6318c280f1069c49f5ada45f70a98245a5c83 (patch)
tree8e778b81f1a7c19daadbda2849e631a1c1fc49f7 /target_explorer/plugins/org.eclipse.tcf.te.core
parenta9e5699bf2d845c2b8d8e941a3eaa32062de05f5 (diff)
downloadorg.eclipse.tcf-69a6318c280f1069c49f5ada45f70a98245a5c83.tar.gz
org.eclipse.tcf-69a6318c280f1069c49f5ada45f70a98245a5c83.tar.xz
org.eclipse.tcf-69a6318c280f1069c49f5ada45f70a98245a5c83.zip
Target Explorer: Added IPersistableNameProvider interface
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.core')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/AdapterFactory.java15
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java47
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableNameProvider.java42
4 files changed, 82 insertions, 23 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml
index b9d868d1e..857bb9f08 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml
@@ -8,6 +8,7 @@
adaptableType="org.eclipse.tcf.te.runtime.model.interfaces.IModelNode"
class="org.eclipse.tcf.te.core.adapters.AdapterFactory">
<adapter type="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable"/>
+ <adapter type="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNameProvider"/>
</factory>
</extension>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/AdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/AdapterFactory.java
index 6f7638185..54e6c5e9c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/AdapterFactory.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/AdapterFactory.java
@@ -12,16 +12,20 @@ package org.eclipse.tcf.te.core.adapters;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNameProvider;
/**
* Adapter factory implementation.
*/
public class AdapterFactory implements IAdapterFactory {
- // The single instance adapter references
- private final IPersistable modelNodePersistableAdapter = new ModelNodePersistableAdapter();
+ // Reference to the persistable adapter to use
+ private final IPersistable persistableAdapter = new ModelNodePersistableAdapter();
+ // Reference to the persistable name provider adapter to use
+ private final IPersistableNameProvider persistableNameProvider = new ModelNodePersistableNameProvider();
private static final Class<?>[] CLASSES = new Class[] {
- IPersistable.class
+ IPersistable.class,
+ IPersistableNameProvider.class
};
/* (non-Javadoc)
@@ -31,7 +35,10 @@ public class AdapterFactory implements IAdapterFactory {
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adaptableObject instanceof IModelNode) {
if (IPersistable.class.equals(adapterType)) {
- return modelNodePersistableAdapter;
+ return persistableAdapter;
+ }
+ if (IPersistableNameProvider.class.equals(adapterType)) {
+ return persistableNameProvider;
}
}
return null;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java
index ec557771b..e3f281eab 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java
@@ -31,6 +31,7 @@ import org.eclipse.tcf.te.runtime.model.interfaces.IContainerModelNode;
import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
import org.eclipse.tcf.te.runtime.persistence.PersistenceDelegateManager;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNameProvider;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
import org.osgi.framework.Bundle;
@@ -63,26 +64,34 @@ public class ModelNodePersistableAdapter implements IPersistable {
IPath path = null;
- // If the persistence node name is set, use it and ignore all other possibilities
- String persistenceNodeName = node.getStringProperty(IPersistableNodeProperties.PROPERTY_NODE_NAME);
- if (persistenceNodeName != null && !"".equals(persistenceNodeName.trim())) { //$NON-NLS-1$
- path = getRoot().append(makeValidFileSystemName(persistenceNodeName.trim()));
+ // Try to adapt the node to the IPersistableNameProvider interface first
+ IPersistableNameProvider provider = (IPersistableNameProvider)node.getAdapter(IPersistableNameProvider.class);
+ if (provider != null) {
+ String name = provider.getName(node);
+ if (name != null && !"".equals(name.trim())) path = getRoot().append(name.trim()); //$NON-NLS-1$
}
- // If the persistence name not set, check for the node name
- else if (node.getName() != null && !"".equals(node.getName().trim())) { //$NON-NLS-1$
- path = getRoot().append(makeValidFileSystemName(node.getName().trim()));
- }
- // If the name is not set, check for an URI
- else if (node.getProperty(IPersistableNodeProperties.PROPERTY_URI) != null) {
- Object candidate = node.getProperty(IPersistableNodeProperties.PROPERTY_URI);
- if (candidate instanceof URI) uri = (URI)candidate;
- else if (candidate instanceof String && !"".equals(((String)candidate).trim())) { //$NON-NLS-1$
- uri = URI.create(((String)candidate).trim());
+
+ if (path == null) {
+ // If the path could not be determined via the IPersistableNameProvider interface, check for the node id
+ if (node.getStringProperty(IModelNode.PROPERTY_ID) != null && !"".equals(node.getStringProperty(IModelNode.PROPERTY_ID).trim())) { //$NON-NLS-1$
+ path = getRoot().append(makeValidFileSystemName(node.getStringProperty(IModelNode.PROPERTY_ID).trim()));
+ }
+ // If the id is not set, check for the node name
+ else if (node.getName() != null && !"".equals(node.getName().trim())) { //$NON-NLS-1$
+ path = getRoot().append(makeValidFileSystemName(node.getName().trim()));
+ }
+ // If the name is not set, check for an URI
+ else if (node.getProperty(IPersistableNodeProperties.PROPERTY_URI) != null) {
+ Object candidate = node.getProperty(IPersistableNodeProperties.PROPERTY_URI);
+ if (candidate instanceof URI) uri = (URI)candidate;
+ else if (candidate instanceof String && !"".equals(((String)candidate).trim())) { //$NON-NLS-1$
+ uri = URI.create(((String)candidate).trim());
+ }
+ }
+ // No name and no explicit path is set -> use the UUID
+ else if (node.getUUID() != null) {
+ path = getRoot().append(makeValidFileSystemName(node.getUUID().toString().trim()));
}
- }
- // No name and no explicit path is set -> use the UUID
- else if (node.getUUID() != null) {
- path = getRoot().append(makeValidFileSystemName(node.getUUID().toString().trim()));
}
if (path != null) {
@@ -100,7 +109,7 @@ public class ModelNodePersistableAdapter implements IPersistable {
* @param name The original name. Must not be <code>null</code>.
* @return The valid file system name.
*/
- private String makeValidFileSystemName(String name) {
+ protected String makeValidFileSystemName(String name) {
Assert.isNotNull(name);
return name.replaceAll("\\W", "_"); //$NON-NLS-1$ //$NON-NLS-2$
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableNameProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableNameProvider.java
new file mode 100644
index 000000000..d11980e9f
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableNameProvider.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.core.adapters;
+
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNameProvider;
+
+/**
+ * Model node persistable name provider implementation.
+ */
+public class ModelNodePersistableNameProvider implements IPersistableNameProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNameProvider#getName(java.lang.Object)
+ */
+ @Override
+ public String getName(Object data) {
+ String name = null;
+
+ // Only model nodes are supported
+ if (data instanceof IModelNode) {
+ IModelNode node = (IModelNode)data;
+
+ // Check for the id property first.
+ name = node.getStringProperty(IModelNode.PROPERTY_ID);
+ // If the id is not set, check for the node name
+ if (name == null || "".equals(name.trim())) { //$NON-NLS-1$
+ name = node.getName();
+ }
+ }
+
+ return name;
+ }
+
+}

Back to the top