Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2012-03-30 10:37:38 +0000
committerUwe Stieber2012-03-30 10:37:38 +0000
commit584d406667038d8c2b9595f291f354b1c4aa4416 (patch)
tree3941823891752d3f0092bae69aa1fff8e170ef44
parentfa6f33666c29c335cfc6a6f6e957a9727529c46d (diff)
downloadorg.eclipse.tcf-584d406667038d8c2b9595f291f354b1c4aa4416.tar.gz
org.eclipse.tcf-584d406667038d8c2b9595f291f354b1c4aa4416.tar.xz
org.eclipse.tcf-584d406667038d8c2b9595f291f354b1c4aa4416.zip
Target Explorer: REWORK persistence, ADD file transfer and referenced projects to remote app launch
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/AdapterFactory.java8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java356
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableURIProvider.java371
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java53
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/IFileTransferItem.java29
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/IReferencedProjectItem.java23
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/delegates/DefaultLaunchManagerDelegate.java17
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java10
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IFileTransferLaunchAttributes.java24
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IReferencedProjectLaunchAttributes.java23
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java101
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties51
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/AbstractItemListPersistenceDelegate.java274
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/AbstractItemListXMLParser.java212
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java555
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ReferencedProjectsPersistenceDelegate.java228
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransferItem.java28
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransferItemValidator.java86
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransfersPersistenceDelegate.java114
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/launchcontext/LaunchContextsPersistenceDelegate.java257
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectItem.java28
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectItemValidator.java50
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectsPersistenceDelegate.java114
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/LaunchContextSelectorSection.java10
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties41
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/bindings.exsd134
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPersistenceDelegate.java20
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesPersistenceDelegate.java103
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesToURIPersistenceDelegate.java335
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceDelegateManager.java)57
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable.java78
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable2.java53
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistableURIProvider.java32
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java59
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceService.java68
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IURIPersistenceService.java71
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java66
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java182
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/properties/PropertiesFilePersistenceDelegate.java275
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/PersistenceService.java152
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java119
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/schema/bindings.exsd2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/internal/StatusHandlerBindingExtensionPointManager.java349
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/dialogs/FSFolderSelectionDialog.java23
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/META-INF/MANIFEST.MF3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml74
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/interfaces/IRemoteAppLaunchAttributes.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/interfaces/ILinuxAppLaunchAttributes.java)2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/FileTransferItemToStringPersistenceDelegate.java78
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/ReferencedProjectItemToStringPersistenceDelegate.java78
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/RemoteAppLaunchManagerDelegate.java93
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/LaunchProcessStep.java14
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.java39
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.properties41
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationMainTabSection.java22
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationTabGroup.java10
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/AddEditFileTransferDialog.java297
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/FileTransferSection.java620
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/FileTransferTab.java67
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/projects/ReferencedProjectsSection.java491
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/projects/ReferencedProjetcsTab.java67
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/META-INF/MANIFEST.MF70
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml84
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeersPersistenceDelegate.java122
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/AdapterFactory.java26
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/MapPersistableAdapter.java152
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/MapPersistableURIProvider.java97
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerModelPersistableAdapter.java258
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerPersistableURIProvider.java208
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelLocationUtil.java46
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/AbstractPropertiesToStringPersistenceDelegate.java116
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/PeerToStringPersistenceDelegate.java145
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/PeerToURIPersistenceDelegate.java89
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java856
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/AttributesSection.java68
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/GeneralInformationSection.java46
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/TransportSection.java82
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RedirectHandler.java25
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/ResetRedirectHandler.java20
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/DeleteHandlerDelegate.java42
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/categories/CategoryManager.java25
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/NewTargetWizard.java11
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractPartWithButtons.java5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractStructuredViewerSection.java6
87 files changed, 6540 insertions, 3313 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 857bb9f08..50188ca3c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml
@@ -7,7 +7,7 @@
<factory
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.IPersistableURIProvider"/>
<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 54e6c5e9c..2fb63dd8d 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
@@ -11,7 +11,7 @@ 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.IPersistableURIProvider;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNameProvider;
/**
@@ -19,12 +19,12 @@ import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNameProvide
*/
public class AdapterFactory implements IAdapterFactory {
// Reference to the persistable adapter to use
- private final IPersistable persistableAdapter = new ModelNodePersistableAdapter();
+ private final IPersistableURIProvider persistableAdapter = new ModelNodePersistableURIProvider();
// Reference to the persistable name provider adapter to use
private final IPersistableNameProvider persistableNameProvider = new ModelNodePersistableNameProvider();
private static final Class<?>[] CLASSES = new Class[] {
- IPersistable.class,
+ IPersistableURIProvider.class,
IPersistableNameProvider.class
};
@@ -34,7 +34,7 @@ public class AdapterFactory implements IAdapterFactory {
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adaptableObject instanceof IModelNode) {
- if (IPersistable.class.equals(adapterType)) {
+ if (IPersistableURIProvider.class.equals(adapterType)) {
return persistableAdapter;
}
if (IPersistableNameProvider.class.equals(adapterType)) {
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
deleted file mode 100644
index e3f281eab..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java
+++ /dev/null
@@ -1,356 +0,0 @@
-/*******************************************************************************
- * 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 java.io.IOException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.URI;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.tcf.te.core.activator.CoreBundleActivator;
-import org.eclipse.tcf.te.core.nls.Messages;
-import org.eclipse.tcf.te.runtime.model.factory.Factory;
-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;
-
-/**
- * Model node persistable adapter implementation.
- */
-public class ModelNodePersistableAdapter implements IPersistable {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getStorageID()
- */
- @Override
- public String getStorageID() {
- return "org.eclipse.tcf.te.runtime.persistence.properties"; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getURI(java.lang.Object)
- */
- @Override
- public URI getURI(Object data) {
- Assert.isNotNull(data);
-
- URI uri = null;
-
- // Only model nodes are supported
- if (data instanceof IModelNode) {
- IModelNode node = (IModelNode) data;
-
- IPath path = null;
-
- // 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 (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()));
- }
- }
-
- if (path != null) {
- if (!"ini".equals(path.getFileExtension())) path = path.addFileExtension("ini"); //$NON-NLS-1$ //$NON-NLS-2$
- uri = path.toFile().toURI();
- }
- }
-
- return uri;
- }
-
- /**
- * Make a valid file system name from the given name.
- *
- * @param name The original name. Must not be <code>null</code>.
- * @return The valid file system name.
- */
- protected String makeValidFileSystemName(String name) {
- Assert.isNotNull(name);
- return name.replaceAll("\\W", "_"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Returns the root location.
- *
- * @return The root location or <code>null</code> if it cannot be determined.
- */
- public IPath getRoot() {
- IPath location = null;
-
- // Try the bundles state location first (not available if launched with -data @none).
- try {
- IPath path = Platform.getStateLocation(CoreBundleActivator.getContext().getBundle()).append(".store"); //$NON-NLS-1$
- if (!path.toFile().exists()) path.toFile().mkdirs();
- if (path.toFile().canRead() && path.toFile().isDirectory()) {
- location = path;
- }
- } catch (IllegalStateException e) {
- // Workspace less environments (-data @none)
- // The users local target definition persistence directory is $HOME/.tcf/.store.
- IPath path = new Path(System.getProperty("user.home")).append(".tcf/.store"); //$NON-NLS-1$ //$NON-NLS-2$
- if (!path.toFile().exists()) path.toFile().mkdirs();
- if (path.toFile().canRead() && path.toFile().isDirectory()) {
- location = path;
- }
- }
-
- return location;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getInterfaceType(java.lang.Object)
- */
- @SuppressWarnings("restriction")
- @Override
- public String getInterfaceTypeName(Object data) {
- if (data instanceof IContainerModelNode) {
- return org.eclipse.tcf.te.runtime.model.activator.CoreBundleActivator.getUniqueIdentifier() + ":" + IContainerModelNode.class.getName(); //$NON-NLS-1$
- } else if (data instanceof IModelNode) {
- return org.eclipse.tcf.te.runtime.model.activator.CoreBundleActivator.getUniqueIdentifier() + ":" + IModelNode.class.getName(); //$NON-NLS-1$
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#exportFrom(java.lang.Object)
- */
- @Override
- public Map<String, Object> exportFrom(Object data) throws IOException {
- Assert.isNotNull(data);
-
- // Create a new map instance that will hold the exported properties
- Map<String, Object> result = new HashMap<String, Object>();
-
- // Only model nodes are supported
- if (data instanceof IModelNode && !((IModelNode)data).isEmpty()) {
- // Get a snapshot of all properties
- Map<String, Object> properties = ((IModelNode)data).getProperties();
- // And export the properties to the result map
- exportFromMap(properties, result);
- }
-
- // If the result map is empty, return null
- return !result.isEmpty() ? result : null;
- }
-
- /**
- * Exports the properties of a map from the given source into the given
- * destination.
- *
- * @param src The map to export the properties from. Must not be <code>null</code>.
- * @param dst The map to write the exported properties to. Must not be <code>null</code>.
- *
- * @throws IOException - if the operation fails.
- */
- @SuppressWarnings("unchecked")
- protected void exportFromMap(Map<String, Object> src, Map<String, Object> dst) throws IOException {
- Assert.isNotNull(src);
- Assert.isNotNull(dst);
-
- // Loop all properties and check for transient or complex properties
- for (String key : src.keySet()) {
- if (key.contains(".transient")) continue; //$NON-NLS-1$
-
- // Get the property value
- Object value = src.get(key);
-
- // If the value is null, no need to go any further
- if (value == null) continue;
-
- // For String, Integer, Boolean, etc ... export them as string
- boolean isSimpleType = value instanceof String || value instanceof Boolean || value instanceof Integer || value instanceof Long
- || value instanceof Float || value instanceof Double;
- if (isSimpleType) {
- dst.put(key, value.toString());
- continue;
- }
-
- // BigInteger, BigDecimal ... probably needs special handling, for now, export them as string
- boolean isBigType = value instanceof BigInteger || value instanceof BigDecimal;
- if (isBigType) {
- dst.put(key, value.toString());
- continue;
- }
-
- // For Lists and Arrays, do a deepToString
- boolean isListType = value instanceof List<?> || value instanceof Object[];
- if (isListType) {
- dst.put(key, Arrays.deepToString(value instanceof List<?> ? ((List<?>)value).toArray() : (Object[])value));
- continue;
- }
-
- // For Maps, create a new destination map and call ourself
- boolean isMapType = value instanceof Map<?,?>;
- if (isMapType) {
- Map<String, Object> result = new HashMap<String, Object>();
- exportFromMap((Map<String, Object>)value, result);
- if (!result.isEmpty()) dst.put(key, result);
- continue;
- }
-
- // For anything remaining, check if the value object type can be adapted to
- // an IPersistable itself
- IPersistable persistable = value instanceof IAdaptable ? (IPersistable)((IAdaptable)value).getAdapter(IPersistable.class) : null;
- if (persistable == null) persistable = (IPersistable)Platform.getAdapterManager().getAdapter(value, IPersistable.class);
- if (persistable != null) {
- String storageID = persistable.getStorageID();
- URI uri = persistable.getURI(value);
- String interfaceTypeName = persistable.getInterfaceTypeName(value);
-
- // Check if the persistable returns complete information to create the reference
- if (storageID == null) {
- throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_invalidPersistable, value.getClass().getCanonicalName(), "storageID")); //$NON-NLS-1$
- }
- if (uri == null) {
- throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_invalidPersistable, value.getClass().getCanonicalName(), "uri")); //$NON-NLS-1$
- }
- if (interfaceTypeName == null) {
- throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_invalidPersistable, value.getClass().getCanonicalName(), "interfaceTypeName")); //$NON-NLS-1$
- }
-
- // Create a reference object
- Map<String, String> reference = new HashMap<String, String>();
- reference.put("storageID", storageID); //$NON-NLS-1$
- reference.put("uri", uri.toString()); //$NON-NLS-1$
- reference.put("interfaceType", interfaceTypeName); //$NON-NLS-1$
-
- IPersistenceDelegate delegate = PersistenceDelegateManager.getInstance().getDelegate(storageID, false);
- if (delegate != null) {
- delegate.write(uri, persistable.exportFrom(value));
- dst.put("reference:" + key, reference); //$NON-NLS-1$
- continue;
- }
- }
-
- // Falling through down here is a problem. We should never end up here,
- // because it means we have no idea on how to persist an object
- throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_unknownType, value.getClass().getCanonicalName(), key));
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#importTo(java.lang.Object, java.util.Map)
- */
- @Override
- public void importTo(Object data, Map<String, Object> external) throws IOException {
- Assert.isNotNull(data);
- Assert.isNotNull(external);
-
- // Only model nodes are supported
- if (data instanceof IModelNode) {
- IModelNode node = (IModelNode) data;
- for (String key : external.keySet()) {
- // Get the property value
- Object value = external.get(key);
-
- // Check for reference objects
- if (key.startsWith("reference:") && value instanceof Map<?,?>) { //$NON-NLS-1$
- // Cut the "reference:" from the key
- String newKey = key.substring(10);
-
- @SuppressWarnings("unchecked")
- Map<String, String> reference = (Map<String, String>)value;
-
- // Get the storage id and the URI from the reference
- String storageID = reference.get("storageID"); //$NON-NLS-1$
- String uriString = reference.get("uri"); //$NON-NLS-1$
- String interfaceTypeName = reference.get("interfaceType"); //$NON-NLS-1$
-
- // Check if the reference returns complete information to read the referenced storage
- if (storageID == null) {
- throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_invalidReference, "storageID")); //$NON-NLS-1$
- }
- if (uriString == null) {
- throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_invalidReference, "uri")); //$NON-NLS-1$
- }
- if (interfaceTypeName == null) {
- throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_invalidReference, "interfaceType")); //$NON-NLS-1$
- }
-
- // Get the persistence delegate
- IPersistenceDelegate delegate = PersistenceDelegateManager.getInstance().getDelegate(storageID, false);
- if (delegate != null) {
- URI uri = URI.create(uriString);
- Map<String, Object> referenceData = delegate.read(uri);
- if (referenceData != null && !referenceData.isEmpty()) {
- try {
- // Now, we have to recreate the object
-
- // Separate the bundleId from the interface name
- String[] pieces = interfaceTypeName.split(":", 2); //$NON-NLS-1$
- String bundleId = pieces.length > 1 ? pieces[0] : null;
- if (pieces.length > 1) interfaceTypeName = pieces[1];
-
- // Determine the bundle to use for loading the class
- Bundle bundle = bundleId != null && !"".equals(bundleId.trim()) ? Platform.getBundle(bundleId.trim()) : CoreBundleActivator.getContext().getBundle(); //$NON-NLS-1$
-
- Class<? extends IModelNode> interfaceType = (Class<? extends IModelNode>)bundle.loadClass(interfaceTypeName);
- IModelNode referenceNode = Factory.getInstance().newInstance(interfaceType);
-
- IPersistable persistable = (IPersistable)referenceNode.getAdapter(IPersistable.class);
- if (persistable == null) persistable = (IPersistable)Platform.getAdapterManager().getAdapter(referenceNode, IPersistable.class);
- if (persistable != null) {
- persistable.importTo(referenceNode, referenceData);
- referenceNode.setProperty(IPersistableNodeProperties.PROPERTY_URI, uriString);
- node.setProperty(newKey, referenceNode);
- }
- } catch (ClassNotFoundException e) {
- throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_cannotLoadClass, interfaceTypeName), e);
- }
- }
- }
- }
- // Not a reference object -> store the object as is to the node
- else {
- node.setProperty(key, value);
- }
- }
- }
- }
-
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableURIProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableURIProvider.java
new file mode 100644
index 000000000..727b9088e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableURIProvider.java
@@ -0,0 +1,371 @@
+/*******************************************************************************
+ * 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 java.net.URI;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.tcf.te.core.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNodeProvider;
+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.IPersistableURIProvider;
+
+/**
+ * Model node persistable adapter implementation.
+ */
+public class ModelNodePersistableURIProvider implements IPersistableURIProvider {
+
+ private IModelNode getModelNode(Object context) {
+ IModelNode node = null;
+
+ if (context instanceof IModelNode) {
+ node = (IModelNode)context;
+ }
+ else if (context instanceof IModelNodeProvider) {
+ node = ((IModelNodeProvider)context).getModelNode();
+ }
+
+ return node;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider#getURI(java.lang.Object)
+ */
+ @Override
+ public URI getURI(Object context) {
+ Assert.isNotNull(context);
+
+ URI uri = null;
+
+ IModelNode node = getModelNode(context);
+
+ // Only model nodes are supported
+ if (node != null) {
+
+ IPath path = null;
+
+ // 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())) { //$NON-NLS-1$
+ path = getRoot().append(name.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()));
+ }
+ }
+
+ if (path != null) {
+ if (!"ini".equals(path.getFileExtension())) { //$NON-NLS-1$
+ path = path.addFileExtension("ini"); //$NON-NLS-1$
+ }
+ uri = path.toFile().toURI();
+ }
+ }
+
+ return uri;
+ }
+
+ /**
+ * Make a valid file system name from the given name.
+ *
+ * @param name The original name. Must not be <code>null</code>.
+ * @return The valid file system name.
+ */
+ protected String makeValidFileSystemName(String name) {
+ Assert.isNotNull(name);
+ return name.replaceAll("\\W", "_"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Returns the root location.
+ *
+ * @return The root location or <code>null</code> if it cannot be determined.
+ */
+ protected IPath getRoot() {
+ IPath location = null;
+
+ // Try the bundles state location first (not available if launched with -data @none).
+ try {
+ IPath path = Platform.getStateLocation(CoreBundleActivator.getContext().getBundle()).append(".store"); //$NON-NLS-1$
+ if (!path.toFile().exists()) {
+ path.toFile().mkdirs();
+ }
+ if (path.toFile().canRead() && path.toFile().isDirectory()) {
+ location = path;
+ }
+ } catch (IllegalStateException e) {
+ // Workspace less environments (-data @none)
+ // The users local target definition persistence directory is $HOME/.tcf/.store.
+ IPath path = new Path(System.getProperty("user.home")).append(".tcf/.store"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (!path.toFile().exists()) {
+ path.toFile().mkdirs();
+ }
+ if (path.toFile().canRead() && path.toFile().isDirectory()) {
+ location = path;
+ }
+ }
+
+ return location;
+ }
+ //
+ // /* (non-Javadoc)
+ // * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider#getInterfaceType(java.lang.Object)
+ // */
+ // @SuppressWarnings("restriction")
+ // @Override
+ // public String getInterfaceTypeName(Object data) {
+ // if (data instanceof IContainerModelNode) {
+ // return org.eclipse.tcf.te.runtime.model.activator.CoreBundleActivator.getUniqueIdentifier() + ":" + IContainerModelNode.class.getName(); //$NON-NLS-1$
+ // } else if (data instanceof IModelNode) {
+ // return org.eclipse.tcf.te.runtime.model.activator.CoreBundleActivator.getUniqueIdentifier() + ":" + IModelNode.class.getName(); //$NON-NLS-1$
+ // }
+ // return null;
+ // }
+ //
+ // /* (non-Javadoc)
+ // * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider#exportFrom(java.lang.Object)
+ // */
+ // @Override
+ // public Map<String, Object> exportFrom(Object data) throws IOException {
+ // Assert.isNotNull(data);
+ //
+ // // Create a new map instance that will hold the exported properties
+ // Map<String, Object> result = new HashMap<String, Object>();
+ //
+ // // Only model nodes are supported
+ // if (data instanceof IModelNode && !((IModelNode)data).isEmpty()) {
+ // // Get a snapshot of all properties
+ // Map<String, Object> properties = ((IModelNode)data).getProperties();
+ // // And export the properties to the result map
+ // exportFromMap(properties, result);
+ // }
+ //
+ // // If the result map is empty, return null
+ // return !result.isEmpty() ? result : null;
+ // }
+ //
+ // /**
+ // * Exports the properties of a map from the given source into the given
+ // * destination.
+ // *
+ // * @param src The map to export the properties from. Must not be <code>null</code>.
+ // * @param dst The map to write the exported properties to. Must not be <code>null</code>.
+ // *
+ // * @throws IOException - if the operation fails.
+ // */
+ // @SuppressWarnings("unchecked")
+ // protected void exportFromMap(Map<String, Object> src, Map<String, Object> dst) throws IOException {
+ // Assert.isNotNull(src);
+ // Assert.isNotNull(dst);
+ //
+ // // Loop all properties and check for transient or complex properties
+ // for (String key : src.keySet()) {
+ // if (key.contains(".transient"))
+ // {
+ // continue; //$NON-NLS-1$
+ // }
+ //
+ // // Get the property value
+ // Object value = src.get(key);
+ //
+ // // If the value is null, no need to go any further
+ // if (value == null) {
+ // continue;
+ // }
+ //
+ // // For String, Integer, Boolean, etc ... export them as string
+ // boolean isSimpleType = value instanceof String || value instanceof Boolean || value instanceof Integer || value instanceof Long
+ // || value instanceof Float || value instanceof Double;
+ // if (isSimpleType) {
+ // dst.put(key, value.toString());
+ // continue;
+ // }
+ //
+ // // BigInteger, BigDecimal ... probably needs special handling, for now, export them as string
+ // boolean isBigType = value instanceof BigInteger || value instanceof BigDecimal;
+ // if (isBigType) {
+ // dst.put(key, value.toString());
+ // continue;
+ // }
+ //
+ // // For Lists and Arrays, do a deepToString
+ // boolean isListType = value instanceof List<?> || value instanceof Object[];
+ // if (isListType) {
+ // dst.put(key, Arrays.deepToString(value instanceof List<?> ? ((List<?>)value).toArray() : (Object[])value));
+ // continue;
+ // }
+ //
+ // // For Maps, create a new destination map and call ourself
+ // boolean isMapType = value instanceof Map<?,?>;
+ // if (isMapType) {
+ // Map<String, Object> result = new HashMap<String, Object>();
+ // exportFromMap((Map<String, Object>)value, result);
+ // if (!result.isEmpty()) {
+ // dst.put(key, result);
+ // }
+ // continue;
+ // }
+ //
+ // // For anything remaining, check if the value object type can be adapted to
+ // // an IPersistableURIProvider itself
+ // IPersistableURIProvider persistableURIProvider = value instanceof IAdaptable ? (IPersistableURIProvider)((IAdaptable)value).getAdapter(IPersistableURIProvider.class) : null;
+ // if (persistableURIProvider == null) {
+ // persistableURIProvider = (IPersistableURIProvider)Platform.getAdapterManager().getAdapter(value, IPersistableURIProvider.class);
+ // }
+ // if (persistableURIProvider != null) {
+ // String storageID = persistableURIProvider.getStorageID();
+ // URI uri = persistableURIProvider.getURI(value);
+ // String interfaceTypeName = persistableURIProvider.getInterfaceTypeName(value);
+ //
+ // // Check if the persistable returns complete information to create the reference
+ // if (storageID == null) {
+ // throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_invalidPersistable, value.getClass().getCanonicalName(), "storageID")); //$NON-NLS-1$
+ // }
+ // if (uri == null) {
+ // throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_invalidPersistable, value.getClass().getCanonicalName(), "uri")); //$NON-NLS-1$
+ // }
+ // if (interfaceTypeName == null) {
+ // throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_invalidPersistable, value.getClass().getCanonicalName(), "interfaceTypeName")); //$NON-NLS-1$
+ // }
+ //
+ // // Create a reference object
+ // Map<String, String> reference = new HashMap<String, String>();
+ // reference.put("storageID", storageID); //$NON-NLS-1$
+ // reference.put("uri", uri.toString()); //$NON-NLS-1$
+ // reference.put("interfaceType", interfaceTypeName); //$NON-NLS-1$
+ //
+ // IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(storageID, false);
+ // if (delegate != null) {
+ // delegate.write(uri, persistableURIProvider.exportFrom(value));
+ // dst.put("reference:" + key, reference); //$NON-NLS-1$
+ // continue;
+ // }
+ // }
+ //
+ // // Falling through down here is a problem. We should never end up here,
+ // // because it means we have no idea on how to persist an object
+ // throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_unknownType, value.getClass().getCanonicalName(), key));
+ // }
+ // }
+ //
+ // /* (non-Javadoc)
+ // * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider#importTo(java.lang.Object, java.util.Map)
+ // */
+ // @Override
+ // public void importTo(Object data, Map<String, Object> external) throws IOException {
+ // Assert.isNotNull(data);
+ // Assert.isNotNull(external);
+ //
+ // // Only model nodes are supported
+ // if (data instanceof IModelNode) {
+ // IModelNode node = (IModelNode) data;
+ // for (String key : external.keySet()) {
+ // // Get the property value
+ // Object value = external.get(key);
+ //
+ // // Check for reference objects
+ // if (key.startsWith("reference:") && value instanceof Map<?,?>) { //$NON-NLS-1$
+ // // Cut the "reference:" from the key
+ // String newKey = key.substring(10);
+ //
+ // @SuppressWarnings("unchecked")
+ // Map<String, String> reference = (Map<String, String>)value;
+ //
+ // // Get the storage id and the URI from the reference
+ // String storageID = reference.get("storageID"); //$NON-NLS-1$
+ // String uriString = reference.get("uri"); //$NON-NLS-1$
+ // String interfaceTypeName = reference.get("interfaceType"); //$NON-NLS-1$
+ //
+ // // Check if the reference returns complete information to read the referenced storage
+ // if (storageID == null) {
+ // throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_invalidReference, "storageID")); //$NON-NLS-1$
+ // }
+ // if (uriString == null) {
+ // throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_invalidReference, "uri")); //$NON-NLS-1$
+ // }
+ // if (interfaceTypeName == null) {
+ // throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_invalidReference, "interfaceType")); //$NON-NLS-1$
+ // }
+ //
+ // // Get the persistence delegate
+ // IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(storageID, false);
+ // if (delegate != null) {
+ // URI uri = URI.create(uriString);
+ // Map<String, Object> referenceData = delegate.read(uri);
+ // if (referenceData != null && !referenceData.isEmpty()) {
+ // try {
+ // // Now, we have to recreate the object
+ //
+ // // Separate the bundleId from the interface name
+ // String[] pieces = interfaceTypeName.split(":", 2); //$NON-NLS-1$
+ // String bundleId = pieces.length > 1 ? pieces[0] : null;
+ // if (pieces.length > 1) {
+ // interfaceTypeName = pieces[1];
+ // }
+ //
+ // // Determine the bundle to use for loading the class
+ // Bundle bundle = bundleId != null && !"".equals(bundleId.trim()) ? Platform.getBundle(bundleId.trim()) : CoreBundleActivator.getContext().getBundle(); //$NON-NLS-1$
+ //
+ // Class<? extends IModelNode> interfaceType = (Class<? extends IModelNode>)bundle.loadClass(interfaceTypeName);
+ // IModelNode referenceNode = Factory.getInstance().newInstance(interfaceType);
+ //
+ // IPersistableURIProvider persistableURIProvider = (IPersistableURIProvider)referenceNode.getAdapter(IPersistableURIProvider.class);
+ // if (persistableURIProvider == null) {
+ // persistableURIProvider = (IPersistableURIProvider)Platform.getAdapterManager().getAdapter(referenceNode, IPersistableURIProvider.class);
+ // }
+ // if (persistableURIProvider != null) {
+ // persistableURIProvider.importTo(referenceNode, referenceData);
+ // referenceNode.setProperty(IPersistableNodeProperties.PROPERTY_URI, uriString);
+ // node.setProperty(newKey, referenceNode);
+ // }
+ // } catch (ClassNotFoundException e) {
+ // throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_cannotLoadClass, interfaceTypeName), e);
+ // }
+ // }
+ // }
+ // }
+ // // Not a reference object -> store the object as is to the node
+ // else {
+ // node.setProperty(key, value);
+ // }
+ // }
+ // }
+ // }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF
index ba537ff4e..ed1b91c01 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF
@@ -25,6 +25,7 @@ Export-Package: org.eclipse.tcf.te.launch.core.activator;x-internal:=true,
org.eclipse.tcf.te.launch.core.bindings.internal;x-friends:="org.eclipse.tcf.te.launch.ui",
org.eclipse.tcf.te.launch.core.delegates,
org.eclipse.tcf.te.launch.core.exceptions,
+ org.eclipse.tcf.te.launch.core.interfaces,
org.eclipse.tcf.te.launch.core.interfaces.tracing,
org.eclipse.tcf.te.launch.core.lm,
org.eclipse.tcf.te.launch.core.lm.delegates,
@@ -32,6 +33,9 @@ Export-Package: org.eclipse.tcf.te.launch.core.activator;x-internal:=true,
org.eclipse.tcf.te.launch.core.lm.internal;x-internal:=true,
org.eclipse.tcf.te.launch.core.nls;x-internal:=true,
org.eclipse.tcf.te.launch.core.persistence,
+ org.eclipse.tcf.te.launch.core.persistence.filetransfer,
+ org.eclipse.tcf.te.launch.core.persistence.launchcontext,
+ org.eclipse.tcf.te.launch.core.persistence.projects,
org.eclipse.tcf.te.launch.core.preferences,
org.eclipse.tcf.te.launch.core.selection,
org.eclipse.tcf.te.launch.core.selection.interfaces,
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java
index 1e737fa4e..e8d70edc3 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java
@@ -32,12 +32,13 @@ import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
import org.eclipse.tcf.te.launch.core.bindings.LaunchConfigTypeBindingsManager;
+import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem;
import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes;
import org.eclipse.tcf.te.launch.core.lm.interfaces.IContextSelectorLaunchAttributes;
import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
import org.eclipse.tcf.te.launch.core.nls.Messages;
-import org.eclipse.tcf.te.launch.core.persistence.ContextSelectorPersistenceDelegate;
-import org.eclipse.tcf.te.launch.core.persistence.DefaultPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.launchcontext.LaunchContextsPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectsPersistenceDelegate;
import org.eclipse.tcf.te.runtime.concurrent.util.ExecutorsUtil;
import org.eclipse.tcf.te.runtime.interfaces.ISharedConstants;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
@@ -116,7 +117,7 @@ public class LaunchConfigurationDelegate extends AbstractLaunchConfigurationDele
launchConfig.getType().getIdentifier(),
launch.getLaunchMode()));
- IModelNode[] contexts = ContextSelectorPersistenceDelegate.decodeLaunchContexts(
+ IModelNode[] contexts = LaunchContextsPersistenceDelegate.decodeLaunchContexts(
launchConfig.getAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String)null));
properties.setProperty(IContextSelectorLaunchAttributes.ATTR_ACTIVE_LAUNCH_CONTEXT, contexts != null && contexts.length > 0 ? contexts[0] : null);
@@ -213,9 +214,12 @@ public class LaunchConfigurationDelegate extends AbstractLaunchConfigurationDele
// Return the projects to build within the order the user configured within
// the corresponding UI launch tab.
- List<String> projectNames = (List<String>)DefaultPersistenceDelegate.getAttribute(configuration, ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD, (List<?>)null);
- if (projectNames != null) {
- projects.addAll(findProjectResources(projectNames));
+ IReferencedProjectItem[] items = ReferencedProjectsPersistenceDelegate.getReferencedProjects(configuration);
+ for (IReferencedProjectItem item : items) {
+ if (item.isProperty(IReferencedProjectItem.PROPERTY_ENABLED, true) && item.getStringProperty(IReferencedProjectItem.PROPERTY_PROJECT_NAME) != null) {
+ IProject project = findProjectResource(item.getStringProperty(IReferencedProjectItem.PROPERTY_PROJECT_NAME));
+ projects.add(project);
+ }
}
// If the list of projects is not empty, we have to check for duplicates
@@ -227,36 +231,27 @@ public class LaunchConfigurationDelegate extends AbstractLaunchConfigurationDele
}
/**
- * Lookup the corresponding project resources for the given list of project
- * names. If one of the referenced projects cannot be found or is closed,
- * a {@link CoreException} will be thrown.
+ * Lookup the corresponding project resource for the given project name.
+ * If the referenced project cannot be found or is closed, a {@link CoreException} will be thrown.
*
- * @param projectNames The list of project names. Must be not <code>null</code>.
- * @return The list of project resources or an empty list.
+ * @param projectName The project name. Must be not <code>null</code>.
+ * @return The project resource or <code>null</code>.
*/
- protected List<IProject> findProjectResources(List<String> projectNames) throws CoreException {
- Assert.isNotNull(projectNames);
-
- List<IProject> projects = new ArrayList<IProject>();
+ protected IProject findProjectResource(String projectName) throws CoreException {
+ Assert.isNotNull(projectName);
// Project resources are stored with the workspace root
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- for (String projectName : projectNames) {
- // Query the project resource from the workspace root.
- IProject project = root.getProject(projectName);
- if (!project.isAccessible()) {
- // Not accessible -> means the project does either not exist or
- // is closed.
- throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- NLS.bind(Messages.LaunchConfigurationDelegate_error_inaccessibleReferencedProject, projectName)
- ));
- }
-
- // add the project resource to the list
- projects.add(project);
+ IProject project = root.getProject(projectName);
+ if (project != null && !project.isAccessible()) {
+ // Not accessible -> means the project does either not exist or
+ // is closed.
+ throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ NLS.bind(Messages.LaunchConfigurationDelegate_error_inaccessibleReferencedProject, projectName)
+ ));
}
- return projects;
+ return project;
}
/**
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/IFileTransferItem.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/IFileTransferItem.java
new file mode 100644
index 000000000..43ef6f630
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/IFileTransferItem.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.interfaces;
+
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+
+/**
+ * IFileTransferItem
+ * @author tobias.schwarz@windriver.com
+ */
+public interface IFileTransferItem extends IPropertiesContainer {
+
+ public static final String PROPERTY_ENABLED = "enabled"; //$NON-NLS-1$
+ public static final String PROPERTY_DIRECTION = "direction"; //$NON-NLS-1$
+ public static final String PROPERTY_HOST = "host"; //$NON-NLS-1$
+ public static final String PROPERTY_TARGET = "target"; //$NON-NLS-1$
+ public static final String PROPERTY_OPTIONS = "options"; //$NON-NLS-1$
+
+ public static final int HOST_TO_TARGET = 1;
+ public static final int TARGET_TO_HOST = 2;
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/IReferencedProjectItem.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/IReferencedProjectItem.java
new file mode 100644
index 000000000..351d3aab3
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/IReferencedProjectItem.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.interfaces;
+
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+
+/**
+ * IFileTransferItem
+ * @author tobias.schwarz@windriver.com
+ */
+public interface IReferencedProjectItem extends IPropertiesContainer {
+
+ public static final String PROPERTY_ENABLED = "enabled"; //$NON-NLS-1$
+ public static final String PROPERTY_PROJECT_NAME = "project_name"; //$NON-NLS-1$
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/delegates/DefaultLaunchManagerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/delegates/DefaultLaunchManagerDelegate.java
index 9c621a2da..6728aa7a3 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/delegates/DefaultLaunchManagerDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/delegates/DefaultLaunchManagerDelegate.java
@@ -28,10 +28,10 @@ import org.eclipse.tcf.te.launch.core.exceptions.LaunchServiceException;
import org.eclipse.tcf.te.launch.core.interfaces.tracing.ITraceIds;
import org.eclipse.tcf.te.launch.core.lm.LaunchConfigSorter;
import org.eclipse.tcf.te.launch.core.lm.LaunchSpecification;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes;
import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchAttribute;
import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IReferencedProjectLaunchAttributes;
import org.eclipse.tcf.te.launch.core.nls.Messages;
import org.eclipse.tcf.te.launch.core.preferences.IPreferenceKeys;
import org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection;
@@ -615,7 +615,7 @@ public class DefaultLaunchManagerDelegate extends ExecutableExtension implements
Assert.isNotNull(specValue);
Assert.isNotNull(confValue);
- if (ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD.equals(attributeKey)) {
+ if (IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS.equals(attributeKey)) {
// get match of list objects
int match = specValue.equals(confValue) ? FULL_MATCH : NO_MATCH;
// compare objects in the list when they are not already equal
@@ -623,13 +623,6 @@ public class DefaultLaunchManagerDelegate extends ExecutableExtension implements
List<?> specProject = (List<?>) specValue;
List<?> confProject = (List<?>) confValue;
match = (specProject.isEmpty() || confProject.isEmpty()) ? PARTIAL_MATCH : NO_MATCH;
- List<?> refProjects = null;
- try {
- refProjects = launchConfig.getAttribute(ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, (List<?>) null);
- }
- catch (CoreException e) {
- // ignore
- }
for (int i = 0; i < specProject.size(); i++) {
Object specObject = specProject.get(i);
if (specObject != null && confProject.contains(specObject)) {
@@ -640,12 +633,6 @@ public class DefaultLaunchManagerDelegate extends ExecutableExtension implements
match = (i == 0) ? FULL_MATCH : PARTIAL_MATCH;
}
}
- else if (specObject != null && refProjects != null && refProjects.contains(specObject)) {
- // spec object can be found in the configuration
- if (match == NO_MATCH) {
- match = PARTIAL_MATCH;
- }
- }
else if (match == FULL_MATCH) {
// reduce full to partial match when spec object wasn't found
match = PARTIAL_MATCH;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java
index 525754897..85caec4a9 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java
@@ -20,16 +20,6 @@ public interface ICommonLaunchAttributes {
public static final String ATTR_PREFIX = "org.eclipse.tcf.te.launch"; //$NON-NLS-1$
/**
- * Launch configuration attribute: List of projects which must be build before executing the launch.
- */
- public static final String ATTR_PROJECTS_FOR_BUILD = ATTR_PREFIX + ".projectsForBuild"; //$NON-NLS-1$
-
- /**
- * Launch configuration attribute: List of referenced projects.
- */
- public static final String ATTR_REFERENCED_PROJECTS = ATTR_PREFIX + ".referencedProjects"; //$NON-NLS-1$
-
- /**
* Time stamp when last launched.
*/
public static final String ATTR_LAST_LAUNCHED = ATTR_PREFIX + ".lastLaunched"; //$NON-NLS-1$
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IFileTransferLaunchAttributes.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IFileTransferLaunchAttributes.java
new file mode 100644
index 000000000..79acc14d1
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IFileTransferLaunchAttributes.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.lm.interfaces;
+
+/**
+ * Defines the launch configuration attribute id's to access the launch step contexts.
+ */
+public interface IFileTransferLaunchAttributes {
+
+ /**
+ * Launch configuration attribute: The file transfer items the launch is operating with. Use
+ * {@link FileTransferPersistanceDelegate} to access
+ * this attribute within a launch configuration.
+ */
+ public static final String ATTR_FILE_TRANSFERS = ICommonLaunchAttributes.ATTR_PREFIX + ".file_transfers"; //$NON-NLS-1$
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IReferencedProjectLaunchAttributes.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IReferencedProjectLaunchAttributes.java
new file mode 100644
index 000000000..23b52749d
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IReferencedProjectLaunchAttributes.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.lm.interfaces;
+
+/**
+ * Defines the launch configuration attribute id's to access the launch step contexts.
+ */
+public interface IReferencedProjectLaunchAttributes {
+
+ /**
+ * Launch configuration attribute: The referenced project items the launch is operating with. Use
+ * {@link ReferencedProjectsPersistanceDelegate} to access
+ * this attribute within a launch configuration.
+ */
+ public static final String ATTR_REFERENCED_PROJECTS = ICommonLaunchAttributes.ATTR_PREFIX + ".referencedProjects"; //$NON-NLS-1$
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java
index d895dcfdc..e9b3a5b7a 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java
@@ -1,45 +1,56 @@
-/*******************************************************************************
- * 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.launch.core.nls;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Launch Core Plug-in externalized strings management.
- */
-public class Messages extends NLS {
-
- // The plug-in resource bundle name
- private static final String BUNDLE_NAME = "org.eclipse.tcf.te.launch.core.nls.Messages"; //$NON-NLS-1$
-
- /**
- * Static constructor.
- */
- static {
- // Load message values from bundle file
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- // **** Declare externalized string id's down here *****
-
- public static String DefaultLaunchManagerDelegate_defaultLaunchName;
-
- public static String LaunchManager_error_invalidExtensionPoint;
- public static String LaunchManager_error_noLaunchConfigType;
- public static String LaunchManager_error_failedToCreateConfig;
- public static String LaunchManager_error_failedToUpdateConfig;
- public static String LaunchManager_error_deleteLaunchConfig;
-
- public static String LaunchConfigurationDelegate_error_failedToGetStepper;
- public static String LaunchConfigurationDelegate_error_failedToCloneStepper;
- public static String LaunchConfigurationDelegate_error_inaccessibleReferencedProject;
-
- public static String AbstractLaunchConfigurationDelegate_scoped_incremental_build;
-}
+/*******************************************************************************
+ * 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.launch.core.nls;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Launch Core Plug-in externalized strings management.
+ */
+public class Messages extends NLS {
+
+ // The plug-in resource bundle name
+ private static final String BUNDLE_NAME = "org.eclipse.tcf.te.launch.core.nls.Messages"; //$NON-NLS-1$
+
+ /**
+ * Static constructor.
+ */
+ static {
+ // Load message values from bundle file
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ // **** Declare externalized string id's down here *****
+
+ public static String DefaultLaunchManagerDelegate_defaultLaunchName;
+
+ public static String LaunchManager_error_invalidExtensionPoint;
+ public static String LaunchManager_error_noLaunchConfigType;
+ public static String LaunchManager_error_failedToCreateConfig;
+ public static String LaunchManager_error_failedToUpdateConfig;
+ public static String LaunchManager_error_deleteLaunchConfig;
+
+ public static String LaunchConfigurationDelegate_error_failedToGetStepper;
+ public static String LaunchConfigurationDelegate_error_failedToCloneStepper;
+ public static String LaunchConfigurationDelegate_error_inaccessibleReferencedProject;
+
+ public static String AbstractLaunchConfigurationDelegate_scoped_incremental_build;
+
+ public static String FileTransferItemValidator_missingFile;
+ public static String FileTransferItemValidator_missingFileOrDirectory;
+ public static String FileTransferItemValidator_notExistingFile;
+ public static String FileTransferItemValidator_notExistingFileOrDirectory;
+ public static String FileTransferItemValidator_invalidFile;
+ public static String FileTransferItemValidator_invalidFileOrDirectory;
+
+ public static String ReferencedProjectItemValidator_missingProject;
+ public static String ReferencedProjectItemValidator_notExistingProject;
+ public static String ReferencedProjectItemValidator_closedProject;
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties
index 844f15224..64c16b153 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties
@@ -1,20 +1,31 @@
-#
-# org.eclipse.tcf.te.launch.core
-# Externalized Strings.
-#
-
-DefaultLaunchManagerDelegate_defaultLaunchName=New configuration
-
-LaunchManager_error_invalidExtensionPoint=Failed to instantiate the executable extension from extension point ''{0}''.
-LaunchManager_error_noLaunchConfigType=No launch configuration type (id = ) is available for launch mode ''{0}''.
-LaunchManager_error_failedToCreateConfig=Failed to create and initialize new launch configuration.
-LaunchManager_error_failedToUpdateConfig=Failed to update existing launch configuration ''{0}''.
-LaunchManager_error_deleteLaunchConfig=Failed to delete launch configuration.
-
-LaunchConfigurationDelegate_error_failedToGetStepper=Failed to access stepper for launch configuration type ''{0}'' \
-and launch mode ''{1}''.
-LaunchConfigurationDelegate_error_failedToCloneStepper=Failed to clone stepper for launch configuration type ''{0}'' \
-and launch mode ''{1}''.
-LaunchConfigurationDelegate_error_inaccessibleReferencedProject=Failed to access project ''{0}''. The project is either missing or closed.
-
-AbstractLaunchConfigurationDelegate_scoped_incremental_build=Scoped incremental build before launch...
+#
+# org.eclipse.tcf.te.launch.core
+# Externalized Strings.
+#
+
+DefaultLaunchManagerDelegate_defaultLaunchName=New configuration
+
+LaunchManager_error_invalidExtensionPoint=Failed to instantiate the executable extension from extension point ''{0}''.
+LaunchManager_error_noLaunchConfigType=No launch configuration type (id = ) is available for launch mode ''{0}''.
+LaunchManager_error_failedToCreateConfig=Failed to create and initialize new launch configuration.
+LaunchManager_error_failedToUpdateConfig=Failed to update existing launch configuration ''{0}''.
+LaunchManager_error_deleteLaunchConfig=Failed to delete launch configuration.
+
+LaunchConfigurationDelegate_error_failedToGetStepper=Failed to access stepper for launch configuration type ''{0}'' \
+and launch mode ''{1}''.
+LaunchConfigurationDelegate_error_failedToCloneStepper=Failed to clone stepper for launch configuration type ''{0}'' \
+and launch mode ''{1}''.
+LaunchConfigurationDelegate_error_inaccessibleReferencedProject=Failed to access project ''{0}''. The project is either missing or closed.
+
+AbstractLaunchConfigurationDelegate_scoped_incremental_build=Scoped incremental build before launch...
+
+FileTransferItemValidator_missingFile = Missing file
+FileTransferItemValidator_missingFileOrDirectory = Missing file or directory
+FileTransferItemValidator_notExistingFile = File does not exist or is not readable
+FileTransferItemValidator_notExistingFileOrDirectory = File or directory does not exist or is not writeable
+FileTransferItemValidator_invalidFile = File is not valid
+FileTransferItemValidator_invalidFileOrDirectory = File or directory is not valid
+
+ReferencedProjectItemValidator_missingProject = Missing project
+ReferencedProjectItemValidator_notExistingProject = Project does not exist
+ReferencedProjectItemValidator_closedProject = Project is closed
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/AbstractItemListPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/AbstractItemListPersistenceDelegate.java
new file mode 100644
index 000000000..ea74b65b0
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/AbstractItemListPersistenceDelegate.java
@@ -0,0 +1,274 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.persistence;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.runtime.persistence.PersistenceManager;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+
+/**
+ * Item list persistence delegate.
+ */
+public abstract class AbstractItemListPersistenceDelegate<ItemType> {
+
+ private final String tagName;
+ private final String key;
+
+ public AbstractItemListPersistenceDelegate(String tagName, String key) {
+ super();
+
+ Assert.isNotNull(tagName);
+ Assert.isNotNull(key);
+ this.tagName = tagName;
+ this.key = key;
+ }
+
+ /**
+ * Saves the selectedr items to the specified launch configuration working copy. If the
+ * selected items are <code>null</code> or empty, the attribute will be removed from
+ * the specified launch configuration working copy.
+ * @param <ItemType>
+ *
+ * @param wc The launch configuration working copy. Must not be <code>null</code>.
+ * @param items The items to save or <code>null</code>.
+ */
+ public final void setItems(ILaunchConfigurationWorkingCopy wc, ItemType[] items) {
+ Assert.isNotNull(wc);
+
+ if (items == null || items.length == 0) {
+ DefaultPersistenceDelegate.setAttribute(wc, key, (String)null);
+ return;
+ }
+
+ // Get the encoded XML representation
+ String xml = encodeItems(items);
+ // And save them to the launch configuration. If XML == null, the
+ // items will be removed from the launch configuration
+ DefaultPersistenceDelegate.setAttribute(wc, key, xml);
+ }
+
+ /**
+ * Saves the selected items to the specified launch specification. If the selected
+ * items are <code>null</code> or empty, the attribute will be removed from the
+ * specified launch specification.
+ *
+ * @param launchSpec The launch specification. Must not be <code>null</code>.
+ * @param items The items to save or <code>null</code>.
+ */
+ public final void setItems(ILaunchSpecification launchSpec, ItemType[] items) {
+ Assert.isNotNull(launchSpec);
+
+ if (items == null || items.length == 0) {
+ launchSpec.removeAttribute(key);
+ return;
+ }
+
+ // Get the encoded XML representation
+ String xml = encodeItems(items);
+ // And save them to the launch specification. If XML == null, the
+ // items will be removed from the launch specification
+ launchSpec.addAttribute(key, xml);
+ }
+
+ /**
+ * Writes the given items into a string encoded in XML.
+ *
+ * @param items The items to encode. Must not be <code>null</code>.
+ * @return The full XML representation of the given items or <code>null</code>.
+ */
+ public final String encodeItems(ItemType[] items) {
+ Assert.isNotNull(items);
+
+ // The final result
+ String result = null;
+
+ // First, we write the selected items as XML representation into a string
+ StringWriter writer = new StringWriter();
+
+ try {
+ // Write the header and get the initial indentation
+ String indentation = writeHeader(writer);
+ // Iterate over the given selected items and write them out.
+ for (ItemType item : items) {
+ writeItem(writer, indentation, item);
+ }
+ // Write the footer
+ writeFooter(writer);
+
+ // Convert into a string
+ result = writer.toString();
+ }
+ catch (IOException e) {
+ // Export to the string writer failed --> remove attribute from launch configuration
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ result = null;
+ }
+ finally {
+ try {
+ writer.close();
+ }
+ catch (IOException e) { /* ignored on purpose */
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Writes the header to the given writer and returns the indentation to be used for following
+ * elements.
+ *
+ * @param writer The writer instance. Must not be <code>null</code>.
+ * @throws IOException in case the write failed.
+ */
+ private String writeHeader(Writer writer) throws IOException {
+ Assert.isNotNull(writer);
+ writer.write("<" + tagName + "s>\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ return "\t"; //$NON-NLS-1$
+ }
+
+ /**
+ * Writes the footer to the given writer and returns the indentation to be used for following
+ * elements.
+ *
+ * @param writer The writer instance. Must not be <code>null</code>.
+ * @throws IOException in case the write failed.
+ */
+ private String writeFooter(Writer writer) throws IOException {
+ Assert.isNotNull(writer);
+ writer.write("</" + tagName + "s>\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Writes the item to the given writer.
+ *
+ * @param writer The writer instance. Must not be <code>null</code>.
+ * @param indentation The indentation to prefix each exported line with. Must not be <code>null</code>.
+ * @param item The item instance. Must not be <code>null</code>.
+ *
+ * @throws IOException in case the write failed.
+ */
+ private void writeItem(Writer writer, String indentation, ItemType item) throws IOException {
+ Assert.isNotNull(writer);
+ Assert.isNotNull(indentation);
+ Assert.isNotNull(item);
+
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(item, String.class, false);
+ if (delegate != null) {
+ writer.write(indentation + "<" + tagName + " " + AbstractItemListXMLParser.ATTR_TYPE + "=\"" + delegate.getPersistedClass(item).getName() + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ writer.write(indentation + "\t" + delegate.write(item, String.class, null) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ writer.write(indentation + "</" + tagName + ">\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ /**
+ * Reads the selected items from the given XML encoded string.
+ *
+ * @param encodedItems The selected items encoded as XML string. Must not be <code>null</code>.
+ * @return The selected items or an empty array.
+ */
+ public final List<ItemType> decodeItems(String encodedItems) {
+ Assert.isNotNull(encodedItems);
+
+ List<ItemType> items = new ArrayList<ItemType>();
+
+ if (!"".equals(encodedItems.trim())) { //$NON-NLS-1$
+ // We have to parse the items from the string
+ InputStream input = new ByteArrayInputStream(encodedItems.getBytes());
+ // Instantiate the XML parser
+ AbstractItemListXMLParser<ItemType> xmlParser = getXMLParser();
+ xmlParser.initXMLParser();
+ xmlParser.setItems(items);
+ try {
+ xmlParser.getXMLReader().parse(input, xmlParser);
+ }
+ catch (Exception e) {
+ // Import failed --> remove attribute from launch configuration
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ items = null;
+ }
+ }
+
+ return items;
+ }
+
+ protected abstract AbstractItemListXMLParser<ItemType> getXMLParser();
+
+ /**
+ * Returns the list of configured items from the given launch configuration.
+ * <p>
+ * If the given launch configuration is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param configuration The launch configuration or <code>null</code>.
+ * @param ItemType
+ * @return The list of configured items or an empty array.
+ */
+ public final List<ItemType> getItems(ILaunchConfiguration configuration) {
+ List<ItemType> items = new ArrayList<ItemType>();
+
+ if (configuration != null) {
+ // Read the attribute from the launch configuration
+ String encodedItems = DefaultPersistenceDelegate.getAttribute(configuration, key, (String) null);
+ if (encodedItems != null) {
+ items = decodeItems(encodedItems);
+ }
+ }
+
+ return items;
+ }
+
+ /**
+ * Returns the list of configured items from the given launch specification.
+ * <p>
+ * If the given launch specification is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param launchSpec The launch specification or <code>null</code>.
+ * @return The list of configured items or an empty array.
+ */
+ public final List<ItemType> getItems(ILaunchSpecification launchSpec) {
+ List<ItemType> items = new ArrayList<ItemType>();
+
+ if (launchSpec != null) {
+ // Read the attribute from the launch specification
+ String encodedItems = (String) launchSpec.getAttribute(key, null);
+ if (encodedItems != null) {
+ items = decodeItems(encodedItems);
+ }
+ }
+
+ return items;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/AbstractItemListXMLParser.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/AbstractItemListXMLParser.java
new file mode 100644
index 000000000..58cef2f06
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/AbstractItemListXMLParser.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.persistence;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.runtime.persistence.PersistenceManager;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.osgi.framework.Bundle;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * AbstractItemListXMLParser
+ * @author tobias.schwarz@windriver.com
+ */
+public abstract class AbstractItemListXMLParser<ItemType> extends DefaultHandler {
+ private final int IN_ITEMS_DEFINITION = 1;
+ private final int IN_ITEM_DEFINITION = 2;
+
+ private SAXParser parser;
+
+ private int parseState;
+ private String lastData;
+ private String lastType;
+ private List<ItemType> items;
+
+ private final String containerTag;
+ private final String itemTag;
+
+ public static final String ATTR_TYPE = "type"; //$NON-NLS-1$
+
+ /**
+ * Constructor
+ */
+ public AbstractItemListXMLParser(String tagName) {
+ super();
+ Assert.isNotNull(tagName);
+
+ containerTag = tagName + "s"; //$NON-NLS-1$
+ itemTag = tagName;
+
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(false);
+ factory.setValidating(false);
+ try {
+ parser = factory.newSAXParser();
+ }
+ catch (ParserConfigurationException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getClass().getName(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ catch (SAXException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getClass().getName(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+
+ /**
+ * Returns the associated XML parser instance.
+ */
+ public SAXParser getXMLReader() {
+ return parser;
+ }
+
+ /**
+ * Reset the XML parser to a defined start point.
+ */
+ public void initXMLParser() {
+ parseState = 0;
+ lastData = null;
+ lastType = null;
+ items = null;
+ }
+
+ /**
+ * Associate the list instance to store the identified contexts.
+ */
+ public void setItems(List<ItemType> items) {
+ this.items = items;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public void endElement(String uri, String localName, String name) throws SAXException {
+ if (containerTag.equalsIgnoreCase(name) && (parseState & IN_ITEMS_DEFINITION) == IN_ITEMS_DEFINITION) {
+ parseState ^= IN_ITEMS_DEFINITION;
+ }
+ if (itemTag.equalsIgnoreCase(name) && (parseState & IN_ITEM_DEFINITION) == IN_ITEM_DEFINITION) {
+ parseState ^= IN_ITEM_DEFINITION;
+
+ // The item encoded string is in last data
+ if (lastType != null && lastData != null) {
+ Class<IModelNode> clazz = null;
+ try {
+ clazz = (Class<IModelNode>)CoreBundleActivator.getContext().getBundle().loadClass(lastType);
+ } catch (ClassNotFoundException e) {
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.WARNING, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+
+ // If the class could not be loaded by our own bundle class loader, try to find
+ // the bundle from the class name and try to load the class through the bundle.
+ if (clazz == null) {
+ String bundleId = lastType;
+ Bundle bundle = null;
+ while (bundleId != null && bundle == null) {
+ bundle = Platform.getBundle(bundleId);
+ if (bundle == null) {
+ int i = bundleId.lastIndexOf('.');
+ if (i != -1) {
+ bundleId = bundleId.substring(0, i);
+ } else {
+ bundleId = null;
+ }
+ }
+ }
+
+ if (bundle != null) {
+ try {
+ clazz = (Class<IModelNode>)bundle.loadClass(lastType);
+ } catch (ClassNotFoundException e) {
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+ }
+ }
+
+ if (clazz != null) {
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(clazz, lastData, false);
+ if (delegate != null) {
+ try {
+ ItemType item = (ItemType)delegate.read(getReadClass(), lastData, null);
+ if (!items.contains(item)) {
+ items.add(item);
+ }
+ }
+ catch (IOException e) {
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected abstract Class<?> getReadClass();
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ @Override
+ public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
+ // Each time we start a new element, throw away the lastData content
+ lastData = null;
+
+ if (containerTag.equalsIgnoreCase(name)) {
+ parseState |= IN_ITEMS_DEFINITION;
+ }
+ if (itemTag.equalsIgnoreCase(name) && (parseState & IN_ITEMS_DEFINITION) == IN_ITEMS_DEFINITION) {
+ parseState |= IN_ITEM_DEFINITION;
+ lastType = attributes.getValue(ATTR_TYPE);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
+ */
+ @Override
+ public void characters(char ch[], int start, int length) {
+ if (lastData == null) {
+ lastData = new String(ch, start, length).trim();
+ }
+ else {
+ lastData += new String(ch, start, length).trim();
+ }
+ }
+} \ No newline at end of file
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java
deleted file mode 100644
index 0d12273ab..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java
+++ /dev/null
@@ -1,555 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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.launch.core.persistence;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.IContextSelectorLaunchAttributes;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
-import org.eclipse.tcf.te.runtime.model.factory.Factory;
-import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable2;
-import org.eclipse.tcf.te.runtime.services.ServiceManager;
-import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService;
-import org.osgi.framework.Bundle;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * Context selector persistence delegate.
- */
-public class ContextSelectorPersistenceDelegate {
- // The read cache for step contexts. Avoid running time consuming
- // re-parsing of an already parsed step context description again and again.
- private final static Map<String, List<IModelNode>> readCache = new LinkedHashMap<String, List<IModelNode>>();
- // The write cache for target contexts. Avoids re-generating the XML again and again.
- private final static Map<String, String> writeCache = new LinkedHashMap<String, String>();
-
- // Limit the read cache to the last 10 read step contexts
- private final static int READ_CACHE_MAX_CAPACITY = 25;
- // Limit the write cache to the last 10 written step contexts
- private final static int WRITE_CACHE_MAX_CAPACITY = 25;
-
- /**
- * Saves the selected launch contexts to the specified launch configuration working copy. If the
- * selected launch contexts are <code>null</code> or empty, the attribute will be removed from
- * the specified launch configuration working copy.
- *
- * @param wc The launch configuration working copy. Must not be <code>null</code>.
- * @param contexts The launch contexts to save or <code>null</code>.
- */
- public final static void setLaunchContexts(ILaunchConfigurationWorkingCopy wc, IModelNode[] contexts) {
- Assert.isNotNull(wc);
-
- if (contexts == null || contexts.length == 0) {
- DefaultPersistenceDelegate.setAttribute(wc, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String) null);
- return;
- }
-
- // Get the encoded XML representation
- String xml = encodeLaunchContexts(contexts);
- // And save them to the launch configuration. If XML == null, the
- // launch contexts will be removed from the launch configuration
- DefaultPersistenceDelegate.setAttribute(wc, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, xml);
- }
-
- /**
- * Saves the selected launch contexts to the specified launch specification. If the selected
- * launch contexts are <code>null</code> or empty, the attribute will be removed from the
- * specified launch specification.
- *
- * @param launchSpec The launch specification. Must not be <code>null</code>.
- * @param contexts The launch contexts to save or <code>null</code>.
- */
- public final static void setLaunchContexts(ILaunchSpecification launchSpec, IModelNode[] contexts) {
- Assert.isNotNull(launchSpec);
-
- if (contexts == null || contexts.length == 0) {
- launchSpec.removeAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS);
- return;
- }
-
- // Get the encoded XML representation
- String xml = encodeLaunchContexts(contexts);
- // And save them to the launch specification. If XML == null, the
- // launch contexts will be removed from the launch specification
- launchSpec.addAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, xml);
- }
-
- /**
- * Writes the given launch contexts into a string encoded in XML.
- *
- * @param contexts The launch contexts to encode. Must not be <code>null</code>.
- * @return The full XML representation of the given contexts or <code>null</code>.
- */
- public final static String encodeLaunchContexts(IModelNode[] contexts) {
- Assert.isNotNull(contexts);
-
- // The final result
- String result = null;
-
- // Generate the write cache key
- String writeCacheKey = makeWriteCacheKey(contexts);
-
- // Check if we have the contexts already generated before
- synchronized (writeCache) {
- if (writeCache.containsKey(writeCacheKey)) {
- result = writeCache.get(writeCacheKey);
- }
- }
-
- // If no cache hit, generate from scratch
- if (result == null) {
- // First, we write the selected contexts as XML representation into a string
- StringWriter writer = new StringWriter();
-
- try {
- // Write the header and get the initial indentation
- String indentation = writeHeader(writer);
- // Iterate over the given selected step contexts and write them out.
- for (IModelNode node : contexts) {
- writeStepContext(writer, indentation, node);
- }
- // Write the footer
- writeFooter(writer);
-
- // Convert into a string
- result = writer.toString();
-
- synchronized (writeCache) {
- // Limit the write cache capacity
- checkCacheCapacity(writeCache, WRITE_CACHE_MAX_CAPACITY);
- // And put it into the write cache
- writeCache.put(writeCacheKey, result);
- }
- }
- catch (IOException e) {
- // Export to the string writer failed --> remove attribute from launch configuration
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- result = null;
- }
- finally {
- try {
- writer.close();
- }
- catch (IOException e) { /* ignored on purpose */
- }
- }
- }
-
- return result;
- }
-
- /**
- * Generates a write cache key from the given contexts.
- *
- * @param contexts The contexts
- * @return The corresponding write key cache.
- */
- private static String makeWriteCacheKey(IModelNode[] contexts) {
- Assert.isNotNull(contexts);
-
- StringBuffer key = new StringBuffer();
- for (IModelNode context : contexts) {
- key.append(Integer.toHexString(context.hashCode()));
- key.append(':');
- }
- if (key.charAt(key.length() - 1) == ':') {
- key.setCharAt(key.length() - 1, ' ');
- }
- return key.toString().trim();
- }
-
- /**
- * Writes the header to the given writer and returns the indentation to be used for following
- * elements.
- *
- * @param writer The writer instance. Must not be <code>null</code>.
- * @throws IOException in case the write failed.
- */
- private static String writeHeader(Writer writer) throws IOException {
- Assert.isNotNull(writer);
- writer.write("<contexts>\n"); //$NON-NLS-1$
- return "\t"; //$NON-NLS-1$
- }
-
- /**
- * Writes the footer to the given writer and returns the indentation to be used for following
- * elements.
- *
- * @param writer The writer instance. Must not be <code>null</code>.
- * @throws IOException in case the write failed.
- */
- private static String writeFooter(Writer writer) throws IOException {
- Assert.isNotNull(writer);
- writer.write("</contexts>\n"); //$NON-NLS-1$
- return ""; //$NON-NLS-1$
- }
-
- /**
- * Writes the step context element to the given writer.
- *
- * @param writer The writer instance. Must not be <code>null</code>.
- * @param indentation The indentation to prefix each exported line with. Must not be <code>null</code>.
- * @param context The step context instance. Must not be <code>null</code>.
- *
- * @throws IOException in case the write failed.
- */
- private static void writeStepContext(Writer writer, String indentation, IModelNode context) throws IOException {
- Assert.isNotNull(writer);
- Assert.isNotNull(indentation);
- Assert.isNotNull(context);
-
- IPersistable2 adapter = (IPersistable2)context.getAdapter(IPersistable2.class);
-
- writer.write(indentation + "<context type=\"" + adapter.getEncodedClassName(context) + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
- writer.write(indentation + "\t" + adapter.exportStringFrom(context) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
- writer.write(indentation + "</context>\n"); //$NON-NLS-1$
- }
-
- /**
- * Reads the selected launch contexts from the given XML encoded string.
- *
- * @param encodedContexts The selected launch contexts encoded as XML string. Must not be <code>null</code>.
- * @return The selected launch contexts or an empty array.
- */
- public final static IModelNode[] decodeLaunchContexts(String encodedContexts) {
- Assert.isNotNull(encodedContexts);
-
- List<IModelNode> contexts = null;
-
- if (!"".equals(encodedContexts.trim())) { //$NON-NLS-1$
- synchronized (readCache) {
- // Check if we have the contexts already parsed before
- if (readCache.containsKey(encodedContexts)) {
- // Take the result from the cache
- contexts = readCache.get(encodedContexts);
- // check sanity. If empty or we cannot find the step context,
- // drop the cache value and decode again.
- ListIterator<IModelNode> iterator = contexts.listIterator();
- while (iterator.hasNext()) {
- IModelNode node = iterator.next();
- IPropertiesAccessService service = ServiceManager.getInstance().getService(node, IPropertiesAccessService.class);
- boolean isGhost = false;
- if (service != null) {
- Object value = service.getProperty(node, IModelNode.PROPERTY_IS_GHOST);
- if (value instanceof Boolean) {
- isGhost = ((Boolean)value).booleanValue();
- }
- }
- if (isGhost) {
- contexts = null;
- readCache.remove(encodedContexts);
- break;
- }
- }
-
- if (contexts != null && contexts.isEmpty()) {
- readCache.remove(encodedContexts);
- contexts = null;
- }
- }
- }
-
- if (contexts == null || contexts.isEmpty()) {
- contexts = new ArrayList<IModelNode>();
- // We have to parse the contexts from the string
- InputStream input = new ByteArrayInputStream(encodedContexts.getBytes());
- // Instantiate the XML parser
- LaunchContextXMLParser xmlParser = new LaunchContextXMLParser();
- xmlParser.initXMLParser();
- xmlParser.setContexts(contexts);
- try {
- xmlParser.getXMLReader().parse(input, xmlParser);
- if (!contexts.isEmpty()) {
- synchronized (readCache) {
- // Limit the read cache capacity
- checkCacheCapacity(readCache, READ_CACHE_MAX_CAPACITY);
- // Put the result into the read cache
- readCache.put(encodedContexts, contexts);
- }
- }
- }
- catch (Exception e) {
- // Import failed --> remove attribute from launch configuration
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- contexts = null;
- }
- }
- }
-
- return contexts != null ? contexts.toArray(new IModelNode[contexts.size()]) : new IModelNode[0];
- }
-
- /**
- * Internal helper method to ensure a maximum capacity of the caches.
- */
- private final static void checkCacheCapacity(Map<String, ?> cache, int maxCapacity) {
- if (cache.size() < maxCapacity) {
- return;
- }
- // Get all keys
- String[] keys = cache.keySet().toArray(new String[cache.keySet().size()]);
- // And remove all keys starting with the eldest till the
- // capacity is fine again.
- for (String key : keys) {
- cache.remove(key);
- if (cache.size() < maxCapacity / 2) {
- break;
- }
- }
- }
-
- private final static class LaunchContextXMLParser extends DefaultHandler {
- private final int IN_CONTEXTS_DEFINITION = 1;
- private final int IN_CONTEXT_DEFINITION = 2;
-
- private SAXParser parser;
-
- private int parseState;
- private String lastData;
- private String lastType;
- private List<IModelNode> contexts;
-
- /**
- * Constructor
- */
- public LaunchContextXMLParser() {
- super();
-
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware(false);
- factory.setValidating(false);
- try {
- parser = factory.newSAXParser();
- }
- catch (ParserConfigurationException e) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getClass().getName(), e);
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- catch (SAXException e) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getClass().getName(), e);
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- }
-
- /**
- * Returns the associated XML parser instance.
- */
- protected SAXParser getXMLReader() {
- return parser;
- }
-
- /**
- * Reset the XML parser to a defined start point.
- */
- protected void initXMLParser() {
- parseState = 0;
- lastData = null;
- lastType = null;
- contexts = null;
- }
-
- /**
- * Associate the list instance to store the identified contexts.
- */
- protected void setContexts(List<IModelNode> contexts) {
- this.contexts = contexts;
- }
-
- /*
- * (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
- * java.lang.String)
- */
- @Override
- public void endElement(String uri, String localName, String name) throws SAXException {
- if ("contexts".equalsIgnoreCase(name) && (parseState & IN_CONTEXTS_DEFINITION) == IN_CONTEXTS_DEFINITION) { //$NON-NLS-1$
- parseState ^= IN_CONTEXTS_DEFINITION;
- }
- if ("context".equalsIgnoreCase(name) && (parseState & IN_CONTEXT_DEFINITION) == IN_CONTEXT_DEFINITION) { //$NON-NLS-1$
- parseState ^= IN_CONTEXT_DEFINITION;
-
- // The context encoded string is in last data
- if (lastType != null && lastData != null) {
- Class<IModelNode> clazz = null;
- try {
- clazz = (Class<IModelNode>)CoreBundleActivator.getContext().getBundle().loadClass(lastType);
- } catch (ClassNotFoundException e) {
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.WARNING, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- }
-
- // If the class could not be loaded by our own bundle class loader, try to find
- // the bundle from the class name and try to load the class through the bundle.
- if (clazz == null) {
- String bundleId = lastType;
- Bundle bundle = null;
- while (bundleId != null && bundle == null) {
- bundle = Platform.getBundle(bundleId);
- if (bundle == null) {
- int i = bundleId.lastIndexOf('.');
- if (i != -1) {
- bundleId = bundleId.substring(0, i);
- } else {
- bundleId = null;
- }
- }
- }
-
- if (bundle != null) {
- try {
- clazz = (Class<IModelNode>)bundle.loadClass(lastType);
- } catch (ClassNotFoundException e) {
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- }
- }
- }
-
- if (clazz != null) {
- // Create an instance of this class and try to load the step context
- Object object = Factory.getInstance().newInstance(clazz);
- if (object instanceof IAdaptable) {
- try {
- IPersistable2 adapter = (IPersistable2)((IAdaptable)object).getAdapter(IPersistable2.class);
- // Decodes the context object
- IModelNode context = (IModelNode)adapter.importFrom(lastData);
- if (!contexts.contains(context)) {
- contexts.add(context);
- }
- } catch (IOException e) {
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- }
- }
- }
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- @Override
- public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
- // Each time we start a new element, throw away the lastData content
- lastData = null;
-
- if ("contexts".equalsIgnoreCase(name)) { //$NON-NLS-1$
- parseState |= IN_CONTEXTS_DEFINITION;
- }
- if ("context".equalsIgnoreCase(name) && (parseState & IN_CONTEXTS_DEFINITION) == IN_CONTEXTS_DEFINITION) { //$NON-NLS-1$
- parseState |= IN_CONTEXT_DEFINITION;
- lastType = attributes.getValue("type"); //$NON-NLS-1$
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
- */
- @Override
- public void characters(char ch[], int start, int length) {
- if (lastData == null) {
- lastData = new String(ch, start, length).trim();
- }
- else {
- lastData += new String(ch, start, length).trim();
- }
- }
- }
-
- /**
- * Returns the list of configured launch contexts from the given launch configuration.
- * <p>
- * If the given launch configuration is <code>null</code> and the method will return an empty
- * array.
- *
- * @param configuration The launch configuration or <code>null</code>.
- * @return The list of configured launch contexts or an empty array.
- */
- public static final IModelNode[] getLaunchContexts(ILaunchConfiguration configuration) {
- IModelNode[] contexts = new IModelNode[0];
-
- // First read the contexts written by the launch context selector control.
- if (configuration != null) {
- // Read the context attribute from the launch configuration
- String encodedContexts = DefaultPersistenceDelegate.getAttribute(configuration, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String) null);
- if (encodedContexts != null) {
- contexts = ContextSelectorPersistenceDelegate.decodeLaunchContexts(encodedContexts);
- }
- }
-
- return contexts;
- }
-
- /**
- * Returns the list of configured launch contexts from the given launch specification.
- * <p>
- * If the given launch specification is <code>null</code> and the method will return an empty
- * array.
- *
- * @param launchSpec The launch specification or <code>null</code>.
- * @return The list of configured launch contexts or an empty array.
- */
- public static final IModelNode[] getLaunchContexts(ILaunchSpecification launchSpec) {
- IModelNode[] contexts = new IModelNode[0];
-
- // First read the contexts written by the launch context selector control.
- if (launchSpec != null) {
- // Read the context attribute from the launch specification
- String encodedContexts = (String) launchSpec.getAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, null);
- if (encodedContexts != null) {
- contexts = ContextSelectorPersistenceDelegate.decodeLaunchContexts(encodedContexts);
- }
- }
-
- return contexts;
- }
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ReferencedProjectsPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ReferencedProjectsPersistenceDelegate.java
deleted file mode 100644
index 26d308f1f..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ReferencedProjectsPersistenceDelegate.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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.launch.core.persistence;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes;
-
-/**
- * Launch framework referenced projects persistence delegate.
- */
-public class ReferencedProjectsPersistenceDelegate {
-
- /**
- * Interface declaring the public accessible attributes or a project reference.
- */
- public static interface IProjectReference {
-
- /**
- * Returns the name of the referenced project.
- *
- * @return The name of the referenced project.
- */
- public String getName();
-
- /**
- * Returns the referenced project instance.
- *
- * @return The referenced project instance or <code>null</code> if not in the workspace.
- */
- public IProject getProject();
-
- /**
- * Returns the enabled state of the project reference.
- *
- * @return <code>True</code> if the project reference is enabled, <code>false</code> otherwise.
- */
- public boolean isEnabled();
-
- /**
- * Set's the project reference enabled state.
- *
- * @param enabled <code>True</code> to enable the project reference, <code>false</code> otherwise.
- */
- public void setEnabled(boolean enabled);
- }
-
- /**
- * Internal default {@link IProjectReference} implementation.
- */
- private static class ProjectReference implements IProjectReference {
- private final String name;
- private boolean enabled;
- private final IProject project;
-
- /**
- * Constructor
- *
- * @param name The project name. Must not be <code>null</code>.
- * @param project The project instance or <code>null</code>.
- * @param enabled The enabled state.
- */
- public ProjectReference(String name, IProject project, boolean enabled) {
- Assert.isNotNull(name);
-
- this.name = name;
- this.enabled = enabled;
- this.project = project;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.persistence.ReferencedProjectsPersistenceDelegate.IProjectReference#getName()
- */
- @Override
- public String getName() {
- return name;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.persistence.ReferencedProjectsPersistenceDelegate.IProjectReference#getProject()
- */
- @Override
- public IProject getProject() {
- return project;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.persistence.ReferencedProjectsPersistenceDelegate.IProjectReference#isEnabled()
- */
- @Override
- public boolean isEnabled() {
- return enabled;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.persistence.ReferencedProjectsPersistenceDelegate.IProjectReference#setEnabled(boolean)
- */
- @Override
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof IProjectReference) {
- return name.equals(((IProjectReference)obj).getName());
- }
- return false;
- }
- }
-
- /**
- * Returns a new project reference instance.
- *
- * @param name The project name. Must not be <code>null</code>.
- * @param project The project instance or <code>null</code>.
- * @param enabled The enabled state.
- *
- * @return The new project reference instance.
- */
- public static IProjectReference create(String name, IProject project, boolean enabled) {
- return new ProjectReference(name, project, enabled);
- }
-
- /**
- * Read the list of project name from the launch configuration attributes and transforms
- * it into a list of project references.
- *
- * @param launchConfig The launch configuration. Must not be <code>null</code>.
- *
- * @return The list of project references or an empty list.
- */
- public static List<IProjectReference> getProjects(ILaunchConfiguration launchConfig) {
- Assert.isNotNull(launchConfig);
-
- List<IProjectReference> references = new ArrayList<IProjectReference>();
-
- // Get the list of referenced project from the launch configuration
- List<String> projects = (List<String>)DefaultPersistenceDelegate.getAttribute(launchConfig, ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, (List<String>)null);
- if (projects != null) {
- // Loop over the found project names and lookup the corresponding project instance.
- for (String name : projects) {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
- IProjectReference ref = create(name, project, false);
- if (!references.contains(ref)) {
- references.add(ref);
- }
- }
- }
-
- // Get the list of referenced project and enabled for build from the launch configuration
- projects = (List<String>)DefaultPersistenceDelegate.getAttribute(launchConfig, ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD, (List<String>)null);
- if (projects != null) {
- // Loop over the found project names and lookup the corresponding project instance.
- for (String name : projects) {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
- IProjectReference ref = create(name, project, true);
- // If already referenced, but not enabled, enable now.
- int i = references.indexOf(ref);
- if (i >= 0) {
- references.get(i).setEnabled(true);
- }
- else {
- references.add(ref);
- }
- }
- }
-
- return references;
- }
-
- /**
- * Writes the list of referenced projects to the given launch configuration working copy.
- *
- * @param wc The launch configuration working copy. Must not be <code>null</code>.
- * @param projects The list of referenced projects or <code>null</code>.
- */
- public static void setProjects(ILaunchConfigurationWorkingCopy wc, List<IProjectReference> projects) {
- Assert.isNotNull(wc);
-
- // If the project list is null or empty, we reset the attributes to use the default value
- if (projects == null || projects.isEmpty()) {
- DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, (List<String>)null);
- DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD, (List<String>)null);
- return;
- }
-
- // The list instances
- List<String> projectsForBuild = new ArrayList<String>();
- List<String> refProjects = new ArrayList<String>();
-
- // Loop all project references and find the referenced projects and
- // the projects enabled for build before launch
- for (IProjectReference projectRef : projects) {
- refProjects.add(projectRef.getName());
- if (projectRef.isEnabled()) {
- projectsForBuild.add(projectRef.getName());
- }
- }
-
- // The attribute "projects for build" is set always.
- DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD, projectsForBuild);
- // The referenced projects list contains only the excluded/disabled projects. Therefore
- // reset the attribute if the lists are equal
- if (projectsForBuild.size() == refProjects.size()) {
- DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, (List<String>)null);
- }
- else {
- DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, refProjects);
- }
- }
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransferItem.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransferItem.java
new file mode 100644
index 000000000..1038152c8
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransferItem.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.persistence.filetransfer;
+
+import org.eclipse.tcf.te.launch.core.interfaces.IFileTransferItem;
+import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+
+/**
+ * FileTransferItem
+ * @author tobias.schwarz@windriver.com
+ */
+public class FileTransferItem extends PropertiesContainer implements IFileTransferItem {
+
+ /**
+ * Constructor.
+ */
+ public FileTransferItem() {
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransferItemValidator.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransferItemValidator.java
new file mode 100644
index 000000000..9b5ec4417
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransferItemValidator.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.persistence.filetransfer;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.tcf.te.launch.core.interfaces.IFileTransferItem;
+import org.eclipse.tcf.te.launch.core.nls.Messages;
+
+/**
+ * FileTransferItemValidator
+ * @author tobias.schwarz@windriver.com
+ */
+public class FileTransferItemValidator {
+
+ public static final Map<String,String> validate(IFileTransferItem item) {
+ Assert.isNotNull(item);
+
+ Map<String,String> invalid = new HashMap<String,String>();
+
+ String host = item.getStringProperty(IFileTransferItem.PROPERTY_HOST);
+ String target = item.getStringProperty(IFileTransferItem.PROPERTY_TARGET);
+ int direction = (item.getProperty(IFileTransferItem.PROPERTY_DIRECTION) != null ?
+ item.getIntProperty(IFileTransferItem.PROPERTY_DIRECTION) : IFileTransferItem.HOST_TO_TARGET);
+
+ if (host == null || host.trim().length() == 0) {
+ if (direction == IFileTransferItem.HOST_TO_TARGET) {
+ invalid.put(IFileTransferItem.PROPERTY_HOST, Messages.FileTransferItemValidator_missingFile);
+ }
+ else {
+ invalid.put(IFileTransferItem.PROPERTY_HOST, Messages.FileTransferItemValidator_missingFileOrDirectory);
+ }
+ }
+ else {
+ IPath hostPath = new Path(host);
+ File hostFile = hostPath.toFile();
+ if (direction == IFileTransferItem.HOST_TO_TARGET) {
+ if (!hostFile.exists() || !hostFile.isFile() || !hostFile.canRead()) {
+ invalid.put(IFileTransferItem.PROPERTY_HOST, Messages.FileTransferItemValidator_notExistingFile);
+ }
+ }
+ else {
+ if ((hostFile.isFile() && !hostFile.canWrite()) || (hostFile.isDirectory() && (!hostFile.exists() || !hostFile.canWrite()))) {
+ invalid.put(IFileTransferItem.PROPERTY_HOST, Messages.FileTransferItemValidator_notExistingFileOrDirectory);
+ }
+ }
+ }
+
+ if (target == null || target.trim().length() == 0) {
+ if (direction == IFileTransferItem.HOST_TO_TARGET) {
+ invalid.put(IFileTransferItem.PROPERTY_TARGET, Messages.FileTransferItemValidator_missingFileOrDirectory);
+ }
+ else {
+ invalid.put(IFileTransferItem.PROPERTY_TARGET, Messages.FileTransferItemValidator_missingFile);
+ }
+ }
+ else {
+ IPath targetPath = new Path(target);
+ if (direction == IFileTransferItem.HOST_TO_TARGET) {
+ if (!targetPath.isValidPath(target)) {
+ invalid.put(IFileTransferItem.PROPERTY_TARGET, Messages.FileTransferItemValidator_invalidFileOrDirectory);
+ }
+ }
+ else {
+ if (!targetPath.isValidPath(target)) {
+ invalid.put(IFileTransferItem.PROPERTY_TARGET, Messages.FileTransferItemValidator_invalidFile);
+ }
+ }
+ }
+
+ return invalid.isEmpty() ? null : invalid;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransfersPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransfersPersistenceDelegate.java
new file mode 100644
index 000000000..074b06512
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/filetransfer/FileTransfersPersistenceDelegate.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.persistence.filetransfer;
+
+import java.util.List;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.launch.core.interfaces.IFileTransferItem;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IFileTransferLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.launch.core.persistence.AbstractItemListPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.AbstractItemListXMLParser;
+
+/**
+ * File transfer persistence delegate.
+ */
+public class FileTransfersPersistenceDelegate {
+
+ private static final String TAG_FILE_TRANSFER = "fileTransfer"; //$NON-NLS-1$
+
+ private static final AbstractItemListPersistenceDelegate<IFileTransferItem> delegate =
+ new AbstractItemListPersistenceDelegate<IFileTransferItem>(TAG_FILE_TRANSFER, IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS) {
+ @Override
+ protected AbstractItemListXMLParser<IFileTransferItem> getXMLParser() {
+ return new AbstractItemListXMLParser<IFileTransferItem>(TAG_FILE_TRANSFER) {
+ @Override
+ protected Class<?> getReadClass() {
+ return IFileTransferItem.class;
+ }
+ };
+ }
+ };
+
+ /**
+ * Saves the selected file transfer items to the specified launch configuration working copy. If the
+ * selected file transfer items are <code>null</code> or empty, the attribute will be removed from
+ * the specified launch configuration working copy.
+ *
+ * @param wc The launch configuration working copy. Must not be <code>null</code>.
+ * @param items The file transfer items to save or <code>null</code>.
+ */
+ public final static void setFileTransfers(ILaunchConfigurationWorkingCopy wc, IFileTransferItem[] items) {
+ delegate.setItems(wc, items);
+ }
+
+ /**
+ * Saves the selected file transfer items to the specified launch specification. If the selected
+ * file transfer items are <code>null</code> or empty, the attribute will be removed from the
+ * specified launch specification.
+ *
+ * @param launchSpec The launch specification. Must not be <code>null</code>.
+ * @param items The file transfer items to save or <code>null</code>.
+ */
+ public final static void setFileTransfers(ILaunchSpecification launchSpec, IFileTransferItem[] items) {
+ delegate.setItems(launchSpec, items);
+ }
+
+ /**
+ * Writes the given file transfer items into a string encoded in XML.
+ *
+ * @param items The file transfer items to encode. Must not be <code>null</code>.
+ * @return The full XML representation of the given items or <code>null</code>.
+ */
+ public final static String encodeFileTransferItems(IFileTransferItem[] items) {
+ return delegate.encodeItems(items);
+ }
+
+ /**
+ * Reads the selected file transfer items from the given XML encoded string.
+ *
+ * @param encodedItems The selected file transfer items encoded as XML string. Must not be <code>null</code>.
+ * @return The selected file transfer items or an empty array.
+ */
+ public final static IFileTransferItem[] decodeFileTransferItems(String encodedItems) {
+ List<IFileTransferItem> list = delegate.decodeItems(encodedItems);
+ return list.toArray(new IFileTransferItem[list.size()]);
+ }
+
+ /**
+ * Returns the list of configured file transfer items from the given launch configuration.
+ * <p>
+ * If the given launch configuration is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param configuration The launch configuration or <code>null</code>.
+ * @return The list of configured file transfer items or an empty array.
+ */
+ public static final IFileTransferItem[] getFileTransfers(ILaunchConfiguration configuration) {
+ List<IFileTransferItem> list = delegate.getItems(configuration);
+ return list.toArray(new IFileTransferItem[list.size()]);
+ }
+
+ /**
+ * Returns the list of configured file transfer items from the given launch specification.
+ * <p>
+ * If the given launch specification is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param launchSpec The launch specification or <code>null</code>.
+ * @return The list of configured file transfer items or an empty array.
+ */
+ public static final IFileTransferItem[] getFileTransfers(ILaunchSpecification launchSpec) {
+ List<IFileTransferItem> list = delegate.getItems(launchSpec);
+ return list.toArray(new IFileTransferItem[list.size()]);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/launchcontext/LaunchContextsPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/launchcontext/LaunchContextsPersistenceDelegate.java
new file mode 100644
index 000000000..f624a0b6c
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/launchcontext/LaunchContextsPersistenceDelegate.java
@@ -0,0 +1,257 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.persistence.launchcontext;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IContextSelectorLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.launch.core.persistence.AbstractItemListPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.AbstractItemListXMLParser;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService;
+
+/**
+ * Context selector persistence delegate.
+ */
+public class LaunchContextsPersistenceDelegate {
+ // The read cache for step contexts. Avoid running time consuming
+ // re-parsing of an already parsed step context description again and again.
+ private final static Map<String, List<IModelNode>> readCache = new LinkedHashMap<String, List<IModelNode>>();
+ // The write cache for target contexts. Avoids re-generating the XML again and again.
+ private final static Map<String, String> writeCache = new LinkedHashMap<String, String>();
+
+ // Limit the read cache to the last 10 read step contexts
+ private final static int READ_CACHE_MAX_CAPACITY = 25;
+ // Limit the write cache to the last 10 written step contexts
+ private final static int WRITE_CACHE_MAX_CAPACITY = 25;
+
+ private static final String TAG_LAUNCH_CONTEXT = "context"; //$NON-NLS-1$
+
+ private static final AbstractItemListPersistenceDelegate<IModelNode> delegate =
+ new AbstractItemListPersistenceDelegate<IModelNode>(TAG_LAUNCH_CONTEXT, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS) {
+ @Override
+ protected AbstractItemListXMLParser<IModelNode> getXMLParser() {
+ return new AbstractItemListXMLParser<IModelNode>(TAG_LAUNCH_CONTEXT) {
+ @Override
+ protected Class<?> getReadClass() {
+ return IModelNode.class;
+ }
+ };
+ }
+ };
+
+ /**
+ * Saves the selected launch contexts to the specified launch configuration working copy. If the
+ * selected launch contexts are <code>null</code> or empty, the attribute will be removed from
+ * the specified launch configuration working copy.
+ *
+ * @param wc The launch configuration working copy. Must not be <code>null</code>.
+ * @param contexts The launch contexts to save or <code>null</code>.
+ */
+ public final static void setLaunchContexts(ILaunchConfigurationWorkingCopy wc, IModelNode[] contexts) {
+ delegate.setItems(wc, contexts);
+ }
+
+ /**
+ * Saves the selected launch contexts to the specified launch specification. If the selected
+ * launch contexts are <code>null</code> or empty, the attribute will be removed from the
+ * specified launch specification.
+ *
+ * @param launchSpec The launch specification. Must not be <code>null</code>.
+ * @param contexts The launch contexts to save or <code>null</code>.
+ */
+ public final static void setLaunchContexts(ILaunchSpecification launchSpec, IModelNode[] contexts) {
+ delegate.setItems(launchSpec, contexts);
+ }
+
+ /**
+ * Writes the given launch contexts into a string encoded in XML.
+ *
+ * @param contexts The launch contexts to encode. Must not be <code>null</code>.
+ * @return The full XML representation of the given contexts or <code>null</code>.
+ */
+ public final static String encodeLaunchContexts(IModelNode[] contexts) {
+ Assert.isNotNull(contexts);
+
+ // The final result
+ String result = null;
+
+ // Generate the write cache key
+ String writeCacheKey = makeWriteCacheKey(contexts);
+
+ // Check if we have the contexts already generated before
+ synchronized (writeCache) {
+ if (writeCache.containsKey(writeCacheKey)) {
+ result = writeCache.get(writeCacheKey);
+ }
+ }
+
+ // If no cache hit, generate from scratch
+ if (result == null) {
+ result = delegate.encodeItems(contexts);
+
+ synchronized (writeCache) {
+ // Limit the write cache capacity
+ checkCacheCapacity(writeCache, WRITE_CACHE_MAX_CAPACITY);
+ // And put it into the write cache
+ writeCache.put(writeCacheKey, result);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates a write cache key from the given contexts.
+ *
+ * @param contexts The contexts
+ * @return The corresponding write key cache.
+ */
+ private static String makeWriteCacheKey(IModelNode[] contexts) {
+ Assert.isNotNull(contexts);
+
+ StringBuffer key = new StringBuffer();
+ for (IModelNode context : contexts) {
+ key.append(Integer.toHexString(context.hashCode()));
+ key.append(':');
+ }
+ if (key.charAt(key.length() - 1) == ':') {
+ key.setCharAt(key.length() - 1, ' ');
+ }
+ return key.toString().trim();
+ }
+
+ /**
+ * Reads the selected launch contexts from the given XML encoded string.
+ *
+ * @param encodedContexts The selected launch contexts encoded as XML string. Must not be <code>null</code>.
+ * @return The selected launch contexts or an empty array.
+ */
+ public final static IModelNode[] decodeLaunchContexts(String encodedContexts) {
+ Assert.isNotNull(encodedContexts);
+
+ List<IModelNode> contexts = null;
+
+ if (!"".equals(encodedContexts.trim())) { //$NON-NLS-1$
+ synchronized (readCache) {
+ // Check if we have the contexts already parsed before
+ if (readCache.containsKey(encodedContexts)) {
+ // Take the result from the cache
+ contexts = readCache.get(encodedContexts);
+ // check sanity. If empty or we cannot find the step context,
+ // drop the cache value and decode again.
+ ListIterator<IModelNode> iterator = contexts.listIterator();
+ while (iterator.hasNext()) {
+ IModelNode node = iterator.next();
+ IPropertiesAccessService service = ServiceManager.getInstance().getService(node, IPropertiesAccessService.class);
+ boolean isGhost = false;
+ if (service != null) {
+ Object value = service.getProperty(node, IModelNode.PROPERTY_IS_GHOST);
+ if (value instanceof Boolean) {
+ isGhost = ((Boolean)value).booleanValue();
+ }
+ }
+ if (isGhost) {
+ contexts = null;
+ readCache.remove(encodedContexts);
+ break;
+ }
+ }
+
+ if (contexts != null && contexts.isEmpty()) {
+ readCache.remove(encodedContexts);
+ contexts = null;
+ }
+ }
+ }
+
+ if (contexts == null || contexts.isEmpty()) {
+ contexts = delegate.decodeItems(encodedContexts);
+ if (!contexts.isEmpty()) {
+ synchronized (readCache) {
+ // Limit the read cache capacity
+ checkCacheCapacity(readCache, READ_CACHE_MAX_CAPACITY);
+ // Put the result into the read cache
+ readCache.put(encodedContexts, contexts);
+ }
+ }
+ }
+ }
+
+ return contexts != null ? contexts.toArray(new IModelNode[contexts.size()]) : new IModelNode[0];
+ }
+
+ /**
+ * Internal helper method to ensure a maximum capacity of the caches.
+ */
+ private final static void checkCacheCapacity(Map<String, ?> cache, int maxCapacity) {
+ if (cache.size() < maxCapacity) {
+ return;
+ }
+ // Get all keys
+ String[] keys = cache.keySet().toArray(new String[cache.keySet().size()]);
+ // And remove all keys starting with the eldest till the
+ // capacity is fine again.
+ for (String key : keys) {
+ cache.remove(key);
+ if (cache.size() < maxCapacity / 2) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * Returns the list of configured launch contexts from the given launch configuration.
+ * <p>
+ * If the given launch configuration is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param configuration The launch configuration or <code>null</code>.
+ * @return The list of configured launch contexts or an empty array.
+ */
+ public static final IModelNode[] getLaunchContexts(ILaunchConfiguration configuration) {
+ List<IModelNode> list = delegate.getItems(configuration);
+ return list.toArray(new IModelNode[list.size()]);
+ }
+
+ /**
+ * Returns the list of configured launch contexts from the given launch specification.
+ * <p>
+ * If the given launch specification is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param launchSpec The launch specification or <code>null</code>.
+ * @return The list of configured launch contexts or an empty array.
+ */
+ public static final IModelNode[] getLaunchContexts(ILaunchSpecification launchSpec) {
+ List<IModelNode> list = delegate.getItems(launchSpec);
+ return list.toArray(new IModelNode[list.size()]);
+ }
+
+ /**
+ * Returns the first configured launch context from the given launch configuration.
+ *
+ * @param configuration The launch configuration or <code>null</code>.
+ * @return The first configured launch context or <code>null</code>.
+ */
+ public static final IModelNode getFirstLaunchContext(ILaunchConfiguration configuration) {
+ List<IModelNode> list = delegate.getItems(configuration);
+ return list != null && !list.isEmpty() ? list.get(0) : null;
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectItem.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectItem.java
new file mode 100644
index 000000000..3d98aa23e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectItem.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.persistence.projects;
+
+import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem;
+import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+
+/**
+ * ReferencedProjectItem
+ * @author tobias.schwarz@windriver.com
+ */
+public class ReferencedProjectItem extends PropertiesContainer implements IReferencedProjectItem {
+
+ /**
+ * Constructor.
+ */
+ public ReferencedProjectItem() {
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectItemValidator.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectItemValidator.java
new file mode 100644
index 000000000..2efd8c288
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectItemValidator.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.persistence.projects;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem;
+import org.eclipse.tcf.te.launch.core.nls.Messages;
+
+/**
+ * ReferencedProjectItemValidator
+ * @author tobias.schwarz@windriver.com
+ */
+public class ReferencedProjectItemValidator {
+
+ public static final Map<String,String> validate(IReferencedProjectItem item) {
+ Assert.isNotNull(item);
+
+ Map<String,String> invalid = new HashMap<String,String>();
+
+ String projectName = item.getStringProperty(IReferencedProjectItem.PROPERTY_PROJECT_NAME);
+
+ if (projectName == null || projectName.trim().length() == 0) {
+ invalid.put(IReferencedProjectItem.PROPERTY_PROJECT_NAME, Messages.ReferencedProjectItemValidator_missingProject);
+ }
+ else {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (project == null) {
+ invalid.put(IReferencedProjectItem.PROPERTY_PROJECT_NAME, Messages.ReferencedProjectItemValidator_notExistingProject);
+ }
+ else if (!project.isOpen()) {
+ invalid.put(IReferencedProjectItem.PROPERTY_PROJECT_NAME, Messages.ReferencedProjectItemValidator_closedProject);
+ }
+ }
+
+ return invalid.isEmpty() ? null : invalid;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectsPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectsPersistenceDelegate.java
new file mode 100644
index 000000000..79be4e877
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/projects/ReferencedProjectsPersistenceDelegate.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.launch.core.persistence.projects;
+
+import java.util.List;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IReferencedProjectLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.persistence.AbstractItemListPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.AbstractItemListXMLParser;
+
+/**
+ * Referenced projects persistence delegate.
+ */
+public class ReferencedProjectsPersistenceDelegate {
+
+ private static final String TAG_PROJECT = "referencedProject"; //$NON-NLS-1$
+
+ private static final AbstractItemListPersistenceDelegate<IReferencedProjectItem> delegate =
+ new AbstractItemListPersistenceDelegate<IReferencedProjectItem>(TAG_PROJECT, IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS) {
+ @Override
+ protected AbstractItemListXMLParser<IReferencedProjectItem> getXMLParser() {
+ return new AbstractItemListXMLParser<IReferencedProjectItem>(TAG_PROJECT) {
+ @Override
+ protected Class<?> getReadClass() {
+ return IReferencedProjectItem.class;
+ }
+ };
+ }
+ };
+
+ /**
+ * Saves the selected referenced project items to the specified launch configuration working copy. If the
+ * selected referenced project items are <code>null</code> or empty, the attribute will be removed from
+ * the specified launch configuration working copy.
+ *
+ * @param wc The launch configuration working copy. Must not be <code>null</code>.
+ * @param items The referenced project items to save or <code>null</code>.
+ */
+ public final static void setReferencedProjects(ILaunchConfigurationWorkingCopy wc, IReferencedProjectItem[] items) {
+ delegate.setItems(wc, items);
+ }
+
+ /**
+ * Saves the selected referenced project items to the specified launch specification. If the selected
+ * referenced project items are <code>null</code> or empty, the attribute will be removed from the
+ * specified launch specification.
+ *
+ * @param launchSpec The launch specification. Must not be <code>null</code>.
+ * @param items The referenced project items to save or <code>null</code>.
+ */
+ public final static void setReferencedProjects(ILaunchSpecification launchSpec, IReferencedProjectItem[] items) {
+ delegate.setItems(launchSpec, items);
+ }
+
+ /**
+ * Writes the given referenced project items into a string encoded in XML.
+ *
+ * @param items The referenced project items to encode. Must not be <code>null</code>.
+ * @return The full XML representation of the given items or <code>null</code>.
+ */
+ public final static String encodeReferencedProjectItems(IReferencedProjectItem[] items) {
+ return delegate.encodeItems(items);
+ }
+
+ /**
+ * Reads the selected referenced project items from the given XML encoded string.
+ *
+ * @param encodedItems The selected referenced project items encoded as XML string. Must not be <code>null</code>.
+ * @return The selected referenced project items or an empty array.
+ */
+ public final static IReferencedProjectItem[] decodeReferencedProjectItems(String encodedItems) {
+ List<IReferencedProjectItem> list = delegate.decodeItems(encodedItems);
+ return list.toArray(new IReferencedProjectItem[list.size()]);
+ }
+
+ /**
+ * Returns the list of configured referenced project items from the given launch configuration.
+ * <p>
+ * If the given launch configuration is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param configuration The launch configuration or <code>null</code>.
+ * @return The list of configured referenced project items or an empty array.
+ */
+ public static final IReferencedProjectItem[] getReferencedProjects(ILaunchConfiguration configuration) {
+ List<IReferencedProjectItem> list = delegate.getItems(configuration);
+ return list.toArray(new IReferencedProjectItem[list.size()]);
+ }
+
+ /**
+ * Returns the list of configured referenced project items from the given launch specification.
+ * <p>
+ * If the given launch specification is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param launchSpec The launch specification or <code>null</code>.
+ * @return The list of configured referenced project items or an empty array.
+ */
+ public static final IReferencedProjectItem[] getReferencedProjects(ILaunchSpecification launchSpec) {
+ List<IReferencedProjectItem> list = delegate.getItems(launchSpec);
+ return list.toArray(new IReferencedProjectItem[list.size()]);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/LaunchContextSelectorSection.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/LaunchContextSelectorSection.java
index 032d9213e..99341d6fe 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/LaunchContextSelectorSection.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/LaunchContextSelectorSection.java
@@ -21,7 +21,7 @@ import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.tcf.te.launch.core.persistence.ContextSelectorPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.launchcontext.LaunchContextsPersistenceDelegate;
import org.eclipse.tcf.te.launch.ui.activator.UIPlugin;
import org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart;
import org.eclipse.tcf.te.launch.ui.internal.ImageConsts;
@@ -138,7 +138,7 @@ public class LaunchContextSelectorSection extends AbstractSection implements ILa
Assert.isNotNull(configuration);
if (selector != null) {
- IModelNode[] contexts = ContextSelectorPersistenceDelegate.getLaunchContexts(configuration);
+ IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(configuration);
if (contexts != null && contexts.length > 0) {
// Loop the contexts and create a list of nodes
List<IModelNode> nodes = new ArrayList<IModelNode>();
@@ -166,12 +166,12 @@ public class LaunchContextSelectorSection extends AbstractSection implements ILa
// Write the selected contexts to the launch configuration
if (nodes != null && nodes.length > 0) {
- ContextSelectorPersistenceDelegate.setLaunchContexts(configuration, nodes);
+ LaunchContextsPersistenceDelegate.setLaunchContexts(configuration, nodes);
} else {
- ContextSelectorPersistenceDelegate.setLaunchContexts(configuration, null);
+ LaunchContextsPersistenceDelegate.setLaunchContexts(configuration, null);
}
} else {
- ContextSelectorPersistenceDelegate.setLaunchContexts(configuration, null);
+ LaunchContextsPersistenceDelegate.setLaunchContexts(configuration, null);
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF
index c5c7ec970..278123ed6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF
@@ -7,12 +7,12 @@ Bundle-Activator: org.eclipse.tcf.te.runtime.persistence.activator.CoreBundleAct
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.tcf.te.runtime;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime.services;bundle-version="1.0.0"
+ org.eclipse.tcf.te.runtime.services;bundle-version="1.0.0",
+ org.eclipse.core.expressions;bundle-version="3.4.300"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Export-Package: org.eclipse.tcf.te.runtime.persistence,
org.eclipse.tcf.te.runtime.persistence.activator;x-internal:=true,
org.eclipse.tcf.te.runtime.persistence.interfaces,
- org.eclipse.tcf.te.runtime.persistence.properties,
org.eclipse.tcf.te.runtime.persistence.services
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties
index 4fb372828..09b469fdb 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties
@@ -1,20 +1,21 @@
-##################################################################################
-# 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
-##################################################################################
-
-pluginName = Target Explorer, Persistence Runtime plug-in
-providerName = Eclipse.org - TCF
-
-# ***** Extension Points *****
-
-ExtensionPoint.delegates.name=Target Explorer Persistence Delegates
-
-# ***** Persistence Delegates *****
-
-PropertiesFilePersistenceDelegate.label=Properties File Persistence Delegate
+##################################################################################
+# 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
+##################################################################################
+
+pluginName = Target Explorer, Persistence Runtime plug-in
+providerName = Eclipse.org - TCF
+
+# ***** Extension Points *****
+
+ExtensionPoint.delegates.name=Target Explorer Persistence Delegates
+ExtensionPoint.bindings.name=Target Explorer Persistence Delegate Bindings
+
+# ***** Persistence Delegates *****
+
+PropertiesFilePersistenceDelegate.label=Properties File Persistence Delegate
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml
index 5b298f250..b14210714 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml
@@ -4,11 +4,12 @@
<!-- Extension points -->
<extension-point id="delegates" name="%ExtensionPoint.delegates.name" schema="schema/delegates.exsd"/>
+ <extension-point id="bindings" name="%ExtensionPoint.bindings.name" schema="schema/bindings.exsd"/>
<!-- Persistence delegate contributions -->
<extension point="org.eclipse.tcf.te.runtime.persistence.delegates">
<delegate
- class="org.eclipse.tcf.te.runtime.persistence.properties.PropertiesFilePersistenceDelegate"
+ class="org.eclipse.tcf.te.runtime.persistence.AbstractPropertiesPersistenceDelegate"
id="org.eclipse.tcf.te.runtime.persistence.properties"
label="%PropertiesFilePersistenceDelegate.label">
</delegate>
@@ -17,9 +18,9 @@
<!-- Service contributions -->
<extension point="org.eclipse.tcf.te.runtime.services.services">
<service
- class="org.eclipse.tcf.te.runtime.persistence.services.PersistenceService"
+ class="org.eclipse.tcf.te.runtime.persistence.services.URIPersistenceService"
id="org.eclipse.tcf.te.runtime.services.persistence">
- <serviceType class="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService"/>
+ <serviceType class="org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService"/>
</service>
</extension>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/bindings.exsd b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/bindings.exsd
new file mode 100644
index 000000000..d222767f9
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/bindings.exsd
@@ -0,0 +1,134 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.tcf.te.runtime.persistence" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.tcf.te.runtime.persistence" id="bindings" name="Persistence Delegate Bindings Extension Point"/>
+ </appinfo>
+ <documentation>
+ This extension point is used to declare the persistence delegate bindings.
+&lt;p&gt;
+&lt;b&gt;Note:&lt;/b&gt; For the enablement expression evaluation, the default variable and &lt;b&gt;context&lt;/b&gt; is set to the delegate context,
+the variable &lt;b&gt;contextClass&lt;/b&gt; is set to the name of the class if the context to evaluate is an instance of java.lang.Class.
+&lt;br&gt;
+The variable &lt;b&gt;container&lt;/b&gt; is set with the persistence container object (i.e. ILaunchConfiguration, ...),
+the variable &lt;b&gt;containerClass&lt;/b&gt; is set to the name of the class if the container to evaluate is an instance of java.lang.Class,
+
+ </documentation>
+ </annotation>
+
+ <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="binding" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="binding">
+ <annotation>
+ <documentation>
+ Declares a persistence delegate binding.
+ </documentation>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="enablement" minOccurs="0" maxOccurs="1"/>
+ </sequence>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ persistence delegaete binding contribution.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="delegateId" type="string" use="required">
+ <annotation>
+ <documentation>
+ The unique id of the referenced persistence delegate.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="identifier" basedOn="org.eclipse.tcf.te.runtime.persistence.delegates/delegate/@id"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ Target Explorer 1.0.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ &lt;pre&gt;
+ &lt;extension point=&quot;org.eclipse.tcf.te.runtime.persistence.bindings&quot;&gt;
+ &lt;binding
+ id=&quot;org.eclipse.tcf.te.runtime.persistence.binding.LaunchConfigPersistenceDelegate&quot;
+ handlerId=&quot;org.eclipse.tcf.te.launch.core.persistence.LaunchConfigPersistenceDelegate&quot;&gt;
+ &lt;enablement&gt;
+ ...
+ &lt;/enablement&gt;
+ &lt;/binding&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+ </documentation>
+ </annotation>
+
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ Copyright (c) 2012 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.
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPersistenceDelegate.java
deleted file mode 100644
index dd04fb2ca..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPersistenceDelegate.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*******************************************************************************
- * 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.runtime.persistence;
-
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
-import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
-
-/**
- * Abstract persistence delegate implementation.
- */
-public abstract class AbstractPersistenceDelegate extends ExecutableExtension implements IPersistenceDelegate {
-
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesPersistenceDelegate.java
new file mode 100644
index 000000000..952b6f532
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesPersistenceDelegate.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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.runtime.persistence;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+
+/**
+ * Properties file persistence delegate implementation.
+ * <p>
+ * The persistence delegates reads and writes a simple grouped properties file format.
+ */
+public abstract class AbstractPropertiesPersistenceDelegate extends ExecutableExtension implements IPersistenceDelegate {
+
+ public final static String CORE_SECTION_NAME = "core"; //$NON-NLS-1$
+
+ /**
+ * Constructor.
+ */
+ public AbstractPropertiesPersistenceDelegate() {
+ super();
+ }
+
+ /**
+ * Convert the given context to map.
+ *
+ * @param context The context. Must not be <code>null</code>.
+ * @return Map representing the context.
+ *
+ * @throws IOException
+ */
+ @SuppressWarnings("unchecked")
+ protected Map<String, Object> toMap(final Object context) throws IOException {
+ Map<String, Object> result = new HashMap<String,Object>();
+
+ Map<String,Object> attrs = null;
+ if (context instanceof Map) {
+ attrs = (Map<String, Object>)context;
+ }
+ else if (context instanceof IPropertiesContainer) {
+ IPropertiesContainer container = (IPropertiesContainer)context;
+ attrs = new HashMap<String,Object>(container.getProperties());
+ }
+
+ if (attrs != null) {
+ for (String key : attrs.keySet()) {
+ if (!key.endsWith(".transient")) { //$NON-NLS-1$
+ result.put(key, attrs.get(key));
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Convert a map into the needed context object.
+ *
+ * @param map The map representing the context. Must not be <code>null</code>.
+ * @param context The context to put the map values in or <code>null</code>.
+ * @return The context object.
+ *
+ * @throws IOException
+ */
+ protected Object fromMap(Map<String,Object> map, Object context) throws IOException {
+ if (context == null || Map.class.equals(context.getClass())) {
+ return map;
+ }
+ else if (context instanceof Map) {
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ Map<String,Object> newMap = new HashMap<String, Object>((Map)context);
+ newMap.putAll(map);
+ return newMap;
+ }
+ else if (IPropertiesContainer.class.equals(context.getClass())) {
+ IPropertiesContainer container = new PropertiesContainer();
+ container.setProperties(map);
+
+ return container;
+ }
+ else if (context instanceof IPropertiesContainer) {
+ IPropertiesContainer container = (IPropertiesContainer)context;
+ container.setProperties(map);
+
+ return container;
+ }
+
+ return null;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesToURIPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesToURIPersistenceDelegate.java
new file mode 100644
index 000000000..b5d7e9b98
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesToURIPersistenceDelegate.java
@@ -0,0 +1,335 @@
+/*******************************************************************************
+ * 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.runtime.persistence;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * Properties file persistence delegate implementation.
+ * <p>
+ * The persistence delegates reads and writes a simple grouped properties file format.
+ */
+public abstract class AbstractPropertiesToURIPersistenceDelegate extends AbstractPropertiesPersistenceDelegate {
+
+ private String defaultFileExtension;
+
+ /**
+ * Constructor.
+ *
+ * @param defaultFileExtension The default file extension.
+ */
+ protected AbstractPropertiesToURIPersistenceDelegate(String defaultFileExtension) {
+ super();
+ Assert.isNotNull(defaultFileExtension);
+ this.defaultFileExtension = defaultFileExtension;
+ }
+
+ /**
+ * Return the default extenion.
+ */
+ protected String getDefaultFileExtension() {
+ return defaultFileExtension;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#write(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public Object write(Object context, Object container, String key) throws IOException {
+ Assert.isNotNull(context);
+ Assert.isNotNull(container);
+
+ if (container instanceof URI) {
+ URI uri = (URI)container;
+
+ // Only "file:" URIs are supported
+ if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
+ throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Create the file object from the given URI
+ File file = new File(uri.normalize());
+
+ // The file must be absolute
+ if (!file.isAbsolute()) {
+ throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
+ }
+
+ // If the file defaultFileExtension is no set, default to "properties"
+ IPath path = new Path(file.getCanonicalPath());
+ if (path.getFileExtension() == null) {
+ file = path.addFileExtension(getDefaultFileExtension()).toFile();
+ }
+
+ // Create the writer object
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); //$NON-NLS-1$
+ try {
+ // Write the first level of attributes
+ writeMap(writer, key, toMap(context));
+ } finally {
+ writer.close();
+ }
+ }
+
+ return container;
+ }
+
+ /**
+ * Write the map data.
+ *
+ * @param writer The writer. Must not be <code>null</code>.
+ * @param section The section name or <code>null</code>.
+ * @param data The data. Must not be <code>null</code>.
+ */
+ private void writeMap(BufferedWriter writer, String section, Map<String, Object> data) throws IOException {
+ Assert.isNotNull(writer);
+ Assert.isNotNull(data);
+
+ // Will contain the list of map keys where the value is a map type itself.
+ List<String> childMapKeys = new ArrayList<String>();
+ // Will contain the list of map keys where the value is not an map type.
+ List<String> childKeys = new ArrayList<String>();
+
+ // Get all the map keys and filter the map type values
+ for (String key : data.keySet()) {
+ if (data.get(key) instanceof Map) {
+ childMapKeys.add(key);
+ }
+ else {
+ childKeys.add(key);
+ }
+ }
+
+ // Sort both lists
+ Collections.sort(childMapKeys);
+ Collections.sort(childKeys);
+
+ // If the child key list is not empty, write the section
+ if (!childKeys.isEmpty()) {
+ // Write a new line except it is the "core" section
+ if (section != null && !CORE_SECTION_NAME.equals(section)) {
+ writer.newLine();
+ }
+
+ // Write the header
+ if (section != null) {
+ writer.write("[" + section.trim() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
+ writer.newLine();
+ }
+
+ for (String key : childKeys) {
+ if (section != null) {
+ writer.write('\t');
+ }
+ writer.write(key);
+ writer.write(" = "); //$NON-NLS-1$
+
+ Object value = data.get(key);
+ if (value instanceof List) {
+ writer.write(Arrays.deepToString(((List<?>)value).toArray()));
+ } else {
+ writer.write(value.toString());
+ }
+
+ writer.newLine();
+ }
+ }
+
+ // If there are map type values, write them now
+ if (!childMapKeys.isEmpty()) {
+ for (String key : childMapKeys) {
+ // Calculate the section name
+ String newSection = section == null || CORE_SECTION_NAME.equals(section) ? key.trim() : section + "." + key.trim(); //$NON-NLS-1$
+ // Write it
+ writeMap(writer, newSection, (Map<String, Object>)data.get(key));
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#read(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public Object read(Object context, Object container, String key) throws IOException {
+ Assert.isNotNull(container);
+
+ if (container instanceof URI) {
+ URI uri = (URI)container;
+
+ // Only "file:" URIs are supported
+ if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
+ throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Create the file object from the given URI
+ File file = new File(uri.normalize());
+
+ // The file must be absolute
+ if (!file.isAbsolute()) {
+ throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
+ }
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> data = context instanceof Map ? (Map<String,Object>)context : new HashMap<String, Object>();
+
+ // Create the reader object
+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); //$NON-NLS-1$
+ try {
+ readMap(reader, key, data);
+ } finally {
+ reader.close();
+ }
+
+ if (key != null && data.containsKey(key) && data.get(key) instanceof Map) {
+ data = (Map<String,Object>)data.get(key);
+ }
+
+ context = fromMap(data, context);
+ }
+
+ return context;
+ }
+
+ private static Pattern SECTION = Pattern.compile("\\s*\\[([^\\]]+)\\]\\s*"); //$NON-NLS-1$
+ private static Pattern PROPERTY = Pattern.compile("\\s*(.+\\s*=\\s*.+)"); //$NON-NLS-1$
+
+ /**
+ * Read the data.
+ *
+ * @param reader The reader. Must not be <code>null</code>.
+ * @param section The section name or <code>null</code>.
+ * @param data The data. Must not be <code>null</code>.
+ */
+ private void readMap(BufferedReader reader, String section, Map<String, Object> data) throws IOException {
+ Assert.isNotNull(reader);
+ Assert.isNotNull(data);
+
+ // The sections by name for easier access.
+ // The "core" section is the incoming data object
+ Map<String, Map<String, Object>> sections = new HashMap<String, Map<String, Object>>();
+ sections.put(section == null ? CORE_SECTION_NAME : section, data);
+
+ String currentSection = section == null ? CORE_SECTION_NAME : section;
+ String line = reader.readLine();
+ while (line != null) {
+ Matcher matcher = SECTION.matcher(line);
+ if (matcher.matches()) {
+ // Section names are case-sensitive too
+ currentSection = matcher.group(1);
+ if (sections.get(currentSection) == null) {
+ sections.put(currentSection, new HashMap<String, Object>());
+ }
+ } else {
+ matcher = PROPERTY.matcher(line);
+ if (matcher.matches()) {
+ String property = matcher.group(1);
+ String[] pieces = property.split("=", 2); //$NON-NLS-1$
+ Map<String, Object> sectionMap = sections.get(currentSection);
+ sectionMap.put(pieces[0].trim(), pieces[1].trim());
+ }
+ }
+
+ line = reader.readLine();
+ }
+
+ // Recreate the sections hierarchy
+ for (String sectionName : sections.keySet()) {
+ if (CORE_SECTION_NAME.equals(sectionName)) {
+ continue;
+ }
+ Map<String, Object> sectionMap = sections.get(sectionName);
+ if (sectionName.contains(".")) { //$NON-NLS-1$
+ // Split the section name and recreate the missing hierarchy
+ String[] pieces = sectionName.split("\\."); //$NON-NLS-1$
+ Map<String, Object> parentSection = data;
+ for (String subSectionName : pieces) {
+ if (CORE_SECTION_NAME.equals(subSectionName)) {
+ continue;
+ }
+
+ if (sectionName.endsWith(subSectionName)) {
+ parentSection.put(subSectionName, sectionMap);
+ } else {
+ Map<String, Object> subSection = (Map<String, Object>)parentSection.get(subSectionName);
+ if (subSection == null) {
+ subSection = new HashMap<String, Object>();
+ parentSection.put(subSectionName, subSection);
+ }
+ parentSection = subSection;
+ }
+ }
+ } else {
+ // Place it into the root object, but check if it may exist
+ Map<String, Object> oldSection = (Map<String, Object>)data.get(sectionName);
+ if (oldSection != null) {
+ oldSection.putAll(sectionMap);
+ }
+ else {
+ data.put(sectionName, sectionMap);
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#delete(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public boolean delete(Object context, Object container, String key) throws IOException {
+ Assert.isNotNull(container);
+
+ if (container instanceof URI) {
+ URI uri = (URI)container;
+
+ // Only "file:" URIs are supported
+ if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
+ throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Create the file object from the given URI
+ File file = new File(uri.normalize());
+
+ // The file must be absolute
+ if (!file.isAbsolute()) {
+ throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
+ }
+
+ // If the file defaultFileExtension is no set, default to "properties"
+ IPath path = new Path(file.getCanonicalPath());
+ if (path.getFileExtension() == null) {
+ file = path.addFileExtension(getDefaultFileExtension()).toFile();
+ }
+
+ return file.delete();
+ }
+
+ return false;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceDelegateManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
index 802f94cb9..f9a8dd163 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceDelegateManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
@@ -13,33 +13,40 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager;
import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
+import org.eclipse.tcf.te.runtime.persistence.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.eclipse.tcf.te.runtime.persistence.internal.PersistenceDelegateBinding;
+import org.eclipse.tcf.te.runtime.persistence.internal.PersistenceDelegateBindingExtensionPointManager;
/**
* Persistence delegate manager implementation.
*/
-public class PersistenceDelegateManager extends AbstractExtensionPointManager<IPersistenceDelegate> {
+public class PersistenceManager extends AbstractExtensionPointManager<IPersistenceDelegate> {
/*
* Thread save singleton instance creation.
*/
private static class LazyInstance {
- public static PersistenceDelegateManager instance = new PersistenceDelegateManager();
+ public static PersistenceManager instance = new PersistenceManager();
}
/**
* Constructor.
*/
- PersistenceDelegateManager() {
+ PersistenceManager() {
super();
}
/**
* Returns the singleton instance of the extension point manager.
*/
- public static PersistenceDelegateManager getInstance() {
+ public static PersistenceManager getInstance() {
return LazyInstance.instance;
}
@@ -67,7 +74,7 @@ public class PersistenceDelegateManager extends AbstractExtensionPointManager<IP
*
* @return The list of contributed persistence delegates, or an empty array.
*/
- public IPersistenceDelegate[] getDelegates(boolean unique) {
+ protected IPersistenceDelegate[] getDelegates(boolean unique) {
List<IPersistenceDelegate> contributions = new ArrayList<IPersistenceDelegate>();
Collection<ExecutableExtensionProxy<IPersistenceDelegate>> delegates = getExtensions().values();
for (ExecutableExtensionProxy<IPersistenceDelegate> delegate : delegates) {
@@ -89,7 +96,7 @@ public class PersistenceDelegateManager extends AbstractExtensionPointManager<IP
*
* @return The persistence delegate instance or <code>null</code>.
*/
- public IPersistenceDelegate getDelegate(String id, boolean unique) {
+ protected IPersistenceDelegate getDelegate(String id, boolean unique) {
IPersistenceDelegate contribution = null;
if (getExtensions().containsKey(id)) {
ExecutableExtensionProxy<IPersistenceDelegate> proxy = getExtensions().get(id);
@@ -99,4 +106,40 @@ public class PersistenceDelegateManager extends AbstractExtensionPointManager<IP
return contribution;
}
+
+ /**
+ * Returns the persistence delegate which is enabled for the given
+ * context and persistence container.
+ *
+ * @param context The persistence delegate context. Must not be <code>null</code>.
+ * @param container The persistence container or <code>null</code>.
+ * @return The persistence delegate which is enabled or <code>null</code>.
+ */
+ public IPersistenceDelegate getDelegate(Object context, Object container, boolean unique) {
+ Assert.isNotNull(context);
+
+ List<IPersistenceDelegate> delegates = new ArrayList<IPersistenceDelegate>();
+
+ // Get the list of applicable bindings
+ PersistenceDelegateBinding[] bindings = PersistenceDelegateBindingExtensionPointManager.getInstance().getApplicableBindings(context, container);
+ for (PersistenceDelegateBinding binding : bindings) {
+ IPersistenceDelegate delegate = getDelegate(binding.getDelegateId(), unique);
+ if (delegate != null && !delegates.contains(delegate)) {
+ delegates.add(delegate);
+ }
+ }
+
+ // If no applicable persistence delegate is found, always return null
+ if (delegates.isEmpty() || delegates.isEmpty()) {
+ return null;
+ }
+
+ if (delegates.size() > 1) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "Found multiple persistence delgates for " + context + //$NON-NLS-1$
+ (container != null ? " to store in " + container : "")); //$NON-NLS-1$ //$NON-NLS-2$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+
+ return delegates.get(0);
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable.java
deleted file mode 100644
index 17368c32a..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * 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.runtime.persistence.interfaces;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Map;
-
-/**
- * Interface to be implemented by persistable elements.
- */
-public interface IPersistable {
-
- /**
- * Returns the id of the persistence storage to use for persisting data objects.
- * <p>
- * The method is expected to return never <code>null</code>.
- *
- * @return The persistence storage id.
- */
- public String getStorageID();
-
- /**
- * Returns the URI reference to pass on to the associated persistence delegate to
- * denote the given data object.
- * <p>
- * The interpretation of the URI reference is up to the persistence delegate, but
- * the method is expected to return never <code>null</code>.
- *
- * @param data The data object. Must not be <code>null</code>.
- *
- * @return The URI.
- */
- public URI getURI(Object data);
-
- /**
- * Returns the interface type name to use for recreating the object from the
- * persisted object representation.
- * <p>
- * <b>Note:</b> The returned string is expected in the format <code>&quot;&lt;bundleId&gt;:&lt;full qualified interface type name&gt;&quot;</code>.
- * If the bundle id is not present, it is very likely that the object recreation will fail with a {@link ClassNotFoundException}.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The interface type or <code>null</code>.
- */
- public String getInterfaceTypeName(Object data);
-
- /**
- * Exports the given data object to an external representation.
- * <p>
- * As a general guide line, it is expected that the external representation contains only base
- * Java objects like maps, lists and Strings. Details about the valid object types can be taken
- * from the referenced persistence delegate.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The external representation of the given data object.
- *
- * @throws IOException - if the operation fails.
- */
- public Map<String, Object> exportFrom(Object data) throws IOException;
-
- /**
- * Imports the given external representation into the given data object.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @param external The external representation. Must not be <code>null</code>.
- *
- * @throws IOException - if the operation fails.
- */
- public void importTo(Object data, Map<String, Object> external) throws IOException;
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable2.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable2.java
deleted file mode 100644
index 5667b1982..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable2.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * 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.runtime.persistence.interfaces;
-
-import java.io.IOException;
-
-/**
- * Interface to be implemented by string persistable elements.
- */
-public interface IPersistable2 extends IPersistable {
-
- /**
- * Returns the class name of the encoded context.
- * <p>
- * The class name is used to load the correct class to decode the persistable representation.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The class name of the encoded context.
- */
- public String getEncodedClassName(Object data);
-
-
- /**
- * Exports the given data object to an external representation.
- * <p>
- * As a general guide line, it is expected that the external representation contains only base
- * Java objects like maps, lists and Strings. Details about the valid object types can be taken
- * from the referenced persistence delegate.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The external representation of the given data object.
- *
- * @throws IOException - if the operation fails.
- */
- public String exportStringFrom(Object data) throws IOException;
-
- /**
- * Imports the given external representation.
- *
- * @param external The external representation. Must not be <code>null</code>.
- * @return The data object or <code>null</code>.
- *
- * @throws IOException - if the operation fails.
- */
- public Object importFrom(String external) throws IOException;
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistableURIProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistableURIProvider.java
new file mode 100644
index 000000000..d1b492c32
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistableURIProvider.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.runtime.persistence.interfaces;
+
+import java.net.URI;
+
+/**
+ * Interface to be implemented by persistable elements.
+ */
+public interface IPersistableURIProvider {
+
+ /**
+ * Returns the URI reference to pass on to the associated persistence delegate to
+ * denote the given context object.
+ * <p>
+ * The interpretation of the URI reference is up to the persistence delegate, but
+ * the method is expected to return never <code>null</code>.
+ *
+ * @param context The context object. Must not be <code>null</code>.
+ *
+ * @return The URI.
+ */
+ public URI getURI(Object context);
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java
index 915680503..983c58b79 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java
@@ -10,8 +10,6 @@
package org.eclipse.tcf.te.runtime.persistence.interfaces;
import java.io.IOException;
-import java.net.URI;
-import java.util.Map;
import org.eclipse.tcf.te.runtime.interfaces.extensions.IExecutableExtension;
@@ -21,45 +19,46 @@ import org.eclipse.tcf.te.runtime.interfaces.extensions.IExecutableExtension;
public interface IPersistenceDelegate extends IExecutableExtension {
/**
- * Writes the given data to the given persistence storage.
- * <p>
- * The persistence storage location is defined by the specified URI reference. The exact
- * interpretation and semantic of the URI reference is up to the persistence delegate
- * contributor.
+ * Writes the given context to the given persistence container using the key.
+ * If the container does not exist yet, the class needs to be given.
*
- * @param uri The persistence storage location URI reference. Must not be <code>null</code>.
- * @param data The data. Must not be <code>null</code>.
+ * @param context The context to persist. Must not be <code>null</code>.
+ * @param container The persistence container or class for a new one. Must not be <code>null</code>.
+ * @param key The key for the context inside the container or <code>null</code>.
*
- * @throws IOException - if the operation fails
+ * @return The new or updated container instance.
*/
- public void write(URI uri, Map<String, Object> data) throws IOException;
+ public Object write(Object context, Object container, String key) throws IOException;
/**
- * Reads the data from the given persistence storage.
- * <p>
- * The persistence storage location is defined by the specified URI reference. The exact
- * interpretation and semantic of the URI reference is up to the persistence delegate
- * contributor.
+ * Get the class or interface for the context.
+ *
+ * @param context The context to persist. Must not be <code>null</code>.
+ * @return The class or interface for the given context.
+ */
+ public Class<?> getPersistedClass(Object context);
+
+ /**
+ * Reads the context from the given persistence container.
+ * If the context does not exist yet, the class needs to be given.
*
- * @param uri The persistence storage location URI reference. Must not be <code>null</code>.
- * @return The data.
+ * @param context The context to update or class for a new context. Must not be <code>null</code>.
+ * @param container The persistence container. Must not be <code>null</code>.
+ * @param key The key for the context inside the container or <code>null</code>.
*
- * @throws IOException - if the operation fails
+ * @return The new or updated context instance.
*/
- public Map<String, Object> read(URI uri) throws IOException;
+ public Object read(Object context, Object container, String key) throws IOException;
/**
- * Deletes the given persistence storage.
- * <p>
- * The persistence storage location is defined by the specified URI reference. The exact
- * interpretation and semantic of the URI reference is up to the persistence delegate
- * contributor.
+ * Deletes the given context inside the container or the whole container.
*
- * @param uri The persistence storage location URI reference. Must not be <code>null</code>.
- * @return <code>True</code> if the persistence storage is successfully deleted;
- * <code>false</code> otherwise.
+ * @param context The context to delete inside the storage or <code>null</code>.
+ * @param container The persistence container. Must not be <code>null</code>.
+ * @param key The key for the context inside the container or <code>null</code>.
*
- * @throws IOException - if the operation fails
+ * @return <code>True</code> if the persistence context or the whole storage was successfully deleted;
+ * <code>false</code> otherwise.
*/
- public boolean delete(URI uri) throws IOException;
+ public boolean delete(Object context, Object container, String key) throws IOException;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceService.java
deleted file mode 100644
index 67b77254f..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceService.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * 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.runtime.persistence.interfaces;
-
-import java.io.IOException;
-import java.net.URI;
-
-import org.eclipse.tcf.te.runtime.services.interfaces.IService;
-
-/**
- * A service for persisting elements to a persistence store.
- */
-public interface IPersistenceService extends IService {
-
- /**
- * Writes the given data object via a persistence delegate to a persistence storage. The
- * persistence delegate to use will be determined by adapting the given data object to an
- * {@link IPersistable}.
- *
- * @param data The data object. Must not be <code>null</code>.
- *
- * @throws IOException - if the operation fails.
- */
- public void write(Object data) throws IOException;
-
- /**
- * Fills the given data object with the data read via a persistence delegate from a given
- * persistence storage. The persistence delegate to use will be determined by adapting the given
- * data object to an {@link IPersistable}.
- *
- * @param data The data object. Must not be <code>null</code>.
- *
- * @throws IOException - if the operation fails
- */
- public void read(Object data) throws IOException;
-
- /**
- * Deletes the persistence storage for the given data object via a persistence delegate. The
- * persistence delegate to use will be determined by adapting the given data object to an
- * {@link IPersistable}.
- *
- * @param data The data object. Must not be <code>null</code>.
- *
- * @return <code>True</code> if the persistence storage is successfully deleted;
- * <code>false</code> otherwise.
- *
- * @throws IOException - if the operation fails
- */
- public boolean delete(Object data) throws IOException;
-
- /**
- * Returns the persistence storage URI for the given data object. The persistence delegate to
- * use will be determined by adapting the given data object to an {@link IPersistable}.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The URI or <code>null</code>.
- *
- * @throws IOException - if the operation fails
- */
- public URI getURI(Object data) throws IOException;
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IURIPersistenceService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IURIPersistenceService.java
new file mode 100644
index 000000000..fdcb6c77e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IURIPersistenceService.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.runtime.persistence.interfaces;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.eclipse.tcf.te.runtime.services.interfaces.IService;
+
+/**
+ * A service for persisting elements to a URI persistence store.
+ */
+public interface IURIPersistenceService extends IService {
+
+ /**
+ * Writes the given context object via a persistence delegate to a persistence storage.
+ * If the given URI is <code>null</code>, it will be determined by adapting the context
+ * to a {@link IPersistableURIProvider}
+ *
+ * @param context The context object. Must not be <code>null</code>.
+ * @param uri The URI or <code>null</code>.
+ *
+ * @throws IOException - if the operation fails.
+ */
+ public void write(Object context, URI uri) throws IOException;
+
+ /**
+ * Reads a context object via a persistence delegate from a given persistence storage.
+ * If the given URI is <code>null</code>, it will be determined by adapting the context
+ * to a {@link IPersistableURIProvider}. In this case the context must not be <code>null</code>.
+ *
+ * @param uri The URI. Must not be <code>null</code>.
+ * @param context The context object or <code>null</code>.
+ *
+ * @throws IOException - if the operation fails
+ */
+ public Object read(URI uri, Object context) throws IOException;
+
+ /**
+ * Deletes the persistence storage for the given context object via a persistence delegate.
+ * If the given URI is <code>null</code>, it will be determined by adapting the context
+ * to a {@link IPersistableURIProvider}
+ *
+ * @param context The context object. Must not be <code>null</code>.
+ * @param uri The URI or <code>null</code>.
+ *
+ * @return <code>True</code> if the persistence storage is successfully deleted;
+ * <code>false</code> otherwise.
+ *
+ * @throws IOException - if the operation fails
+ */
+ public boolean delete(Object context, URI uri) throws IOException;
+
+ /**
+ * Returns the persistence storage URI for the given context object. The persistence delegate to
+ * use will be determined by adapting the given context object to an {@link IPersistable}.
+ *
+ * @param context The context object. Must not be <code>null</code>.
+ * @return The URI or <code>null</code>.
+ *
+ * @throws IOException - if the operation fails
+ */
+ public URI getURI(Object context) throws IOException;
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java
new file mode 100644
index 000000000..0a63f6327
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.runtime.persistence.internal;
+
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.ExpressionConverter;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
+
+/**
+ * Persistence delegate binding implementation.
+ */
+public class PersistenceDelegateBinding extends ExecutableExtension {
+ // The mandatory delegate identifier
+ private String delegateId;
+ // The converted expression
+ private Expression expression;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtension#doSetInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
+ */
+ @Override
+ public void doSetInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ super.doSetInitializationData(config, propertyName, data);
+
+ // Initialize the delegate id field by reading the <delegate> extension attribute.
+ // Throws an exception if the id is empty or null.
+ delegateId = config != null ? config.getAttribute("delegateId") : null; //$NON-NLS-1$
+ if (delegateId == null || (delegateId != null && "".equals(delegateId.trim()))) { //$NON-NLS-1$
+ throw createMissingMandatoryAttributeException("delegateId", config.getContributor().getName()); //$NON-NLS-1$
+ }
+
+ // Read the sub elements of the extension
+ IConfigurationElement[] children = config != null ? config.getChildren() : null;
+ // The "enablement" element is the only expected one
+ if (children != null && children.length > 0) {
+ expression = ExpressionConverter.getDefault().perform(children[0]);
+ }
+ }
+
+ /**
+ * Returns the delegate id which is associated with this binding.
+ *
+ * @return The delegate id.
+ */
+ public String getDelegateId() {
+ return delegateId;
+ }
+
+ /**
+ * Returns the enablement expression which is associated with this binding.
+ *
+ * @return The enablement expression or <code>null</code>.
+ */
+ public Expression getEnablement() {
+ return expression;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java
new file mode 100644
index 000000000..20768e24b
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * 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.runtime.persistence.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
+import org.eclipse.tcf.te.runtime.persistence.activator.CoreBundleActivator;
+
+
+/**
+ */
+public class PersistenceDelegateBindingExtensionPointManager extends AbstractExtensionPointManager<PersistenceDelegateBinding> {
+
+ /*
+ * Thread save singleton instance creation.
+ */
+ private static class LazyInstance {
+ public static PersistenceDelegateBindingExtensionPointManager instance = new PersistenceDelegateBindingExtensionPointManager();
+ }
+
+ /**
+ * Constructor.
+ */
+ PersistenceDelegateBindingExtensionPointManager() {
+ super();
+ }
+
+ /**
+ * Returns the singleton instance of the extension point manager.
+ */
+ public static PersistenceDelegateBindingExtensionPointManager getInstance() {
+ return LazyInstance.instance;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId()
+ */
+ @Override
+ protected String getExtensionPointId() {
+ return "org.eclipse.tcf.te.runtime.persistence.bindings"; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName()
+ */
+ @Override
+ protected String getConfigurationElementName() {
+ return "binding"; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#doCreateExtensionProxy(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ @Override
+ protected ExecutableExtensionProxy<PersistenceDelegateBinding> doCreateExtensionProxy(IConfigurationElement element) throws CoreException {
+ return new ExecutableExtensionProxy<PersistenceDelegateBinding>(element) {
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy#newInstance()
+ */
+ @Override
+ public PersistenceDelegateBinding newInstance() {
+ PersistenceDelegateBinding instance = new PersistenceDelegateBinding();
+ try {
+ instance.setInitializationData(getConfigurationElement(), null, null);
+ } catch (CoreException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ e.getLocalizedMessage(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ return instance;
+ }
+ };
+ }
+
+ /**
+ * Returns the applicable persistence delegate bindings for the given delegate context.
+ *
+ * @param context The delegate context or <code>null</code>.
+ * @return The list of applicable editor page bindings or an empty array.
+ */
+ public PersistenceDelegateBinding[] getApplicableBindings(Object context, Object container) {
+ List<PersistenceDelegateBinding> applicable = new ArrayList<PersistenceDelegateBinding>();
+
+ for (PersistenceDelegateBinding binding : getBindings()) {
+ Expression enablement = binding.getEnablement();
+
+ // The binding is applicable by default if no expression is specified.
+ boolean isApplicable = enablement == null;
+
+ if (enablement != null) {
+ if (context != null) {
+ // Set the default variable to the delegate context.
+ EvaluationContext evalContext = new EvaluationContext(null, context);
+ evalContext.addVariable("context", context); //$NON-NLS-1$
+ if (context instanceof Class) {
+ evalContext.addVariable("contextClass", ((Class<?>)context).getName()); //$NON-NLS-1$
+ }
+ evalContext.addVariable("container", container); //$NON-NLS-1$
+ if (container instanceof Class) {
+ evalContext.addVariable("containerClass", ((Class<?>)container).getName()); //$NON-NLS-1$
+ }
+ // Allow plugin activation
+ evalContext.setAllowPluginActivation(true);
+ // Evaluate the expression
+ try {
+ isApplicable = enablement.evaluate(evalContext).equals(EvaluationResult.TRUE);
+ } catch (CoreException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ e.getLocalizedMessage(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ } else {
+ // The enablement is false by definition if no delegate context is given.
+ isApplicable = false;
+ }
+ }
+
+ // Add the binding if applicable
+ if (isApplicable) {
+ applicable.add(binding);
+ }
+ }
+
+ return applicable.toArray(new PersistenceDelegateBinding[applicable.size()]);
+ }
+
+ /**
+ * Returns the list of all contributed persistence delegate bindings.
+ *
+ * @return The list of contributed persistence delegate bindings, or an empty array.
+ */
+ public PersistenceDelegateBinding[] getBindings() {
+ List<PersistenceDelegateBinding> contributions = new ArrayList<PersistenceDelegateBinding>();
+ Collection<ExecutableExtensionProxy<PersistenceDelegateBinding>> persistenceDelegateBindings = getExtensions().values();
+ for (ExecutableExtensionProxy<PersistenceDelegateBinding> persistenceDelegateBinding : persistenceDelegateBindings) {
+ PersistenceDelegateBinding instance = persistenceDelegateBinding.getInstance();
+ if (instance != null && !contributions.contains(instance)) {
+ contributions.add(instance);
+ }
+ }
+
+ return contributions.toArray(new PersistenceDelegateBinding[contributions.size()]);
+ }
+
+ /**
+ * Returns the persistence delegate binding identified by its unique id. If no persistence
+ * delegate binding with the specified id is registered, <code>null</code> is returned.
+ *
+ * @param id The unique id of the persistence delegate binding or <code>null</code>
+ *
+ * @return The persistence delegate binding instance or <code>null</code>.
+ */
+ public PersistenceDelegateBinding getBinding(String id) {
+ PersistenceDelegateBinding contribution = null;
+ if (getExtensions().containsKey(id)) {
+ ExecutableExtensionProxy<PersistenceDelegateBinding> proxy = getExtensions().get(id);
+ // Get the extension instance
+ contribution = proxy.getInstance();
+ }
+
+ return contribution;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/properties/PropertiesFilePersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/properties/PropertiesFilePersistenceDelegate.java
deleted file mode 100644
index 8522891c2..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/properties/PropertiesFilePersistenceDelegate.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*******************************************************************************
- * 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.runtime.persistence.properties;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.tcf.te.runtime.persistence.AbstractPersistenceDelegate;
-
-/**
- * Properties file persistence delegate implementation.
- * <p>
- * The persistence delegates reads and writes a simple grouped properties file format.
- */
-public class PropertiesFilePersistenceDelegate extends AbstractPersistenceDelegate {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#write(java.net.URI, java.util.Map)
- */
- @Override
- public void write(URI uri, Map<String, Object> data) throws IOException {
- Assert.isNotNull(uri);
- Assert.isNotNull(data);
-
- // Only "file:" URIs are supported
- if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
- throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Create the file object from the given URI
- File file = new File(uri.normalize());
-
- // The file must be absolute
- if (!file.isAbsolute()) {
- throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
- }
-
- // If the file extension is no set, default to "properties"
- IPath path = new Path(file.getCanonicalPath());
- if (path.getFileExtension() == null) {
- file = path.addFileExtension("properties").toFile(); //$NON-NLS-1$
- }
-
- // Create the writer object
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); //$NON-NLS-1$
- try {
- // Write the first level of attributes
- writeMap(writer, "core", data); //$NON-NLS-1$
- } finally {
- writer.close();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#delete(java.net.URI)
- */
- @Override
- public boolean delete(URI uri) throws IOException {
- Assert.isNotNull(uri);
-
- // Only "file:" URIs are supported
- if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
- throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Create the file object from the given URI
- File file = new File(uri.normalize());
-
- // The file must be absolute
- if (!file.isAbsolute()) {
- throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
- }
-
- // If the file extension is no set, default to "properties"
- IPath path = new Path(file.getCanonicalPath());
- if (path.getFileExtension() == null) {
- file = path.addFileExtension("properties").toFile(); //$NON-NLS-1$
- }
-
- return file.delete();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#read(java.net.URI)
- */
- @Override
- public Map<String, Object> read(URI uri) throws IOException {
- Assert.isNotNull(uri);
-
- // Only "file:" URIs are supported
- if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
- throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Create the file object from the given URI
- File file = new File(uri.normalize());
-
- // The file must be absolute
- if (!file.isAbsolute()) {
- throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
- }
-
- Map<String, Object> data = new HashMap<String, Object>();
-
- // Create the reader object
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); //$NON-NLS-1$
- try {
- read(reader, data);
- } finally {
- reader.close();
- }
-
- return !data.isEmpty() ? data : null;
- }
-
- /**
- * Write the map data.
- *
- * @param writer The writer. Must not be <code>null</code>.
- * @param section The section name. Must not be <code>null</code>.
- * @param data The data. Must not be <code>null</code>.
- */
- protected void writeMap(BufferedWriter writer, String section, Map<String, Object> data) throws IOException {
- Assert.isNotNull(writer);
- Assert.isNotNull(section);
- Assert.isNotNull(data);
-
- // Will contain the list of map keys where the value is a map type itself.
- List<String> childMapKeys = new ArrayList<String>();
- // Will contain the list of map keys where the value is not an map type.
- List<String> childKeys = new ArrayList<String>();
-
- // Get all the map keys and filter the map type values
- for (String key : data.keySet()) {
- if (data.get(key) instanceof Map) childMapKeys.add(key);
- else childKeys.add(key);
- }
-
- // Sort both lists
- Collections.sort(childMapKeys);
- Collections.sort(childKeys);
-
- // If the child key list is not empty, write the section
- if (!childKeys.isEmpty()) {
- // Write a new line except it is the "core" section
- if (!"core".equals(section)) writer.newLine(); //$NON-NLS-1$
-
- // Write the header
- writer.write("[" + section.trim() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
- writer.newLine();
-
- for (String key : childKeys) {
- writer.write('\t');
- writer.write(key);
- writer.write(" = "); //$NON-NLS-1$
-
- Object value = data.get(key);
- if (value instanceof List) {
- writer.write(Arrays.deepToString(((List<?>)value).toArray()));
- } else {
- writer.write(value.toString());
- }
-
- writer.newLine();
- }
- }
-
- // If there are map type values, write them now
- if (!childMapKeys.isEmpty()) {
- for (String key : childMapKeys) {
- // Calculate the section name
- String newSection = "core".equals(section) ? key.trim() : section + "." + key.trim(); //$NON-NLS-1$ //$NON-NLS-2$
- // Write it
- writeMap(writer, newSection, (Map<String, Object>)data.get(key));
- }
- }
- }
-
- private static Pattern SECTION = Pattern.compile("\\s*\\[([^\\]]+)\\]\\s*"); //$NON-NLS-1$
- private static Pattern PROPERTY = Pattern.compile("\\s*(.+\\s*=\\s*.+)"); //$NON-NLS-1$
-
- /**
- * Read the data.
- *
- * @param reader The reader. Must not be <code>null</code>.
- * @param data The data. Must not be <code>null</code>.
- */
- protected void read(BufferedReader reader, Map<String, Object> data) throws IOException {
- Assert.isNotNull(reader);
- Assert.isNotNull(data);
-
- // The sections by name for easier access.
- // The "core" section is the incoming data object
- Map<String, Map<String, Object>> sections = new HashMap<String, Map<String, Object>>();
- sections.put("core", data); //$NON-NLS-1$
-
- String currentSection = "core"; //$NON-NLS-1$
- String line = reader.readLine();
- while (line != null) {
- Matcher matcher = SECTION.matcher(line);
- if (matcher.matches()) {
- // Section names are case-sensitive too
- currentSection = matcher.group(1);
- if (sections.get(currentSection) == null) {
- sections.put(currentSection, new HashMap<String, Object>());
- }
- } else {
- matcher = PROPERTY.matcher(line);
- if (matcher.matches()) {
- String property = matcher.group(1);
- String[] pieces = property.split("=", 2); //$NON-NLS-1$
- Map<String, Object> section = sections.get(currentSection);
- section.put(pieces[0].trim(), pieces[1].trim());
- }
- }
-
- line = reader.readLine();
- }
-
- // Recreate the sections hierarchy
- for (String sectionName : sections.keySet()) {
- if ("core".equals(sectionName)) continue; //$NON-NLS-1$
- Map<String, Object> section = sections.get(sectionName);
- if (sectionName.contains(".")) { //$NON-NLS-1$
- // Split the section name and recreate the missing hierarchy
- String[] pieces = sectionName.split("\\."); //$NON-NLS-1$
- Map<String, Object> parentSection = data;
- for (String subSectionName : pieces) {
- if ("core".equals(subSectionName)) continue; //$NON-NLS-1$
-
- if (sectionName.endsWith(subSectionName)) {
- parentSection.put(subSectionName, section);
- } else {
- Map<String, Object> subSection = (Map<String, Object>)parentSection.get(subSectionName);
- if (subSection == null) {
- subSection = new HashMap<String, Object>();
- parentSection.put(subSectionName, subSection);
- }
- parentSection = subSection;
- }
- }
- } else {
- // Place it into the root object, but check if it may exist
- Map<String, Object> oldSection = (Map<String, Object>)data.get(sectionName);
- if (oldSection != null) oldSection.putAll(section);
- else data.put(sectionName, section);
- }
- }
- }
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/PersistenceService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/PersistenceService.java
deleted file mode 100644
index cf4d9fe29..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/PersistenceService.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * 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.runtime.persistence.services;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.Platform;
-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.IPersistenceDelegate;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
-import org.eclipse.tcf.te.runtime.services.AbstractService;
-
-/**
- * Persistence service implementation.
- */
-public class PersistenceService extends AbstractService implements IPersistenceService {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService#write(java.lang.Object)
- */
- @Override
- public void write(Object data) throws IOException {
- Assert.isNotNull(data);
-
- // Determine the persistable element for the given data object
- IPersistable persistable = data instanceof IPersistable ? (IPersistable)data : null;
- // If the element isn't a persistable by itself, try to adapt the element
- if (persistable == null) persistable = data instanceof IAdaptable ? (IPersistable) ((IAdaptable)data).getAdapter(IPersistable.class) : null;
- if (persistable == null) persistable = (IPersistable) Platform.getAdapterManager().getAdapter(data, IPersistable.class);
-
- // If the persistable could be still not determined, throw an IOException
- if (persistable == null) throw new IOException("'data' must be adaptable to IPersistable."); //$NON-NLS-1$
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = persistable.getStorageID() != null ? PersistenceDelegateManager.getInstance().getDelegate(persistable.getStorageID(), false) : null;
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) throw new IOException("The persistence delegate for ID '" + persistable.getStorageID() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Determine the URI
- URI uri = persistable.getURI(data);
- if (uri == null) throw new IOException("The URI cannot be determined."); //$NON-NLS-1$
-
- // Get the external representation of the data object from the
- // associated persistable.
- Map<String, Object> externalData = persistable.exportFrom(data);
- // If the external representation cannot be retrieved, throw an IOException
- if (externalData == null) throw new IOException("Failed to retrieve external data representation."); //$NON-NLS-1$
-
- // Pass on to the delegate for writing
- delegate.write(uri, externalData);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService#read(java.lang.Object)
- */
- @Override
- public void read(Object data) throws IOException {
- Assert.isNotNull(data);
-
- // Determine the persistable element for the given data object
- IPersistable persistable = data instanceof IPersistable ? (IPersistable)data : null;
- // If the element isn't a persistable by itself, try to adapt the element
- if (persistable == null) persistable = data instanceof IAdaptable ? (IPersistable) ((IAdaptable)data).getAdapter(IPersistable.class) : null;
- if (persistable == null) persistable = (IPersistable) Platform.getAdapterManager().getAdapter(data, IPersistable.class);
-
- // If the persistable could be still not determined, throw an IOException
- if (persistable == null) throw new IOException("'data' must be adaptable to IPersistable."); //$NON-NLS-1$
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = persistable.getStorageID() != null ? PersistenceDelegateManager.getInstance().getDelegate(persistable.getStorageID(), false) : null;
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) throw new IOException("The persistence delegate for ID '" + persistable.getStorageID() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Determine the URI
- URI uri = persistable.getURI(data);
- if (uri == null) throw new IOException("The URI cannot be determined."); //$NON-NLS-1$
-
- // Pass on to the delegate for reading
- Map<String, Object> externalData = delegate.read(uri);
- if (externalData == null) throw new IOException("Failed to read external data representation from URI '" + uri.toString() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Import the external representation into the data object via
- // the associated persistable
- persistable.importTo(data, externalData);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService#delete(java.lang.Object)
- */
- @Override
- public boolean delete(Object data) throws IOException {
- Assert.isNotNull(data);
-
- // Determine the persistable element for the given data object
- IPersistable persistable = data instanceof IPersistable ? (IPersistable)data : null;
- // If the element isn't a persistable by itself, try to adapt the element
- if (persistable == null) persistable = data instanceof IAdaptable ? (IPersistable) ((IAdaptable)data).getAdapter(IPersistable.class) : null;
- if (persistable == null) persistable = (IPersistable) Platform.getAdapterManager().getAdapter(data, IPersistable.class);
-
- // If the persistable could be still not determined, throw an IOException
- if (persistable == null) throw new IOException("'data' must be adaptable to IPersistable."); //$NON-NLS-1$
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = persistable.getStorageID() != null ? PersistenceDelegateManager.getInstance().getDelegate(persistable.getStorageID(), false) : null;
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) throw new IOException("The persistence delegate for ID '" + persistable.getStorageID() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Determine the URI
- URI uri = persistable.getURI(data);
- if (uri == null) throw new IOException("The URI cannot be determined."); //$NON-NLS-1$
-
- // Pass on to the delegate for deleting
- return delegate.delete(uri);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService#getURI(java.lang.Object)
- */
- @Override
- public URI getURI(Object data) throws IOException {
- Assert.isNotNull(data);
-
- // Determine the persistable element for the given data object
- IPersistable persistable = data instanceof IPersistable ? (IPersistable)data : null;
- // If the element isn't a persistable by itself, try to adapt the element
- if (persistable == null) persistable = data instanceof IAdaptable ? (IPersistable) ((IAdaptable)data).getAdapter(IPersistable.class) : null;
- if (persistable == null) persistable = (IPersistable) Platform.getAdapterManager().getAdapter(data, IPersistable.class);
-
- // If the persistable could be still not determined, throw an IOException
- if (persistable == null) throw new IOException("'data' must be adaptable to IPersistable."); //$NON-NLS-1$
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = persistable.getStorageID() != null ? PersistenceDelegateManager.getInstance().getDelegate(persistable.getStorageID(), false) : null;
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) throw new IOException("The persistence delegate for ID '" + persistable.getStorageID() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Determine the URI
- return persistable.getURI(data);
- }
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java
new file mode 100644
index 000000000..41942ce5f
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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.runtime.persistence.services;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.tcf.te.runtime.persistence.PersistenceManager;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
+import org.eclipse.tcf.te.runtime.services.AbstractService;
+
+/**
+ * Persistence service implementation.
+ */
+public class URIPersistenceService extends AbstractService implements IURIPersistenceService {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#write(java.lang.Object, java.net.URI)
+ */
+ @Override
+ public void write(Object context, URI uri) throws IOException {
+ Assert.isNotNull(context);
+
+ uri = uri != null ? uri : getURI(context);
+
+ // Determine the persistence delegate
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri, false);
+ // If the persistence delegate could not be determined, throw an IOException
+ if (delegate == null) {
+ throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Pass on to the delegate for writing
+ delegate.write(context, uri, null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#read(java.net.URI, java.lang.Object)
+ */
+ @Override
+ public Object read(URI uri, Object context) throws IOException {
+ Assert.isNotNull(context);
+
+ uri = uri != null ? uri : getURI(context);
+
+ // Determine the persistence delegate
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri, false);
+ // If the persistence delegate could not be determined, throw an IOException
+ if (delegate == null) {
+ throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Pass on to the delegate for reading
+ return delegate.read(context, uri, null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#delete(java.lang.Object, java.net.URI)
+ */
+ @Override
+ public boolean delete(Object context, URI uri) throws IOException {
+ Assert.isNotNull(context);
+
+ uri = uri != null ? uri : getURI(context);
+
+ // Determine the persistence delegate
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri, false);
+ // If the persistence delegate could not be determined, throw an IOException
+ if (delegate == null) {
+ throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return delegate.delete(context, uri, null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#getURI(java.lang.Object)
+ */
+ @Override
+ public URI getURI(Object context) throws IOException {
+ Assert.isNotNull(context);
+
+ // Determine the persistable element for the given data object
+ IPersistableURIProvider persistableURIProvider = context instanceof IPersistableURIProvider ? (IPersistableURIProvider)context : null;
+ // If the element isn't a persistable by itself, try to adapt the element
+ if (persistableURIProvider == null) {
+ persistableURIProvider = context instanceof IAdaptable ? (IPersistableURIProvider) ((IAdaptable)context).getAdapter(IPersistableURIProvider.class) : null;
+ }
+ if (persistableURIProvider == null) {
+ persistableURIProvider = (IPersistableURIProvider) Platform.getAdapterManager().getAdapter(context, IPersistableURIProvider.class);
+ }
+
+ // If the persistable could be still not determined, throw an IOException
+ if (persistableURIProvider == null) {
+ throw new IOException("'context' must be adaptable to IPersistableURIProvider."); //$NON-NLS-1$
+ }
+
+ URI uri = persistableURIProvider.getURI(context);
+
+ if (uri == null) {
+ throw new IOException("The URI cannot be determined for context '" + context.getClass().getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Determine the URI
+ return uri;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/schema/bindings.exsd b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/schema/bindings.exsd
index fe0131db8..cb8332335 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/schema/bindings.exsd
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/schema/bindings.exsd
@@ -8,7 +8,7 @@
<documentation>
This extension point is used to declare the status handler bindings.
&lt;p&gt;
-&lt;b&gt;Note:&lt;/b&gt; For the enablement expression evaluation, note that only the default variable is set and it is non-iterable. The default variable is set to the handler context, which is typically the object calling the status handler.
+&lt;b&gt;Note:&lt;/b&gt; For the enablement expression evaluation, note that only the default variable and &quot;context&quot; is set and it is non-iterable. The default variable and &quot;context&quot; is set to the handler context, which is typically the object calling the status handler.
</documentation>
</annotation>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/internal/StatusHandlerBindingExtensionPointManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/internal/StatusHandlerBindingExtensionPointManager.java
index f93a3991d..8d80604ab 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/internal/StatusHandlerBindingExtensionPointManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/internal/StatusHandlerBindingExtensionPointManager.java
@@ -1,173 +1,176 @@
-/*******************************************************************************
- * 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.runtime.statushandler.internal;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.expressions.EvaluationContext;
-import org.eclipse.core.expressions.EvaluationResult;
-import org.eclipse.core.expressions.Expression;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager;
-import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
-import org.eclipse.tcf.te.runtime.statushandler.activator.CoreBundleActivator;
-
-
-/**
- * Status handler binding extension point manager implementation.
- */
-public class StatusHandlerBindingExtensionPointManager extends AbstractExtensionPointManager<StatusHandlerBinding> {
-
- /*
- * Thread save singleton instance creation.
- */
- private static class LazyInstance {
- public static StatusHandlerBindingExtensionPointManager instance = new StatusHandlerBindingExtensionPointManager();
- }
-
- /**
- * Constructor.
- */
- StatusHandlerBindingExtensionPointManager() {
- super();
- }
-
- /**
- * Returns the singleton instance of the extension point manager.
- */
- public static StatusHandlerBindingExtensionPointManager getInstance() {
- return LazyInstance.instance;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId()
- */
- @Override
- protected String getExtensionPointId() {
- return "org.eclipse.tcf.te.runtime.statushandler.bindings"; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName()
- */
- @Override
- protected String getConfigurationElementName() {
- return "binding"; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#doCreateExtensionProxy(org.eclipse.core.runtime.IConfigurationElement)
- */
- @Override
- protected ExecutableExtensionProxy<StatusHandlerBinding> doCreateExtensionProxy(IConfigurationElement element) throws CoreException {
- return new ExecutableExtensionProxy<StatusHandlerBinding>(element) {
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy#newInstance()
- */
- @Override
- public StatusHandlerBinding newInstance() {
- StatusHandlerBinding instance = new StatusHandlerBinding();
- try {
- instance.setInitializationData(getConfigurationElement(), null, null);
- } catch (CoreException e) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- e.getLocalizedMessage(), e);
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- return instance;
- }
- };
- }
-
- /**
- * Returns the applicable status handler bindings for the given handler context.
- *
- * @param context The handler context or <code>null</code>.
- * @return The list of applicable editor page bindings or an empty array.
- */
- public StatusHandlerBinding[] getApplicableBindings(Object context) {
- List<StatusHandlerBinding> applicable = new ArrayList<StatusHandlerBinding>();
-
- for (StatusHandlerBinding binding : getBindings()) {
- Expression enablement = binding.getEnablement();
-
- // The binding is applicable by default if no expression is specified.
- boolean isApplicable = enablement == null;
-
- if (enablement != null) {
- if (context != null) {
- // Set the default variable to the handler context.
- EvaluationContext evalContext = new EvaluationContext(null, context);
- // Allow plugin activation
- evalContext.setAllowPluginActivation(true);
- // Evaluate the expression
- try {
- isApplicable = enablement.evaluate(evalContext).equals(EvaluationResult.TRUE);
- } catch (CoreException e) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- e.getLocalizedMessage(), e);
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- } else {
- // The enablement is false by definition if no handler context is given.
- isApplicable = false;
- }
- }
-
- // Add the binding if applicable
- if (isApplicable) applicable.add(binding);
- }
-
- return applicable.toArray(new StatusHandlerBinding[applicable.size()]);
- }
-
- /**
- * Returns the list of all contributed status handler bindings.
- *
- * @return The list of contributed status handler bindings, or an empty array.
- */
- public StatusHandlerBinding[] getBindings() {
- List<StatusHandlerBinding> contributions = new ArrayList<StatusHandlerBinding>();
- Collection<ExecutableExtensionProxy<StatusHandlerBinding>> statusHandlerBindings = getExtensions().values();
- for (ExecutableExtensionProxy<StatusHandlerBinding> statusHandlerBinding : statusHandlerBindings) {
- StatusHandlerBinding instance = statusHandlerBinding.getInstance();
- if (instance != null && !contributions.contains(instance)) {
- contributions.add(instance);
- }
- }
-
- return contributions.toArray(new StatusHandlerBinding[contributions.size()]);
- }
-
- /**
- * Returns the status handler binding identified by its unique id. If no status
- * handler binding with the specified id is registered, <code>null</code> is returned.
- *
- * @param id The unique id of the status handler binding or <code>null</code>
- *
- * @return The status handler binding instance or <code>null</code>.
- */
- public StatusHandlerBinding getBinding(String id) {
- StatusHandlerBinding contribution = null;
- if (getExtensions().containsKey(id)) {
- ExecutableExtensionProxy<StatusHandlerBinding> proxy = getExtensions().get(id);
- // Get the extension instance
- contribution = proxy.getInstance();
- }
-
- return contribution;
- }
-}
+/*******************************************************************************
+ * 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.runtime.statushandler.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
+import org.eclipse.tcf.te.runtime.statushandler.activator.CoreBundleActivator;
+
+
+/**
+ * Status handler binding extension point manager implementation.
+ */
+public class StatusHandlerBindingExtensionPointManager extends AbstractExtensionPointManager<StatusHandlerBinding> {
+
+ /*
+ * Thread save singleton instance creation.
+ */
+ private static class LazyInstance {
+ public static StatusHandlerBindingExtensionPointManager instance = new StatusHandlerBindingExtensionPointManager();
+ }
+
+ /**
+ * Constructor.
+ */
+ StatusHandlerBindingExtensionPointManager() {
+ super();
+ }
+
+ /**
+ * Returns the singleton instance of the extension point manager.
+ */
+ public static StatusHandlerBindingExtensionPointManager getInstance() {
+ return LazyInstance.instance;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId()
+ */
+ @Override
+ protected String getExtensionPointId() {
+ return "org.eclipse.tcf.te.runtime.statushandler.bindings"; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName()
+ */
+ @Override
+ protected String getConfigurationElementName() {
+ return "binding"; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#doCreateExtensionProxy(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ @Override
+ protected ExecutableExtensionProxy<StatusHandlerBinding> doCreateExtensionProxy(IConfigurationElement element) throws CoreException {
+ return new ExecutableExtensionProxy<StatusHandlerBinding>(element) {
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy#newInstance()
+ */
+ @Override
+ public StatusHandlerBinding newInstance() {
+ StatusHandlerBinding instance = new StatusHandlerBinding();
+ try {
+ instance.setInitializationData(getConfigurationElement(), null, null);
+ } catch (CoreException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ e.getLocalizedMessage(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ return instance;
+ }
+ };
+ }
+
+ /**
+ * Returns the applicable status handler bindings for the given handler context.
+ *
+ * @param context The handler context or <code>null</code>.
+ * @return The list of applicable editor page bindings or an empty array.
+ */
+ public StatusHandlerBinding[] getApplicableBindings(Object context) {
+ List<StatusHandlerBinding> applicable = new ArrayList<StatusHandlerBinding>();
+
+ for (StatusHandlerBinding binding : getBindings()) {
+ Expression enablement = binding.getEnablement();
+
+ // The binding is applicable by default if no expression is specified.
+ boolean isApplicable = enablement == null;
+
+ if (enablement != null) {
+ if (context != null) {
+ // Set the default variable to the handler context.
+ EvaluationContext evalContext = new EvaluationContext(null, context);
+ evalContext.addVariable("context", context); //$NON-NLS-1$
+ // Allow plugin activation
+ evalContext.setAllowPluginActivation(true);
+ // Evaluate the expression
+ try {
+ isApplicable = enablement.evaluate(evalContext).equals(EvaluationResult.TRUE);
+ } catch (CoreException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ e.getLocalizedMessage(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ } else {
+ // The enablement is false by definition if no handler context is given.
+ isApplicable = false;
+ }
+ }
+
+ // Add the binding if applicable
+ if (isApplicable) {
+ applicable.add(binding);
+ }
+ }
+
+ return applicable.toArray(new StatusHandlerBinding[applicable.size()]);
+ }
+
+ /**
+ * Returns the list of all contributed status handler bindings.
+ *
+ * @return The list of contributed status handler bindings, or an empty array.
+ */
+ public StatusHandlerBinding[] getBindings() {
+ List<StatusHandlerBinding> contributions = new ArrayList<StatusHandlerBinding>();
+ Collection<ExecutableExtensionProxy<StatusHandlerBinding>> statusHandlerBindings = getExtensions().values();
+ for (ExecutableExtensionProxy<StatusHandlerBinding> statusHandlerBinding : statusHandlerBindings) {
+ StatusHandlerBinding instance = statusHandlerBinding.getInstance();
+ if (instance != null && !contributions.contains(instance)) {
+ contributions.add(instance);
+ }
+ }
+
+ return contributions.toArray(new StatusHandlerBinding[contributions.size()]);
+ }
+
+ /**
+ * Returns the status handler binding identified by its unique id. If no status
+ * handler binding with the specified id is registered, <code>null</code> is returned.
+ *
+ * @param id The unique id of the status handler binding or <code>null</code>
+ *
+ * @return The status handler binding instance or <code>null</code>.
+ */
+ public StatusHandlerBinding getBinding(String id) {
+ StatusHandlerBinding contribution = null;
+ if (getExtensions().containsKey(id)) {
+ ExecutableExtensionProxy<StatusHandlerBinding> proxy = getExtensions().get(id);
+ // Get the extension instance
+ contribution = proxy.getInstance();
+ }
+
+ return contribution;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/dialogs/FSFolderSelectionDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/dialogs/FSFolderSelectionDialog.java
index cdcc39117..3cc6b5980 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/dialogs/FSFolderSelectionDialog.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/dialogs/FSFolderSelectionDialog.java
@@ -101,7 +101,7 @@ public class FSFolderSelectionDialog extends ElementTreeSelectionDialog {
}
});
}
-
+
/**
* The viewer filter used to filter out files.
*/
@@ -115,22 +115,24 @@ public class FSFolderSelectionDialog extends ElementTreeSelectionDialog {
return false;
}
}
-
+
/*
* (non-Javadoc)
* @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#setInput(java.lang.Object)
*/
@Override
- public void setInput(Object input) {
+ public void setInput(Object input) {
super.setInput(input);
FilterDescriptor[] filterDescriptors = ViewerStateManager.getInstance().getFilterDescriptors(IFSConstants.ID_TREE_VIEWER_FS, input);
if (filterDescriptors != null) {
for(FilterDescriptor descriptor : filterDescriptors) {
- if(descriptor.isEnabled()) addFilter(descriptor.getFilter());
+ if(descriptor.isEnabled()) {
+ addFilter(descriptor.getFilter());
+ }
}
}
}
-
+
/**
* Create a decorating label provider using the specified label provider.
*
@@ -179,13 +181,16 @@ public class FSFolderSelectionDialog extends ElementTreeSelectionDialog {
return error;
}
FSTreeNode target = (FSTreeNode) selection[0];
- for (FSTreeNode node : movedNodes) {
- if (node == target || node.isAncestorOf(target)) {
- return error;
+ if (movedNodes != null) {
+ for (FSTreeNode node : movedNodes) {
+ if (node == target || node.isAncestorOf(target)) {
+ return error;
+ }
}
}
- if(!target.isWritable())
+ if(!target.isWritable()) {
return error;
+ }
return new Status(IStatus.OK, pluginId, null);
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/META-INF/MANIFEST.MF
index 70bfceff9..8e1d4772c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/META-INF/MANIFEST.MF
@@ -18,7 +18,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.tcf.te.launch.core;bundle-version="1.0.0",
org.eclipse.tcf.te.tcf.core;bundle-version="1.0.0",
org.eclipse.tcf.te.tcf.locator;bundle-version="1.0.0",
- org.eclipse.tcf.te.tcf.processes.core;bundle-version="1.0.0"
+ org.eclipse.tcf.te.tcf.processes.core;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.persistence;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml
index 908b10a97..1ec368f6b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml
@@ -57,7 +57,7 @@
<!-- Launch Manager Delegate contributions -->
<extension point="org.eclipse.tcf.te.launch.core.launchManagerDelegates">
<delegate
- class="org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate"
+ class="org.eclipse.tcf.te.tcf.launch.core.lm.delegates.RemoteAppLaunchManagerDelegate"
id="org.eclipse.tcf.te.tcf.launch.type.remote.app.launchManagerDelegate">
</delegate>
</extension>
@@ -110,4 +110,76 @@
</step>
</extension>
+<!-- Persistence delegate contributions -->
+ <extension point="org.eclipse.tcf.te.runtime.persistence.delegates">
+ <delegate
+ id="org.eclipse.tcf.te.tcf.launch.core.persistence.fileTransferToString"
+ class="org.eclipse.tcf.te.tcf.launch.core.internal.FileTransferItemToStringPersistenceDelegate">
+ </delegate>
+ <delegate
+ id="org.eclipse.tcf.te.tcf.launch.core.persistence.referencedProjectToString"
+ class="org.eclipse.tcf.te.tcf.launch.core.internal.ReferencedProjectItemToStringPersistenceDelegate">
+ </delegate>
+ </extension>
+
+<!-- Persistence delegate bindings contributions -->
+ <extension point="org.eclipse.tcf.te.runtime.persistence.bindings">
+ <binding
+ delegateId="org.eclipse.tcf.te.tcf.launch.core.persistence.fileTransferToString"
+ id="org.eclipse.tcf.te.tcf.launch.core.binding.fileTransferToString">
+ <enablement>
+ <with variable="container">
+ <or>
+ <instanceof value="java.lang.String"/>
+ <and>
+ <instanceof value="java.lang.Class"/>
+ <with variable="containerClass">
+ <equals value="java.lang.String"/>
+ </with>
+ </and>
+ </or>
+ </with>
+ <with variable="context">
+ <or>
+ <instanceof value="org.eclipse.tcf.te.launch.core.interfaces.IFileTransferItem"/>
+ <and>
+ <instanceof value="java.lang.Class"/>
+ <with variable="contextClass">
+ <equals value="org.eclipse.tcf.te.launch.core.interfaces.IFileTransferItem"/>
+ </with>
+ </and>
+ </or>
+ </with>
+ </enablement>
+ </binding>
+ <binding
+ delegateId="org.eclipse.tcf.te.tcf.launch.core.persistence.referencedProjectToString"
+ id="org.eclipse.tcf.te.tcf.launch.core.binding.referencedProjectToString">
+ <enablement>
+ <with variable="container">
+ <or>
+ <instanceof value="java.lang.String"/>
+ <and>
+ <instanceof value="java.lang.Class"/>
+ <with variable="containerClass">
+ <equals value="java.lang.String"/>
+ </with>
+ </and>
+ </or>
+ </with>
+ <with variable="context">
+ <or>
+ <instanceof value="org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem"/>
+ <and>
+ <instanceof value="java.lang.Class"/>
+ <with variable="contextClass">
+ <equals value="org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem"/>
+ </with>
+ </and>
+ </or>
+ </with>
+ </enablement>
+ </binding>
+ </extension>
+
</plugin>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/interfaces/ILinuxAppLaunchAttributes.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/interfaces/IRemoteAppLaunchAttributes.java
index cf0306488..7dcdd501e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/interfaces/ILinuxAppLaunchAttributes.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/interfaces/IRemoteAppLaunchAttributes.java
@@ -14,7 +14,7 @@ import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes;
/**
* Defines the launch configuration attribute id's to access the launch step contexts.
*/
-public interface ILinuxAppLaunchAttributes {
+public interface IRemoteAppLaunchAttributes {
/**
* Define the prefix used by all other attribute id's as prefix.
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/FileTransferItemToStringPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/FileTransferItemToStringPersistenceDelegate.java
new file mode 100644
index 000000000..0ec8ad123
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/FileTransferItemToStringPersistenceDelegate.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.launch.core.internal;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.tcf.te.launch.core.interfaces.IFileTransferItem;
+import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransferItem;
+import org.eclipse.tcf.te.tcf.locator.persistence.AbstractPropertiesToStringPersistenceDelegate;
+
+/**
+ * File transfer item to string delegate implementation.
+ */
+public class FileTransferItemToStringPersistenceDelegate extends AbstractPropertiesToStringPersistenceDelegate {
+
+ /**
+ * Constructor.
+ */
+ public FileTransferItemToStringPersistenceDelegate() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#getPersistedClassName(java.lang.Object)
+ */
+ @Override
+ public Class<?> getPersistedClass(Object context) {
+ return IFileTransferItem.class;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#toMap(java.lang.Object)
+ */
+ @Override
+ protected Map<String, Object> toMap(final Object context) throws IOException {
+ IFileTransferItem item = getFileTransferItem(context);
+ if (item != null) {
+ return super.toMap(item.getProperties());
+ }
+
+ return new HashMap<String, Object>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#fromMap(java.util.Map, java.lang.Object)
+ */
+ @Override
+ protected Object fromMap(Map<String, Object> map, Object context) throws IOException {
+ IFileTransferItem item = new FileTransferItem();
+ item.setProperties(map);
+ return item;
+ }
+
+ /**
+ * Get a file transfer item from the given context.
+ *
+ * @param context The context. Mut not be <code>null</code>.
+ * @return The file transfer item or <code>null</code>.
+ */
+ protected IFileTransferItem getFileTransferItem(Object context) {
+ IFileTransferItem item = null;
+
+ if (context instanceof IFileTransferItem) {
+ item = (IFileTransferItem)context;
+ }
+
+ return item;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/ReferencedProjectItemToStringPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/ReferencedProjectItemToStringPersistenceDelegate.java
new file mode 100644
index 000000000..add8a8690
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/ReferencedProjectItemToStringPersistenceDelegate.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.launch.core.internal;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem;
+import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectItem;
+import org.eclipse.tcf.te.tcf.locator.persistence.AbstractPropertiesToStringPersistenceDelegate;
+
+/**
+ * Referenced project item to string delegate implementation.
+ */
+public class ReferencedProjectItemToStringPersistenceDelegate extends AbstractPropertiesToStringPersistenceDelegate {
+
+ /**
+ * Constructor.
+ */
+ public ReferencedProjectItemToStringPersistenceDelegate() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#getPersistedClassName(java.lang.Object)
+ */
+ @Override
+ public Class<?> getPersistedClass(Object context) {
+ return IReferencedProjectItem.class;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#toMap(java.lang.Object)
+ */
+ @Override
+ protected Map<String, Object> toMap(final Object context) throws IOException {
+ IReferencedProjectItem item = getReferencedProjectItem(context);
+ if (item != null) {
+ return super.toMap(item.getProperties());
+ }
+
+ return new HashMap<String, Object>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#fromMap(java.util.Map, java.lang.Object)
+ */
+ @Override
+ protected Object fromMap(Map<String, Object> map, Object context) throws IOException {
+ IReferencedProjectItem item = new ReferencedProjectItem();
+ item.setProperties(map);
+ return item;
+ }
+
+ /**
+ * Get a referenced project item from the given context.
+ *
+ * @param context The context. Mut not be <code>null</code>.
+ * @return The referenced project item or <code>null</code>.
+ */
+ protected IReferencedProjectItem getReferencedProjectItem(Object context) {
+ IReferencedProjectItem item = null;
+
+ if (context instanceof IReferencedProjectItem) {
+ item = (IReferencedProjectItem)context;
+ }
+
+ return item;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/RemoteAppLaunchManagerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/RemoteAppLaunchManagerDelegate.java
new file mode 100644
index 000000000..b15f860ed
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/RemoteAppLaunchManagerDelegate.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.launch.core.lm.delegates;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.launch.core.interfaces.IFileTransferItem;
+import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem;
+import org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IFileTransferLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IReferencedProjectLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransferItem;
+import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransfersPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectItem;
+import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectsPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.IProjectSelectionContext;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
+
+/**
+ * RemoteAppLaunchManagerDelegate
+ * @author tobias.schwarz@windriver.com
+ */
+public class RemoteAppLaunchManagerDelegate extends DefaultLaunchManagerDelegate {
+
+ /**
+ * Constructor.
+ */
+ public RemoteAppLaunchManagerDelegate() {
+ super();
+ }
+
+ @Override
+ public void initLaunchConfigAttributes(ILaunchConfigurationWorkingCopy wc, ILaunchSpecification launchSpec) {
+ super.initLaunchConfigAttributes(wc, launchSpec);
+
+ if (launchSpec.hasAttribute(IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS)) {
+ wc.setAttribute(IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS, (String)launchSpec.getAttribute(IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS).getValue());
+ }
+ if (launchSpec.hasAttribute(IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS)) {
+ wc.setAttribute(IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS, (String)launchSpec.getAttribute(IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS).getValue());
+ }
+ }
+
+ @Override
+ protected ILaunchSpecification addLaunchSpecAttributes(ILaunchSpecification launchSpec, String launchConfigTypeId, ISelectionContext selectionContext) {
+ launchSpec = super.addLaunchSpecAttributes(launchSpec, launchConfigTypeId, selectionContext);
+
+ if (selectionContext instanceof IProjectSelectionContext) {
+ List<IFileTransferItem> transfers = new ArrayList<IFileTransferItem>(Arrays.asList(FileTransfersPersistenceDelegate.getFileTransfers(launchSpec)));
+ List<IReferencedProjectItem> projects = new ArrayList<IReferencedProjectItem>(Arrays.asList(ReferencedProjectsPersistenceDelegate.getReferencedProjects(launchSpec)));
+
+ boolean added = false;
+ for (Object selection : selectionContext.getSelections()) {
+ if (selection instanceof IPath) {
+ IPath path = (IPath)selection;
+ IFileTransferItem transfer = new FileTransferItem();
+ transfer.setProperty(IFileTransferItem.PROPERTY_ENABLED, true);
+ transfer.setProperty(IFileTransferItem.PROPERTY_HOST, path.toPortableString());
+ transfer.setProperty(IFileTransferItem.PROPERTY_DIRECTION, IFileTransferItem.HOST_TO_TARGET);
+ transfer.setProperty(IFileTransferItem.PROPERTY_HOST, new Path("/tmp/").toPortableString()); //$NON-NLS-1$
+ transfers.add(transfer);
+ added = true;
+ }
+ }
+
+ if (added) {
+ IReferencedProjectItem project = new ReferencedProjectItem();
+ project.setProperty(IReferencedProjectItem.PROPERTY_ENABLED, true);
+ project.setProperty(IReferencedProjectItem.PROPERTY_PROJECT_NAME, ((IProjectSelectionContext)selectionContext).getProjectCtx().getName());
+ projects.add(project);
+ }
+
+ FileTransfersPersistenceDelegate.setFileTransfers(launchSpec, transfers.toArray(new IFileTransferItem[transfers.size()]));
+ ReferencedProjectsPersistenceDelegate.setReferencedProjects(launchSpec, projects.toArray(new IReferencedProjectItem[projects.size()]));
+ }
+
+ return launchSpec;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/LaunchProcessStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/LaunchProcessStep.java
index 15ea054f9..638fd6712 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/LaunchProcessStep.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/LaunchProcessStep.java
@@ -26,7 +26,7 @@ import org.eclipse.tcf.te.runtime.stepper.StepperAttributeUtil;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext;
import org.eclipse.tcf.te.tcf.launch.core.activator.CoreBundleActivator;
-import org.eclipse.tcf.te.tcf.launch.core.interfaces.ILinuxAppLaunchAttributes;
+import org.eclipse.tcf.te.tcf.launch.core.interfaces.IRemoteAppLaunchAttributes;
import org.eclipse.tcf.te.tcf.processes.core.interfaces.launcher.IProcessLauncher;
import org.eclipse.tcf.te.tcf.processes.core.launcher.ProcessLauncher;
@@ -46,16 +46,16 @@ public class LaunchProcessStep extends AbstractTcfLaunchStep {
*/
@Override
public void validateExecute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor) throws CoreException {
- String processImage = DefaultPersistenceDelegate.getAttribute(getLaunchConfiguration(context), ILinuxAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
+ String processImage = DefaultPersistenceDelegate.getAttribute(getLaunchConfiguration(context), IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
if (processImage != null && processImage.trim().length() > 0) {
- StepperAttributeUtil.setProperty(ILinuxAppLaunchAttributes.ATTR_PROCESS_IMAGE, fullQualifiedId, data, processImage);
+ StepperAttributeUtil.setProperty(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, fullQualifiedId, data, processImage);
}
else {
throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "missing process image name")); //$NON-NLS-1$
}
- String processArguments = DefaultPersistenceDelegate.getAttribute(getLaunchConfiguration(context), ILinuxAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, (String)null);
- StepperAttributeUtil.setProperty(ILinuxAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, fullQualifiedId, data, processArguments);
+ String processArguments = DefaultPersistenceDelegate.getAttribute(getLaunchConfiguration(context), IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, (String)null);
+ StepperAttributeUtil.setProperty(IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, fullQualifiedId, data, processArguments);
}
/* (non-Javadoc)
@@ -68,9 +68,9 @@ public class LaunchProcessStep extends AbstractTcfLaunchStep {
Map<String, Object> launchAttributes = new HashMap<String, Object>();
- launchAttributes.put(IProcessLauncher.PROP_PROCESS_PATH, StepperAttributeUtil.getStringProperty(ILinuxAppLaunchAttributes.ATTR_PROCESS_IMAGE, fullQualifiedId, data));
+ launchAttributes.put(IProcessLauncher.PROP_PROCESS_PATH, StepperAttributeUtil.getStringProperty(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, fullQualifiedId, data));
- String arguments = StepperAttributeUtil.getStringProperty(ILinuxAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, fullQualifiedId, data);
+ String arguments = StepperAttributeUtil.getStringProperty(IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, fullQualifiedId, data);
String[] args = arguments != null && !"".equals(arguments.trim()) ? StringUtil.tokenize(arguments, 0, true) : null; //$NON-NLS-1$
launchAttributes.put(IProcessLauncher.PROP_PROCESS_ARGS, args);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.java
index dca541478..8ec2522ef 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.java
@@ -35,4 +35,43 @@ public class Messages extends NLS {
public static String ProcessImageSelectorControl_label;
public static String ProcessImageSelectorControl_error_missingProcessImage;
+ public static String FileTransferTab_name;
+
+ public static String FileTransferSection_title;
+ public static String FileTransferSection_description;
+ public static String FileTransferSection_host_column;
+ public static String FileTransferSection_target_column;
+ public static String FileTransferSection_options_column;
+ public static String FileTransferSection_add_button;
+ public static String FileTransferSection_edit_button;
+ public static String FileTransferSection_delete_button;
+ public static String FileTransferSection_up_button;
+ public static String FileTransferSection_down_button;
+ public static String FileTransferSection_toHost_text;
+ public static String FileTransferSection_toTarget_text;
+ public static String FileTransferSection_toHost_tooltip;
+ public static String FileTransferSection_toTarget_tooltip;
+
+ public static String ReferencedProjectsTab_name;
+
+ public static String ReferencedProjectsSection_title;
+ public static String ReferencedProjectsSection_description;
+ public static String ReferencedProjectsSection_project_column;
+ public static String ReferencedProjectsSection_add_button;
+ public static String ReferencedProjectsSection_delete_button;
+ public static String ReferencedProjectsSection_up_button;
+ public static String ReferencedProjectsSection_down_button;
+ public static String ReferencedProjectsSection_addDialog_message;
+
+ public static String AddEditFileTransferDialog_add_dialogTitle;
+ public static String AddEditFileTransferDialog_edit_dialogTitle;
+ public static String AddEditFileTransferDialog_add_title;
+ public static String AddEditFileTransferDialog_edit_title;
+ public static String AddEditFileTransferDialog_add_message;
+ public static String AddEditFileTransferDialog_edit_message;
+ public static String AddEditFileTransferDialog_target_label;
+ public static String AddEditFileTransferDialog_host_label;
+ public static String AddEditFileTransferDialog_options_label;
+ public static String AddEditFileTransferDialog_toHost_checkbox;
+ public static String AddEditFileTransferDialog_toTarget_checkbox;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.properties
index 1cf47ceb5..500e106cf 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/nls/Messages.properties
@@ -8,3 +8,44 @@ LaunchConfigurationMainTabSection_processArguments_label = Arguments:
ProcessImageSelectorControl_label = Process Image:
ProcessImageSelectorControl_error_missingProcessImage = Please select or enter a process image.
+
+FileTransferTab_name = File Transfers
+
+FileTransferSection_title = File Transfers
+FileTransferSection_description = File Transfers
+FileTransferSection_host_column = Host
+FileTransferSection_target_column = Target
+FileTransferSection_options_column = Options
+FileTransferSection_add_button = Add
+FileTransferSection_edit_button = Edit
+FileTransferSection_delete_button = Delete
+FileTransferSection_up_button = Up
+FileTransferSection_down_button = Down
+FileTransferSection_toHost_tooltip = Transfer from Target to Host
+FileTransferSection_toTarget_tooltip = Transfer from Host to Target
+FileTransferSection_toHost_text = <<
+FileTransferSection_toTarget_text = >>
+
+ReferencedProjectsTab_name = Referenced Projects
+
+ReferencedProjectsSection_title = Referenced Projects
+ReferencedProjectsSection_description = Referenced Projects
+ReferencedProjectsSection_project_column = Project
+ReferencedProjectsSection_add_button = Add
+ReferencedProjectsSection_delete_button = Delete
+ReferencedProjectsSection_up_button = Up
+ReferencedProjectsSection_down_button = Down
+ReferencedProjectsSection_addDialog_message = Select projects that should be built before launch.
+
+AddEditFileTransferDialog_add_dialogTitle = Add
+AddEditFileTransferDialog_edit_dialogTitle = Edit
+AddEditFileTransferDialog_add_title = Add new file transfer
+AddEditFileTransferDialog_edit_title = Edit existing file transfer
+AddEditFileTransferDialog_add_message = Please enter the host and traget file/directory.
+AddEditFileTransferDialog_edit_message = Change the host or target file/directory or the direction.
+AddEditFileTransferDialog_target_label = Target:
+AddEditFileTransferDialog_host_label = Host:
+AddEditFileTransferDialog_options_label = Options:
+AddEditFileTransferDialog_toHost_checkbox = Transfer from Target to Host
+AddEditFileTransferDialog_toTarget_checkbox = Transfer from Host to Target
+ \ No newline at end of file
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationMainTabSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationMainTabSection.java
index 31e1f01f0..ff4132bbc 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationMainTabSection.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationMainTabSection.java
@@ -18,13 +18,13 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.tcf.te.launch.core.persistence.ContextSelectorPersistenceDelegate;
import org.eclipse.tcf.te.launch.core.persistence.DefaultPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.launchcontext.LaunchContextsPersistenceDelegate;
import org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart;
import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
import org.eclipse.tcf.te.tcf.filesystem.dialogs.FSOpenFileDialog;
import org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode;
-import org.eclipse.tcf.te.tcf.launch.core.interfaces.ILinuxAppLaunchAttributes;
+import org.eclipse.tcf.te.tcf.launch.core.interfaces.IRemoteAppLaunchAttributes;
import org.eclipse.tcf.te.tcf.launch.ui.nls.Messages;
import org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl;
import org.eclipse.tcf.te.ui.forms.parts.AbstractSection;
@@ -132,12 +132,12 @@ public class LaunchConfigurationMainTabSection extends AbstractSection implement
Assert.isNotNull(configuration);
if (processImage != null) {
- String image = DefaultPersistenceDelegate.getAttribute(configuration, ILinuxAppLaunchAttributes.ATTR_PROCESS_IMAGE, ""); //$NON-NLS-1$
+ String image = DefaultPersistenceDelegate.getAttribute(configuration, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, ""); //$NON-NLS-1$
processImage.setEditFieldControlText(image);
}
if (processArguments != null) {
- String arguments = DefaultPersistenceDelegate.getAttribute(configuration, ILinuxAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, ""); //$NON-NLS-1$
+ String arguments = DefaultPersistenceDelegate.getAttribute(configuration, IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, ""); //$NON-NLS-1$
processArguments.setEditFieldControlText(arguments);
}
}
@@ -153,31 +153,31 @@ public class LaunchConfigurationMainTabSection extends AbstractSection implement
String image = processImage.getEditFieldControlText();
if (image != null && image.trim().length() > 0) {
- DefaultPersistenceDelegate.setAttribute(configuration, ILinuxAppLaunchAttributes.ATTR_PROCESS_IMAGE, image);
+ DefaultPersistenceDelegate.setAttribute(configuration, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, image);
} else {
- DefaultPersistenceDelegate.setAttribute(configuration, ILinuxAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
+ DefaultPersistenceDelegate.setAttribute(configuration, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
}
} else {
- DefaultPersistenceDelegate.setAttribute(configuration, ILinuxAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
+ DefaultPersistenceDelegate.setAttribute(configuration, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
}
if (processArguments != null) {
String arguments = processArguments.getEditFieldControlText();
if (arguments != null && arguments.trim().length() > 0) {
- DefaultPersistenceDelegate.setAttribute(configuration, ILinuxAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, arguments);
+ DefaultPersistenceDelegate.setAttribute(configuration, IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, arguments);
} else {
- DefaultPersistenceDelegate.setAttribute(configuration, ILinuxAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, (String)null);
+ DefaultPersistenceDelegate.setAttribute(configuration, IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, (String)null);
}
} else {
- DefaultPersistenceDelegate.setAttribute(configuration, ILinuxAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, (String)null);
+ DefaultPersistenceDelegate.setAttribute(configuration, IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, (String)null);
}
}
@Override
public boolean isValid(ILaunchConfiguration configuration) {
firstSelection = null;
- IModelNode[] contexts = ContextSelectorPersistenceDelegate.getLaunchContexts(configuration);
+ IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(configuration);
if (contexts != null && contexts.length > 0) {
firstSelection = contexts[0];
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationTabGroup.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationTabGroup.java
index a68d7a6c8..36dd89ff0 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationTabGroup.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationTabGroup.java
@@ -14,6 +14,8 @@ import java.util.List;
import org.eclipse.core.runtime.Assert;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
+import org.eclipse.tcf.te.tcf.launch.ui.remote.app.filetransfer.FileTransferTab;
+import org.eclipse.tcf.te.tcf.launch.ui.remote.app.projects.ReferencedProjetcsTab;
/**
* Remote application launch configuration tab group implementation.
@@ -32,7 +34,15 @@ public class LaunchConfigurationTabGroup extends org.eclipse.tcf.te.launch.ui.ta
Assert.isNotNull(tabs);
ILaunchConfigurationTab tab = new LaunchConfigurationMainTab();
+ tabs.add(tab);
+ }
+ @Override
+ public void createAdditionalTabs(ILaunchConfigurationDialog dialog, List<ILaunchConfigurationTab> tabs, String mode) {
+
+ ILaunchConfigurationTab tab = new FileTransferTab();
+ tabs.add(tab);
+ tab = new ReferencedProjetcsTab();
tabs.add(tab);
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/AddEditFileTransferDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/AddEditFileTransferDialog.java
new file mode 100644
index 000000000..9c9930e20
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/AddEditFileTransferDialog.java
@@ -0,0 +1,297 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.launch.ui.remote.app.filetransfer;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tcf.te.launch.core.interfaces.IFileTransferItem;
+import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransferItem;
+import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransferItemValidator;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.tcf.filesystem.dialogs.FSFolderSelectionDialog;
+import org.eclipse.tcf.te.tcf.filesystem.dialogs.FSOpenFileDialog;
+import org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode;
+import org.eclipse.tcf.te.tcf.launch.ui.nls.Messages;
+import org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl;
+import org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+
+/**
+ * AddEditFileTransferDialog
+ * @author tobias.schwarz@windriver.com
+ */
+public class AddEditFileTransferDialog extends CustomTitleAreaDialog {
+
+ final private IFileTransferItem item;
+ final IModelNode launchContext;
+
+ private BaseEditBrowseTextControl host;
+ private BaseEditBrowseTextControl target;
+ private BaseEditBrowseTextControl options;
+
+ private Button toTarget;
+ private Button toHost;
+
+ private boolean modeNew = true;
+
+
+ /**
+ * Constructor.
+ *
+ * @param item The file transfer item to edit or <code>null</code> to create a new one.
+ * @param shell The shell.
+ * @param contextHelpId The context help id.
+ */
+ public AddEditFileTransferDialog(Shell shell, String contextHelpId, IFileTransferItem item, IModelNode launchContexts) {
+ super(shell, contextHelpId);
+
+ Assert.isNotNull(item);
+
+ this.item = item;
+ this.launchContext = launchContexts;
+ this.modeNew = item.isEmpty();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ // Set dialog title and default message
+ setDialogTitle(modeNew ? Messages.AddEditFileTransferDialog_add_dialogTitle : Messages.AddEditFileTransferDialog_edit_dialogTitle);
+ setTitle(modeNew ? Messages.AddEditFileTransferDialog_add_title : Messages.AddEditFileTransferDialog_edit_title);
+ setDefaultMessage(modeNew ? Messages.AddEditFileTransferDialog_add_message : Messages.AddEditFileTransferDialog_edit_message, IMessageProvider.INFORMATION);
+
+ // Get the parent container composite
+ Composite container = (Composite) super.createDialogArea(parent);
+
+ // Create the inner panel
+ Composite panel = new Composite(container, SWT.NULL);
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginHeight = 0; layout.marginWidth = 0;
+ panel.setLayout(layout);
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ @SuppressWarnings("unused")
+ Label spacer = new Label(panel, SWT.NONE);
+
+ toTarget = new Button(panel, SWT.RADIO);
+ toTarget.setText(Messages.AddEditFileTransferDialog_toTarget_checkbox);
+ toTarget.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ validate();
+ }
+ });
+
+ spacer = new Label(panel, SWT.NONE);
+
+ toHost = new Button(panel, SWT.RADIO);
+ toHost.setText(Messages.AddEditFileTransferDialog_toHost_checkbox);
+ toHost.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ validate();
+ }
+ });
+
+ // Create the section sub controls
+ host = new BaseEditBrowseTextControl(null) {
+ @Override
+ protected void onButtonControlSelected() {
+ @SuppressWarnings("synthetic-access")
+ int direction = toTarget.getSelection() ? IFileTransferItem.HOST_TO_TARGET : IFileTransferItem.TARGET_TO_HOST;
+ if (direction == IFileTransferItem.HOST_TO_TARGET) {
+ FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
+ fileDialog.setFilterPath(getEditFieldControlText());
+ fileDialog.setFileName(getEditFieldControlText());
+ String file = fileDialog.open();
+ if (file != null) {
+ setEditFieldControlText(file);
+ }
+ }
+ else {
+ DirectoryDialog directoryDialog = new DirectoryDialog(getShell(), SWT.OPEN);
+ directoryDialog.setFilterPath(getEditFieldControlText());
+ String directory = directoryDialog.open();
+ if (directory != null) {
+ setEditFieldControlText(directory);
+ }
+ }
+ }
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ };
+ host.setEditFieldLabel(Messages.AddEditFileTransferDialog_host_label);
+ host.setIsGroup(false);
+ host.setHideBrowseButton(false);
+ host.setAdjustBackgroundColor(true);
+ host.setParentControlIsInnerPanel(true);
+ host.setupPanel(panel);
+ host.doCreateControlDecoration(host.getEditFieldControl());
+
+ // Create the section sub controls
+ target = new BaseEditBrowseTextControl(null) {
+ @Override
+ protected void onButtonControlSelected() {
+ @SuppressWarnings("synthetic-access")
+ int direction = toTarget.getSelection() ? IFileTransferItem.HOST_TO_TARGET : IFileTransferItem.TARGET_TO_HOST;
+ ElementTreeSelectionDialog dialog = direction == IFileTransferItem.HOST_TO_TARGET ? new FSFolderSelectionDialog(getShell()) : new FSOpenFileDialog(getShell());
+ dialog.setInput(getEditFieldControlText());
+ dialog.setInput(launchContext);
+ if (dialog.open() == Window.OK) {
+ Object candidate = dialog.getFirstResult();
+ if (candidate instanceof FSTreeNode) {
+ String absPath = ((FSTreeNode) candidate).getLocation();
+ if (absPath != null) {
+ setEditFieldControlText(absPath);
+ }
+ }
+ }
+ }
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ };
+ target.setEditFieldLabel(Messages.AddEditFileTransferDialog_target_label);
+ target.setIsGroup(false);
+ target.setHideBrowseButton(false);
+ target.setAdjustBackgroundColor(true);
+ target.setParentControlIsInnerPanel(true);
+ target.setupPanel(panel);
+ target.doCreateControlDecoration(target.getEditFieldControl());
+
+ spacer = new Label(panel, SWT.NONE);
+ spacer = new Label(panel, SWT.NONE);
+
+ options = new BaseEditBrowseTextControl(null) {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ };
+ options.setEditFieldLabel(Messages.AddEditFileTransferDialog_options_label);
+ options.setIsGroup(false);
+ options.setHideBrowseButton(true);
+ options.setHasHistory(false);
+ options.setAdjustBackgroundColor(true);
+ options.setParentControlIsInnerPanel(true);
+ options.setupPanel(panel);
+ options.doCreateControlDecoration(target.getEditFieldControl());
+
+ applyDialogFont(container);
+
+ return container;
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Control control = super.createContents(parent);
+
+ restoreWidgetValues();
+ validate();
+
+ return control;
+ }
+
+ protected void validate() {
+ IFileTransferItem wc = new FileTransferItem();
+ saveWidgetValues(wc);
+ Map<String,String> invalid = FileTransferItemValidator.validate(wc);
+ boolean valid = true;
+
+ if (invalid != null && invalid.containsKey(IFileTransferItem.PROPERTY_HOST)) {
+ host.updateControlDecoration(invalid.get(IFileTransferItem.PROPERTY_HOST), IMessageProvider.ERROR);
+ if (valid) {
+ setErrorMessage(invalid.get(IFileTransferItem.PROPERTY_HOST));
+ }
+ valid = false;
+ }
+ else {
+ host.updateControlDecoration(null, IMessageProvider.NONE);
+ }
+
+ if (invalid != null && invalid.containsKey(IFileTransferItem.PROPERTY_TARGET)) {
+ target.updateControlDecoration(invalid.get(IFileTransferItem.PROPERTY_TARGET), IMessageProvider.ERROR);
+ if (valid) {
+ setErrorMessage(invalid.get(IFileTransferItem.PROPERTY_TARGET));
+ }
+ valid = false;
+ }
+ else {
+ target.updateControlDecoration(null, IMessageProvider.NONE);
+ }
+
+ if (valid) {
+ setErrorMessage(null);
+ }
+
+ getButton(IDialogConstants.OK_ID).setEnabled(valid);
+ }
+
+ private void saveWidgetValues(IFileTransferItem wc) {
+ wc.setProperty(IFileTransferItem.PROPERTY_HOST, new Path(host.getEditFieldControlText()).toPortableString());
+ wc.setProperty(IFileTransferItem.PROPERTY_TARGET, new Path(target.getEditFieldControlText()).toPortableString());
+ wc.setProperty(IFileTransferItem.PROPERTY_OPTIONS, options.getEditFieldControlText());
+
+ int direction = toTarget.getSelection() ? IFileTransferItem.HOST_TO_TARGET : IFileTransferItem.TARGET_TO_HOST;
+ wc.setProperty(IFileTransferItem.PROPERTY_DIRECTION, direction);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#restoreWidgetValues()
+ */
+ @Override
+ protected void restoreWidgetValues() {
+ String hostPath = item.getStringProperty(IFileTransferItem.PROPERTY_HOST);
+ host.setEditFieldControlText(hostPath != null ? new Path(hostPath).toOSString() : ""); //$NON-NLS-1$
+
+ String targetPath = item.getStringProperty(IFileTransferItem.PROPERTY_TARGET);
+ target.setEditFieldControlText(targetPath != null ? new Path(targetPath).toPortableString() : ""); //$NON-NLS-1$
+ target.getButtonControl().setEnabled(launchContext != null);
+
+ String optionsString = item.getStringProperty(IFileTransferItem.PROPERTY_OPTIONS);
+ options.setEditFieldControlText(optionsString != null ? optionsString : ""); //$NON-NLS-1$
+
+ int direction = item.getIntProperty(IFileTransferItem.PROPERTY_DIRECTION);
+ toTarget.setSelection(direction != IFileTransferItem.TARGET_TO_HOST);
+ toHost.setSelection(direction == IFileTransferItem.TARGET_TO_HOST);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#saveWidgetValues()
+ */
+ @Override
+ protected void saveWidgetValues() {
+ saveWidgetValues(item);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/FileTransferSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/FileTransferSection.java
new file mode 100644
index 000000000..323c8bcd4
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/FileTransferSection.java
@@ -0,0 +1,620 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.launch.ui.remote.app.filetransfer;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnPixelData;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ICheckStateProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.tcf.te.launch.core.interfaces.IFileTransferItem;
+import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransferItem;
+import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransferItemValidator;
+import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransfersPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.launchcontext.LaunchContextsPersistenceDelegate;
+import org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.tcf.launch.ui.nls.Messages;
+import org.eclipse.tcf.te.ui.forms.parts.AbstractTableSection;
+import org.eclipse.tcf.te.ui.swt.listener.AbstractDecorationCellPaintListener;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+
+/**
+ * FileTransferSection
+ * @author tobias.schwarz@windriver.com
+ */
+public class FileTransferSection extends AbstractTableSection implements ILaunchConfigurationTabFormPart {
+
+ private ControlDecoration controlDecoration;
+ private IModelNode launchContext = null;
+
+ protected static final String PROPERTY_VALIDATION_RESULT = "validation_result.transient"; //$NON-NLS-1$
+
+ /**
+ * Constructor.
+ * @param form
+ * @param parent
+ */
+ public FileTransferSection(IManagedForm form, Composite parent) {
+ super(form, parent, SWT.NONE, new String[]{
+ Messages.FileTransferSection_add_button,
+ Messages.FileTransferSection_edit_button,
+ Messages.FileTransferSection_delete_button,
+ null,
+ Messages.FileTransferSection_up_button,
+ Messages.FileTransferSection_down_button});
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ IFileTransferItem[] items = FileTransfersPersistenceDelegate.getFileTransfers(configuration);
+ getTablePart().getViewer().setInput(items);
+ if (items != null && items.length > 0) {
+ ((TableViewer)getTablePart().getViewer()).setSelection(new StructuredSelection(items[0]), true);
+ }
+ launchContext = LaunchContextsPersistenceDelegate.getFirstLaunchContext(configuration);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ @Override
+ public void performApply(ILaunchConfigurationWorkingCopy wc) {
+ FileTransfersPersistenceDelegate.setFileTransfers(wc, (IFileTransferItem[])getTablePart().getViewer().getInput());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart#isValid(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public boolean isValid(ILaunchConfiguration configuration) {
+ return validateInputList();
+ }
+
+ private boolean validateInputList() {
+ List<IFileTransferItem> list = getInputList();
+ boolean valid = true;
+ for (IFileTransferItem item : list) {
+ Map<String,String> invalid = item.getBooleanProperty(IFileTransferItem.PROPERTY_ENABLED) ? FileTransferItemValidator.validate(item) : null;
+ item.setProperty(PROPERTY_VALIDATION_RESULT, invalid);
+ if (valid && invalid != null) {
+ valid = false;
+ setMessage(invalid.get(invalid.keySet().toArray()[0]), IMessageProvider.ERROR);
+ }
+ }
+ return valid;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.forms.parts.AbstractSection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
+ */
+ @Override
+ protected void createClient(Section section, FormToolkit toolkit) {
+ Assert.isNotNull(section);
+ Assert.isNotNull(toolkit);
+
+ section.setText(Messages.FileTransferSection_title);
+ section.setDescription(Messages.FileTransferSection_description);
+
+ section.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL, SWT.CENTER, true, true));
+
+ Composite client = createClientContainer(section, 2, toolkit);
+ client.setBackground(section.getBackground());
+
+ section.setClient(client);
+
+ createPartControl((Composite)section.getClient(), SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION, 2, toolkit);
+ }
+
+ @Override
+ protected TableViewer createTableViewer(Composite parent, int style) {
+ return new CheckboxTableViewer(new Table(parent, style | SWT.CHECK));
+ }
+
+ @Override
+ protected void configureTableViewer(TableViewer viewer) {
+ super.configureTableViewer(viewer);
+
+ ColumnViewerToolTipSupport.enableFor(viewer);
+
+ final Table table = viewer.getTable();
+
+ ((CheckboxTableViewer)viewer).setCheckStateProvider(new ICheckStateProvider() {
+ @Override
+ public boolean isGrayed(Object element) {
+ return false;
+ }
+ @Override
+ public boolean isChecked(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ return item.getBooleanProperty(IFileTransferItem.PROPERTY_ENABLED);
+ }
+ return false;
+ }
+ });
+ ((CheckboxTableViewer)viewer).addCheckStateListener(new ICheckStateListener() {
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if (event.getElement() instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)event.getElement();
+ item.setProperty(IFileTransferItem.PROPERTY_ENABLED, event.getChecked());
+ getManagedForm().dirtyStateChanged();
+ }
+ }
+ });
+
+ TableViewerColumn tvEnableCol = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn colEnable = tvEnableCol.getColumn();
+ colEnable.setResizable(false);
+ tvEnableCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return null;
+ }
+ });
+
+ TableViewerColumn tvHostCol = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn colHost = tvHostCol.getColumn();
+ colHost.setText(Messages.FileTransferSection_host_column);
+ colHost.setResizable(true);
+ tvHostCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getToolTipText(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ Map<String,String> invalid = (Map<String,String>)item.getProperty(PROPERTY_VALIDATION_RESULT);
+ if (invalid != null && invalid.containsKey(IFileTransferItem.PROPERTY_HOST)) {
+ return invalid.get(IFileTransferItem.PROPERTY_HOST);
+ }
+ String host = item.getStringProperty(IFileTransferItem.PROPERTY_HOST);
+ return host != null ? new Path(host).toOSString() : host;
+ }
+ return super.getText(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ String host = item.getStringProperty(IFileTransferItem.PROPERTY_HOST);
+ return host != null ? new Path(host).toOSString() : host;
+ }
+ return super.getText(element);
+ }
+ });
+
+ TableViewerColumn tvDirCol = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn colDir = tvDirCol.getColumn();
+ colDir.setResizable(false);
+ colDir.setAlignment(SWT.CENTER);
+ tvDirCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getToolTipText(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ switch (item.getIntProperty(IFileTransferItem.PROPERTY_DIRECTION)) {
+ case IFileTransferItem.HOST_TO_TARGET:
+ return Messages.FileTransferSection_toTarget_tooltip;
+ case IFileTransferItem.TARGET_TO_HOST:
+ return Messages.FileTransferSection_toHost_tooltip;
+ }
+ }
+ return super.getToolTipText(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ switch (item.getIntProperty(IFileTransferItem.PROPERTY_DIRECTION)) {
+ case IFileTransferItem.HOST_TO_TARGET:
+ return Messages.FileTransferSection_toTarget_text;
+ case IFileTransferItem.TARGET_TO_HOST:
+ return Messages.FileTransferSection_toHost_text;
+ }
+ }
+ return super.getText(element);
+ }
+ });
+ tvDirCol.setEditingSupport(new EditingSupport(tvDirCol.getViewer()) {
+ @Override
+ protected void setValue(Object element, Object value) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ item.setProperty(IFileTransferItem.PROPERTY_DIRECTION,
+ Boolean.parseBoolean(value.toString()) ? IFileTransferItem.HOST_TO_TARGET : IFileTransferItem.TARGET_TO_HOST);
+ getManagedForm().dirtyStateChanged();
+ getViewer().refresh();
+ }
+ }
+
+ @Override
+ protected Object getValue(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ return new Boolean(item.getIntProperty(IFileTransferItem.PROPERTY_DIRECTION) != IFileTransferItem.TARGET_TO_HOST);
+ }
+ return null;
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ return new CheckboxCellEditor();
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+ });
+
+ TableViewerColumn tvTargetCol = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn colTarget = tvTargetCol.getColumn();
+ colTarget.setText(Messages.FileTransferSection_target_column);
+ colTarget.setResizable(true);
+ tvTargetCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getToolTipText(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ Map<String,String> invalid = (Map<String,String>)item.getProperty(PROPERTY_VALIDATION_RESULT);
+ if (invalid != null && invalid.containsKey(IFileTransferItem.PROPERTY_TARGET)) {
+ return invalid.get(IFileTransferItem.PROPERTY_TARGET);
+ }
+ String target = item.getStringProperty(IFileTransferItem.PROPERTY_TARGET);
+ return target != null ? new Path(target).toPortableString() : target;
+ }
+ return super.getText(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ String target = item.getStringProperty(IFileTransferItem.PROPERTY_TARGET);
+ return target != null ? new Path(target).toPortableString() : target;
+ }
+ return super.getText(element);
+ }
+ });
+
+ TableViewerColumn tvOptionCol = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn colOption = tvOptionCol.getColumn();
+ colOption.setText(Messages.FileTransferSection_options_column);
+ colOption.setResizable(true);
+ tvOptionCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getToolTipText(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ return item.getStringProperty(IFileTransferItem.PROPERTY_OPTIONS);
+ }
+ return super.getText(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)element;
+ return item.getStringProperty(IFileTransferItem.PROPERTY_OPTIONS);
+ }
+ return super.getText(element);
+ }
+ });
+
+ TableLayout tableLayout = new TableLayout();
+ tableLayout.addColumnData(new ColumnPixelData(30, true));
+ tableLayout.addColumnData(new ColumnPixelData(200, true));
+ tableLayout.addColumnData(new ColumnPixelData(30, true));
+ tableLayout.addColumnData(new ColumnPixelData(200, true));
+ tableLayout.addColumnData(new ColumnPixelData(100, true));
+ table.setLayout(tableLayout);
+ GridData data = new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING);
+ table.setLayoutData(data);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ table.addListener(SWT.Resize, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ int width = table.getSize().x - 4 - colEnable.getWidth() - colHost.getWidth() - colDir.getWidth() - colTarget.getWidth();
+ colOption.setWidth(Math.max(width, 100));
+ }
+ });
+ colHost.addListener(SWT.Resize, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ int colWidth = colHost.getWidth();
+ if (colWidth < 100) {
+ event.doit = false;
+ colHost.setWidth(100);
+ colWidth = 100;
+ }
+ int width = table.getSize().x - 4 - colWidth - colEnable.getWidth() - colDir.getWidth() - colTarget.getWidth();
+ colOption.setWidth(Math.max(width, 100));
+ }
+ });
+ colTarget.addListener(SWT.Resize, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ int colWidth = colTarget.getWidth();
+ if (colWidth < 100) {
+ event.doit = false;
+ colTarget.setWidth(100);
+ colWidth = 100;
+ }
+ int width = table.getSize().x - 4 - colWidth - colEnable.getWidth() - colHost.getWidth() - colDir.getWidth();
+ colOption.setWidth(Math.max(width, 100));
+ }
+ });
+
+ @SuppressWarnings("unused")
+ AbstractDecorationCellPaintListener cpl = new AbstractDecorationCellPaintListener(table, 1, 3) {
+ @Override
+ protected int getDecorationState(Object data, int columnIndex) {
+ if (data instanceof IFileTransferItem) {
+ IFileTransferItem item = (IFileTransferItem)data;
+ if (item.getBooleanProperty(IFileTransferItem.PROPERTY_ENABLED)) {
+ Map<String,String> invalid = (Map<String,String>)item.getProperty(PROPERTY_VALIDATION_RESULT);
+ if (invalid != null) {
+ switch (columnIndex) {
+ case 1:
+ if (invalid.containsKey(IFileTransferItem.PROPERTY_HOST)) {
+ return STATE_ERROR;
+ }
+ break;
+ case 3:
+ if (invalid.containsKey(IFileTransferItem.PROPERTY_TARGET)) {
+ return STATE_ERROR;
+ }
+ break;
+ }
+ }
+ }
+ }
+ return STATE_NONE;
+ }
+ };
+
+ viewer.setContentProvider(new IStructuredContentProvider() {
+ @Override
+ public void dispose() {
+ }
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ viewer.refresh();
+ }
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return inputElement instanceof Object[] ? (Object[])inputElement : new Object[0];
+ }
+ });
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ initializeButtonsEnablement();
+ }
+ });
+
+ doCreateControlDecoration(table);
+ configureControlDecoration(getControlDecoration());
+ }
+
+ /**
+ * Creates a new instance of a {@link ControlDecoration} object associated with
+ * the given control. The method is called after the control has been created.
+ *
+ * @param control The control. Must not be <code>null</code>.
+ * @return The control decoration object instance.
+ */
+ public ControlDecoration doCreateControlDecoration(Control control) {
+ Assert.isNotNull(control);
+ controlDecoration = new ControlDecoration(control, SWT.TOP | SWT.LEFT);
+ return controlDecoration;
+ }
+
+ /**
+ * Returns the control decoration.
+ *
+ * @return The control decoration instance or <code>null</code> if not yet created.
+ */
+ public final ControlDecoration getControlDecoration() {
+ return controlDecoration;
+ }
+
+ /**
+ * Configure the given control decoration.
+ *
+ * @param decoration The control decoration. Must not be <code>null</code>.
+ */
+ protected void configureControlDecoration(ControlDecoration decoration) {
+ Assert.isNotNull(decoration);
+ decoration.setShowOnlyOnFocus(false);
+ }
+
+ /**
+ * Updates the control decoration to represent the given message and message type.
+ * If the message is <code>null</code> or the message type is IMessageProvider.NONE,
+ * no decoration will be shown.
+ *
+ * @param message The message.
+ * @param messageType The message type.
+ */
+ public void updateControlDecoration(String message, int messageType) {
+ if (getControlDecoration() != null) {
+ // The description is the same as the message
+ getControlDecoration().setDescriptionText(message);
+
+ // The icon depends on the message type
+ FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
+
+ // Determine the id of the decoration to show
+ String decorationId = FieldDecorationRegistry.DEC_INFORMATION;
+ if (messageType == IMessageProvider.ERROR) {
+ decorationId = FieldDecorationRegistry.DEC_ERROR;
+ } else if (messageType == IMessageProvider.WARNING) {
+ decorationId = FieldDecorationRegistry.DEC_WARNING;
+ }
+
+ // Get the field decoration
+ FieldDecoration fieldDeco = registry.getFieldDecoration(decorationId);
+ if (fieldDeco != null) {
+ getControlDecoration().setImage(fieldDeco.getImage());
+ }
+
+ if (message == null || messageType == IMessageProvider.NONE) {
+ getControlDecoration().hide();
+ }
+ else {
+ getControlDecoration().show();
+ }
+ }
+ }
+
+ private List<IFileTransferItem> getInputList() {
+ return new ArrayList<IFileTransferItem>(Arrays.asList((IFileTransferItem[])getTablePart().getViewer().getInput()));
+ }
+
+ private void setInputList(List<IFileTransferItem> list) {
+ getTablePart().getViewer().setInput(list.toArray(new IFileTransferItem[list.size()]));
+ }
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ onButtonEditClick();
+ }
+
+ @Override
+ protected void onButtonSelected(Button button) {
+ int selIndex = ((TableViewer)getTablePart().getViewer()).getTable().getSelectionIndex();
+ List<IFileTransferItem> list = getInputList();
+
+ switch (((Integer)button.getData()).intValue()) {
+ case 0: // Add
+ onButtonAddClick();
+ break;
+ case 1: // Edit
+ onButtonEditClick();
+ break;
+ case 2: // Delete
+ list.remove(selIndex);
+ setInputList(list);
+ if (!list.isEmpty()) {
+ ((TableViewer)getTablePart().getViewer()).setSelection(
+ new StructuredSelection(list.get(selIndex < list.size() ? selIndex : list.size()-1)), true);
+ }
+ break;
+ case 4: // Up
+ list.add(selIndex-1, list.remove(selIndex));
+ setInputList(list);
+ ((TableViewer)getTablePart().getViewer()).setSelection(new StructuredSelection(list.get(selIndex-1)), true);
+ break;
+ case 5: // Down
+ list.add(selIndex+1, list.remove(selIndex));
+ setInputList(list);
+ ((TableViewer)getTablePart().getViewer()).setSelection(new StructuredSelection(list.get(selIndex+1)), true);
+ break;
+ }
+ validateInputList();
+ getManagedForm().dirtyStateChanged();
+ }
+
+ private void onButtonAddClick() {
+ int selIndex = ((TableViewer)getTablePart().getViewer()).getTable().getSelectionIndex();
+ List<IFileTransferItem> list = getInputList();
+ IFileTransferItem item = new FileTransferItem();
+ AddEditFileTransferDialog dialog = new AddEditFileTransferDialog(getSection().getShell(), null, item, launchContext);
+ if (dialog.open() == Window.OK) {
+ item.setProperty(IFileTransferItem.PROPERTY_ENABLED, true);
+ list.add(selIndex != -1 ? selIndex : 0, item);
+ setInputList(list);
+ ((TableViewer)getTablePart().getViewer()).setSelection(new StructuredSelection(item), true);
+ }
+ }
+
+ private void onButtonEditClick() {
+ int selIndex = ((TableViewer)getTablePart().getViewer()).getTable().getSelectionIndex();
+
+ if (selIndex >= 0) {
+ List<IFileTransferItem> list = getInputList();
+ IFileTransferItem item = list.get(selIndex);
+
+ AddEditFileTransferDialog dialog = new AddEditFileTransferDialog(getSection().getShell(), null, item, launchContext);
+ if (dialog.open() == Window.OK) {
+ list.set(selIndex, item);
+ setInputList(list);
+ ((TableViewer)getTablePart().getViewer()).setSelection(new StructuredSelection(item), true);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.forms.parts.AbstractTableSection#initializeButtonsEnablement()
+ */
+ @Override
+ protected void initializeButtonsEnablement() {
+ ISelection selection = ((TableViewer)getTablePart().getViewer()).getSelection();
+ boolean singleSelection = selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1;
+ int selIndex = ((TableViewer)getTablePart().getViewer()).getTable().getSelectionIndex();
+ int count = ((TableViewer)getTablePart().getViewer()).getTable().getItemCount();
+
+ getTablePart().getButton(0).setEnabled(getTablePart().isEnabled());
+ getTablePart().getButton(1).setEnabled(getTablePart().isEnabled() && singleSelection);
+ getTablePart().getButton(2).setEnabled(getTablePart().isEnabled() && singleSelection);
+ getTablePart().getButton(4).setEnabled(getTablePart().isEnabled() && singleSelection && selIndex > 0);
+ getTablePart().getButton(5).setEnabled(getTablePart().isEnabled() && singleSelection && selIndex < count-1);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/FileTransferTab.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/FileTransferTab.java
new file mode 100644
index 000000000..44dcd4c76
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/filetransfer/FileTransferTab.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.launch.ui.remote.app.filetransfer;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tcf.te.launch.ui.tabs.AbstractFormsLaunchConfigurationTab;
+import org.eclipse.tcf.te.tcf.launch.ui.nls.Messages;
+import org.eclipse.tcf.te.ui.forms.CustomFormToolkit;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
+
+/**
+ * File transfer launch configuration tab implementation.
+ */
+public class FileTransferTab extends AbstractFormsLaunchConfigurationTab {
+ // References to the tab sub sections
+ private FileTransferSection section;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.tabs.AbstractFormsLaunchConfigurationTab#dispose()
+ */
+ @Override
+ public void dispose() {
+ if (section != null) { section.dispose(); section = null; }
+ super.dispose();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.tabs.AbstractFormsLaunchConfigurationTab#doCreateFormContent(org.eclipse.swt.widgets.Composite, org.eclipse.tcf.te.ui.forms.CustomFormToolkit)
+ */
+ @Override
+ protected void doCreateFormContent(Composite parent, CustomFormToolkit toolkit) {
+ Assert.isNotNull(parent);
+ Assert.isNotNull(toolkit);
+
+ // Setup the main panel (using the table wrap layout)
+ Composite panel = toolkit.getFormToolkit().createComposite(parent);
+ TableWrapLayout layout = new TableWrapLayout();
+ layout.makeColumnsEqualWidth = true;
+ layout.numColumns = 1;
+ panel.setLayout(layout);
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ panel.setBackground(parent.getBackground());
+
+ section = new FileTransferSection(getManagedForm(), panel);
+ section.getSection().setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP));
+ getManagedForm().addPart(section);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
+ */
+ @Override
+ public String getName() {
+ return Messages.FileTransferTab_name;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/projects/ReferencedProjectsSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/projects/ReferencedProjectsSection.java
new file mode 100644
index 000000000..ee4d91323
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/projects/ReferencedProjectsSection.java
@@ -0,0 +1,491 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.launch.ui.remote.app.projects;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnPixelData;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ICheckStateProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem;
+import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectItem;
+import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectItemValidator;
+import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectsPersistenceDelegate;
+import org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart;
+import org.eclipse.tcf.te.tcf.launch.ui.nls.Messages;
+import org.eclipse.tcf.te.ui.forms.parts.AbstractTableSection;
+import org.eclipse.tcf.te.ui.swt.listener.AbstractDecorationCellPaintListener;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+
+/**
+ * ReferencedProjectsSection
+ * @author tobias.schwarz@windriver.com
+ */
+public class ReferencedProjectsSection extends AbstractTableSection implements ILaunchConfigurationTabFormPart {
+
+ private ControlDecoration controlDecoration;
+
+ protected static final String PROPERTY_VALIDATION_RESULT = "validation_result.transient"; //$NON-NLS-1$
+
+ /**
+ * Constructor.
+ * @param form
+ * @param parent
+ */
+ public ReferencedProjectsSection(IManagedForm form, Composite parent) {
+ super(form, parent, SWT.NONE, new String[]{
+ Messages.ReferencedProjectsSection_add_button,
+ Messages.ReferencedProjectsSection_delete_button,
+ null,
+ Messages.ReferencedProjectsSection_up_button,
+ Messages.ReferencedProjectsSection_down_button});
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ IReferencedProjectItem[] items = ReferencedProjectsPersistenceDelegate.getReferencedProjects(configuration);
+ getTablePart().getViewer().setInput(items);
+ if (items != null && items.length > 0) {
+ ((TableViewer)getTablePart().getViewer()).setSelection(new StructuredSelection(items[0]), true);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ @Override
+ public void performApply(ILaunchConfigurationWorkingCopy wc) {
+ ReferencedProjectsPersistenceDelegate.setReferencedProjects(wc, (IReferencedProjectItem[])getTablePart().getViewer().getInput());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.interfaces.ILaunchConfigurationTabFormPart#isValid(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public boolean isValid(ILaunchConfiguration configuration) {
+ return validateInputList();
+ }
+
+ private boolean validateInputList() {
+ List<IReferencedProjectItem> list = getInputList();
+ boolean valid = true;
+ for (IReferencedProjectItem item : list) {
+ Map<String,String> invalid = item.getBooleanProperty(IReferencedProjectItem.PROPERTY_ENABLED) ? ReferencedProjectItemValidator.validate(item) : null;
+ item.setProperty(PROPERTY_VALIDATION_RESULT, invalid);
+ if (valid && invalid != null) {
+ valid = false;
+ setMessage(invalid.get(invalid.keySet().toArray()[0]), IMessageProvider.ERROR);
+ }
+ }
+ return valid;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.forms.parts.AbstractSection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
+ */
+ @Override
+ protected void createClient(Section section, FormToolkit toolkit) {
+ Assert.isNotNull(section);
+ Assert.isNotNull(toolkit);
+
+ section.setText(Messages.ReferencedProjectsSection_title);
+ section.setDescription(Messages.ReferencedProjectsSection_description);
+
+ section.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL, SWT.CENTER, true, true));
+
+ Composite client = createClientContainer(section, 2, toolkit);
+ client.setBackground(section.getBackground());
+
+ section.setClient(client);
+
+ createPartControl((Composite)section.getClient(), SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION, 2, toolkit);
+ }
+
+ @Override
+ protected TableViewer createTableViewer(Composite parent, int style) {
+ return new CheckboxTableViewer(new Table(parent, style | SWT.CHECK));
+ }
+
+ @Override
+ protected void configureTableViewer(TableViewer viewer) {
+ super.configureTableViewer(viewer);
+
+ ColumnViewerToolTipSupport.enableFor(viewer);
+
+ final Table table = viewer.getTable();
+
+ ((CheckboxTableViewer)viewer).setCheckStateProvider(new ICheckStateProvider() {
+ @Override
+ public boolean isGrayed(Object element) {
+ return false;
+ }
+ @Override
+ public boolean isChecked(Object element) {
+ if (element instanceof IReferencedProjectItem) {
+ IReferencedProjectItem item = (IReferencedProjectItem)element;
+ return item.getBooleanProperty(IReferencedProjectItem.PROPERTY_ENABLED);
+ }
+ return false;
+ }
+ });
+ ((CheckboxTableViewer)viewer).addCheckStateListener(new ICheckStateListener() {
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if (event.getElement() instanceof IReferencedProjectItem) {
+ IReferencedProjectItem item = (IReferencedProjectItem)event.getElement();
+ item.setProperty(IReferencedProjectItem.PROPERTY_ENABLED, event.getChecked());
+ getManagedForm().dirtyStateChanged();
+ }
+ }
+ });
+
+ TableViewerColumn tvEnableCol = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn colEnable = tvEnableCol.getColumn();
+ colEnable.setResizable(false);
+ tvEnableCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return null;
+ }
+ });
+
+ TableViewerColumn tvProjectCol = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn colProject = tvProjectCol.getColumn();
+ colProject.setText(Messages.ReferencedProjectsSection_project_column);
+ colProject.setResizable(true);
+ tvProjectCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getToolTipText(Object element) {
+ if (element instanceof IReferencedProjectItem) {
+ IReferencedProjectItem item = (IReferencedProjectItem)element;
+ Map<String,String> invalid = (Map<String,String>)item.getProperty(PROPERTY_VALIDATION_RESULT);
+ if (invalid != null && invalid.containsKey(IReferencedProjectItem.PROPERTY_PROJECT_NAME)) {
+ return invalid.get(IReferencedProjectItem.PROPERTY_PROJECT_NAME);
+ }
+ return item.getStringProperty(IReferencedProjectItem.PROPERTY_PROJECT_NAME);
+ }
+ return super.getText(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IReferencedProjectItem) {
+ IReferencedProjectItem item = (IReferencedProjectItem)element;
+ return item.getStringProperty(IReferencedProjectItem.PROPERTY_PROJECT_NAME);
+ }
+ return super.getText(element);
+ }
+ });
+
+ TableLayout tableLayout = new TableLayout();
+ tableLayout.addColumnData(new ColumnPixelData(30, true));
+ tableLayout.addColumnData(new ColumnPixelData(200, true));
+ table.setLayout(tableLayout);
+ GridData data = new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING);
+ table.setLayoutData(data);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ table.addListener(SWT.Resize, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ int width = table.getSize().x - 4 - colEnable.getWidth();
+ colProject.setWidth(Math.max(width, 100));
+ }
+ });
+
+ @SuppressWarnings("unused")
+ AbstractDecorationCellPaintListener cpl = new AbstractDecorationCellPaintListener(table, 1) {
+ @Override
+ protected int getDecorationState(Object data, int columnIndex) {
+ if (data instanceof IReferencedProjectItem) {
+ IReferencedProjectItem item = (IReferencedProjectItem)data;
+ if (item.getBooleanProperty(IReferencedProjectItem.PROPERTY_ENABLED)) {
+ Map<String,String> invalid = (Map<String,String>)item.getProperty(PROPERTY_VALIDATION_RESULT);
+ if (invalid != null) {
+ switch (columnIndex) {
+ case 1:
+ if (invalid.containsKey(IReferencedProjectItem.PROPERTY_PROJECT_NAME)) {
+ return STATE_ERROR;
+ }
+ break;
+ }
+ }
+ }
+ }
+ return STATE_NONE;
+ }
+ };
+
+ viewer.setContentProvider(new IStructuredContentProvider() {
+ @Override
+ public void dispose() {
+ }
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ viewer.refresh();
+ }
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return inputElement instanceof Object[] ? (Object[])inputElement : new Object[0];
+ }
+ });
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ initializeButtonsEnablement();
+ }
+ });
+
+ doCreateControlDecoration(table);
+ configureControlDecoration(getControlDecoration());
+ }
+
+ /**
+ * Creates a new instance of a {@link ControlDecoration} object associated with
+ * the given control. The method is called after the control has been created.
+ *
+ * @param control The control. Must not be <code>null</code>.
+ * @return The control decoration object instance.
+ */
+ public ControlDecoration doCreateControlDecoration(Control control) {
+ Assert.isNotNull(control);
+ controlDecoration = new ControlDecoration(control, SWT.TOP | SWT.LEFT);
+ return controlDecoration;
+ }
+
+ /**
+ * Returns the control decoration.
+ *
+ * @return The control decoration instance or <code>null</code> if not yet created.
+ */
+ public final ControlDecoration getControlDecoration() {
+ return controlDecoration;
+ }
+
+ /**
+ * Configure the given control decoration.
+ *
+ * @param decoration The control decoration. Must not be <code>null</code>.
+ */
+ protected void configureControlDecoration(ControlDecoration decoration) {
+ Assert.isNotNull(decoration);
+ decoration.setShowOnlyOnFocus(false);
+ }
+
+ /**
+ * Updates the control decoration to represent the given message and message type.
+ * If the message is <code>null</code> or the message type is IMessageProvider.NONE,
+ * no decoration will be shown.
+ *
+ * @param message The message.
+ * @param messageType The message type.
+ */
+ public void updateControlDecoration(String message, int messageType) {
+ if (getControlDecoration() != null) {
+ // The description is the same as the message
+ getControlDecoration().setDescriptionText(message);
+
+ // The icon depends on the message type
+ FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
+
+ // Determine the id of the decoration to show
+ String decorationId = FieldDecorationRegistry.DEC_INFORMATION;
+ if (messageType == IMessageProvider.ERROR) {
+ decorationId = FieldDecorationRegistry.DEC_ERROR;
+ } else if (messageType == IMessageProvider.WARNING) {
+ decorationId = FieldDecorationRegistry.DEC_WARNING;
+ }
+
+ // Get the field decoration
+ FieldDecoration fieldDeco = registry.getFieldDecoration(decorationId);
+ if (fieldDeco != null) {
+ getControlDecoration().setImage(fieldDeco.getImage());
+ }
+
+ if (message == null || messageType == IMessageProvider.NONE) {
+ getControlDecoration().hide();
+ }
+ else {
+ getControlDecoration().show();
+ }
+ }
+ }
+
+ private List<IReferencedProjectItem> getInputList() {
+ return new ArrayList<IReferencedProjectItem>(Arrays.asList((IReferencedProjectItem[])getTablePart().getViewer().getInput()));
+ }
+
+ private void setInputList(List<IReferencedProjectItem> list) {
+ getTablePart().getViewer().setInput(list.toArray(new IReferencedProjectItem[list.size()]));
+ }
+
+ @Override
+ protected void onButtonSelected(Button button) {
+ int selIndex = ((TableViewer)getTablePart().getViewer()).getTable().getSelectionIndex();
+ List<IReferencedProjectItem> list = getInputList();
+
+ switch (((Integer)button.getData()).intValue()) {
+ case 0: // Add
+ onButtonAddClick();
+ break;
+ case 1: // Edit
+ list.remove(selIndex);
+ setInputList(list);
+ if (!list.isEmpty()) {
+ ((TableViewer)getTablePart().getViewer()).setSelection(
+ new StructuredSelection(list.get(selIndex < list.size() ? selIndex : list.size()-1)), true);
+ }
+ break;
+ case 3: // Up
+ list.add(selIndex-1, list.remove(selIndex));
+ setInputList(list);
+ ((TableViewer)getTablePart().getViewer()).setSelection(new StructuredSelection(list.get(selIndex-1)), true);
+ break;
+ case 4: // Down
+ list.add(selIndex+1, list.remove(selIndex));
+ setInputList(list);
+ ((TableViewer)getTablePart().getViewer()).setSelection(new StructuredSelection(list.get(selIndex+1)), true);
+ break;
+ }
+ validateInputList();
+ getManagedForm().dirtyStateChanged();
+ }
+
+ private boolean contains(List<IReferencedProjectItem> list, IProject project) {
+ for (IReferencedProjectItem item : list) {
+ if (item.isProperty(IReferencedProjectItem.PROPERTY_PROJECT_NAME, project.getName())) {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ private void onButtonAddClick() {
+ int selIndex = ((TableViewer)getTablePart().getViewer()).getTable().getSelectionIndex();
+ List<IReferencedProjectItem> list = getInputList();
+
+ IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ List<String> unreferencedProjects = new ArrayList<String>();
+ for (IProject project : allProjects) {
+ if (project.isOpen() && !contains(list, project)) {
+ unreferencedProjects.add(project.getName());
+ }
+ }
+
+ ILabelProvider labelProvider = new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return (String)element;
+ }
+ };
+
+ IStructuredContentProvider contentProvider = new IStructuredContentProvider() {
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ @Override
+ public void dispose() {
+ }
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return (Object[])inputElement;
+ }
+ };
+
+ ListSelectionDialog dialog = new ListSelectionDialog(getSection().getShell(),
+ unreferencedProjects.toArray(), contentProvider, labelProvider, Messages.ReferencedProjectsSection_addDialog_message);
+
+ if (dialog.open() == Window.OK) {
+ Object[] result = dialog.getResult();
+
+ if (result != null) {
+ IReferencedProjectItem first = null;
+ for (Object name : result) {
+ IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject((String)name);
+ if (prj != null && prj.isOpen()) {
+ IReferencedProjectItem item = new ReferencedProjectItem();
+ item.setProperty(IReferencedProjectItem.PROPERTY_ENABLED, true);
+ item.setProperty(IReferencedProjectItem.PROPERTY_PROJECT_NAME, prj.getName());
+ list.add(selIndex != -1 ? selIndex++ : 0, item);
+ if (first == null) {
+ first = item;
+ }
+ }
+ }
+ setInputList(list);
+ if (first != null) {
+ ((TableViewer)getTablePart().getViewer()).setSelection(new StructuredSelection(first), true);
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.forms.parts.AbstractTableSection#initializeButtonsEnablement()
+ */
+ @Override
+ protected void initializeButtonsEnablement() {
+ ISelection selection = ((TableViewer)getTablePart().getViewer()).getSelection();
+ boolean singleSelection = selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1;
+ int selIndex = ((TableViewer)getTablePart().getViewer()).getTable().getSelectionIndex();
+ int count = ((TableViewer)getTablePart().getViewer()).getTable().getItemCount();
+
+ getTablePart().getButton(0).setEnabled(getTablePart().isEnabled());
+ getTablePart().getButton(1).setEnabled(getTablePart().isEnabled() && singleSelection);
+ getTablePart().getButton(3).setEnabled(getTablePart().isEnabled() && singleSelection && selIndex > 0);
+ getTablePart().getButton(4).setEnabled(getTablePart().isEnabled() && singleSelection && selIndex < count-1);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/projects/ReferencedProjetcsTab.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/projects/ReferencedProjetcsTab.java
new file mode 100644
index 000000000..9c86abb7a
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/projects/ReferencedProjetcsTab.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.launch.ui.remote.app.projects;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tcf.te.launch.ui.tabs.AbstractFormsLaunchConfigurationTab;
+import org.eclipse.tcf.te.tcf.launch.ui.nls.Messages;
+import org.eclipse.tcf.te.ui.forms.CustomFormToolkit;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
+
+/**
+ * Referenced projetcs launch configuration tab implementation.
+ */
+public class ReferencedProjetcsTab extends AbstractFormsLaunchConfigurationTab {
+ // References to the tab sub sections
+ private ReferencedProjectsSection section;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.tabs.AbstractFormsLaunchConfigurationTab#dispose()
+ */
+ @Override
+ public void dispose() {
+ if (section != null) { section.dispose(); section = null; }
+ super.dispose();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.tabs.AbstractFormsLaunchConfigurationTab#doCreateFormContent(org.eclipse.swt.widgets.Composite, org.eclipse.tcf.te.ui.forms.CustomFormToolkit)
+ */
+ @Override
+ protected void doCreateFormContent(Composite parent, CustomFormToolkit toolkit) {
+ Assert.isNotNull(parent);
+ Assert.isNotNull(toolkit);
+
+ // Setup the main panel (using the table wrap layout)
+ Composite panel = toolkit.getFormToolkit().createComposite(parent);
+ TableWrapLayout layout = new TableWrapLayout();
+ layout.makeColumnsEqualWidth = true;
+ layout.numColumns = 1;
+ panel.setLayout(layout);
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ panel.setBackground(parent.getBackground());
+
+ section = new ReferencedProjectsSection(getManagedForm(), panel);
+ section.getSection().setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP));
+ getManagedForm().addPart(section);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
+ */
+ @Override
+ public String getName() {
+ return Messages.ReferencedProjectsTab_name;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/META-INF/MANIFEST.MF
index d3049fac1..ebfe30c70 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/META-INF/MANIFEST.MF
@@ -1,34 +1,36 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.tcf.te.tcf.locator; singleton:=true
-Bundle-Version: 1.0.0.qualifier
-Bundle-Activator: org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator
-Bundle-Vendor: %providerName
-Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
- org.eclipse.core.expressions;bundle-version="3.4.300",
- org.eclipse.tcf.core;bundle-version="1.0.0",
- org.eclipse.tcf.te.tcf.core;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime.model;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime.persistence;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime.services;bundle-version="1.0.0"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ActivationPolicy: lazy
-Bundle-Localization: plugin
-Export-Package: org.eclipse.tcf.te.tcf.locator,
- org.eclipse.tcf.te.tcf.locator.activator;x-internal:=true,
- org.eclipse.tcf.te.tcf.locator.interfaces,
- org.eclipse.tcf.te.tcf.locator.interfaces.nodes,
- org.eclipse.tcf.te.tcf.locator.interfaces.preferences,
- org.eclipse.tcf.te.tcf.locator.interfaces.services,
- org.eclipse.tcf.te.tcf.locator.internal;x-internal:=true,
- org.eclipse.tcf.te.tcf.locator.internal.adapters;x-internal:=true,
- org.eclipse.tcf.te.tcf.locator.internal.nls;x-internal:=true,
- org.eclipse.tcf.te.tcf.locator.internal.nodes;x-internal:=true,
- org.eclipse.tcf.te.tcf.locator.internal.preferences;x-internal:=true,
- org.eclipse.tcf.te.tcf.locator.internal.services;x-internal:=true,
- org.eclipse.tcf.te.tcf.locator.listener,
- org.eclipse.tcf.te.tcf.locator.model,
- org.eclipse.tcf.te.tcf.locator.nodes,
- org.eclipse.tcf.te.tcf.locator.services
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.tcf.te.tcf.locator; singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator
+Bundle-Vendor: %providerName
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.eclipse.core.expressions;bundle-version="3.4.300",
+ org.eclipse.tcf.core;bundle-version="1.0.0",
+ org.eclipse.tcf.te.core;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.model;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.persistence;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.services;bundle-version="1.0.0",
+ org.eclipse.tcf.te.tcf.core;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Bundle-Localization: plugin
+Export-Package: org.eclipse.tcf.te.tcf.locator,
+ org.eclipse.tcf.te.tcf.locator.activator;x-internal:=true,
+ org.eclipse.tcf.te.tcf.locator.interfaces,
+ org.eclipse.tcf.te.tcf.locator.interfaces.nodes,
+ org.eclipse.tcf.te.tcf.locator.interfaces.preferences,
+ org.eclipse.tcf.te.tcf.locator.interfaces.services,
+ org.eclipse.tcf.te.tcf.locator.internal;x-internal:=true,
+ org.eclipse.tcf.te.tcf.locator.internal.adapters;x-internal:=true,
+ org.eclipse.tcf.te.tcf.locator.internal.nls;x-internal:=true,
+ org.eclipse.tcf.te.tcf.locator.internal.nodes;x-internal:=true,
+ org.eclipse.tcf.te.tcf.locator.internal.preferences;x-internal:=true,
+ org.eclipse.tcf.te.tcf.locator.internal.services;x-internal:=true,
+ org.eclipse.tcf.te.tcf.locator.listener,
+ org.eclipse.tcf.te.tcf.locator.model,
+ org.eclipse.tcf.te.tcf.locator.nodes,
+ org.eclipse.tcf.te.tcf.locator.persistence,
+ org.eclipse.tcf.te.tcf.locator.services
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml
index 26ce9a9fc..6e9c8a3a0 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml
@@ -22,24 +22,92 @@
<!-- Persistence delegate contributions -->
<extension point="org.eclipse.tcf.te.runtime.persistence.delegates">
<delegate
- id="org.eclipse.tcf.te.tcf.locator.persistence"
- class="org.eclipse.tcf.te.tcf.locator.internal.PeersPersistenceDelegate">
+ id="org.eclipse.tcf.te.tcf.locator.persistence.peerToURI"
+ class="org.eclipse.tcf.te.tcf.locator.persistence.PeerToURIPersistenceDelegate">
+ </delegate>
+ <delegate
+ id="org.eclipse.tcf.te.tcf.locator.persistence.peerToString"
+ class="org.eclipse.tcf.te.tcf.locator.persistence.PeerToStringPersistenceDelegate">
+ </delegate>
+ <delegate
+ id="org.eclipse.tcf.te.tcf.locator.persistence.propertiesToString"
+ class="org.eclipse.tcf.te.tcf.locator.persistence.AbstractPropertiesToStringPersistenceDelegate">
</delegate>
</extension>
+<!-- Persistence delegate bindings contributions -->
+ <extension
+ point="org.eclipse.tcf.te.runtime.persistence.bindings">
+ <binding
+ delegateId="org.eclipse.tcf.te.tcf.locator.persistence.peerToURI"
+ id="org.eclipse.tcf.te.tcf.locator.binding.peerToURI">
+ <enablement>
+ <with variable="container">
+ <instanceof value="java.net.URI"/>
+ </with>
+ <with variable="context">
+ <or>
+ <instanceof value="org.eclipse.tcf.protocol.IPeer"/>
+ <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"/>
+ <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProvider"/>
+ <and>
+ <instanceof value="java.lang.Class"/>
+ <with variable="contextClass">
+ <equals value="org.eclipse.tcf.protocol.IPeer"/>
+ </with>
+ </and>
+ </or>
+ </with>
+ </enablement>
+ </binding>
+ <binding
+ delegateId="org.eclipse.tcf.te.tcf.locator.persistence.peerToString"
+ id="org.eclipse.tcf.te.tcf.locator.binding.peerToString">
+ <enablement>
+ <with variable="container">
+ <or>
+ <instanceof value="java.lang.String"/>
+ <and>
+ <instanceof value="java.lang.Class"/>
+ <with variable="containerClass">
+ <equals value="java.lang.String"/>
+ </with>
+ </and>
+ </or>
+ </with>
+ <with variable="context">
+ <or>
+ <instanceof value="org.eclipse.tcf.protocol.IPeer"/>
+ <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"/>
+ <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProvider"/>
+ <and>
+ <instanceof value="java.lang.Class"/>
+ <with variable="contextClass">
+ <equals value="org.eclipse.tcf.protocol.IPeer"/>
+ </with>
+ </and>
+ </or>
+ </with>
+ </enablement>
+ </binding>
+ </extension>
+
<!-- Adapter factory contributions -->
<extension point="org.eclipse.core.runtime.adapters">
<factory
- adaptableType="java.util.Map"
+ adaptableType="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"
class="org.eclipse.tcf.te.tcf.locator.internal.adapters.AdapterFactory">
- <adapter type="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable"/>
+ <adapter type="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider"/>
</factory>
-
<factory
- adaptableType="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"
+ adaptableType="org.eclipse.tcf.protocol.IPeer"
+ class="org.eclipse.tcf.te.tcf.locator.internal.adapters.AdapterFactory">
+ <adapter type="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider"/>
+ </factory>
+ <factory
+ adaptableType="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProvider"
class="org.eclipse.tcf.te.tcf.locator.internal.adapters.AdapterFactory">
- <adapter type="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable"/>
- <adapter type="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable2"/>
+ <adapter type="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider"/>
</factory>
</extension>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeersPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeersPersistenceDelegate.java
deleted file mode 100644
index 91112202b..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeersPersistenceDelegate.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * 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.tcf.locator.internal;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.net.URI;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.tcf.te.runtime.persistence.AbstractPersistenceDelegate;
-
-/**
- * Static peers persistence delegate implementation.
- */
-public class PeersPersistenceDelegate extends AbstractPersistenceDelegate {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#write(java.net.URI, java.util.Map)
- */
- @Override
- public void write(URI uri, Map<String, Object> data) throws IOException {
- Assert.isNotNull(uri);
- Assert.isNotNull(data);
-
- // Only "file:" URIs are supported
- if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
- throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Create the file object from the given URI
- File file = new File(uri.normalize());
-
- // The file must be absolute
- if (!file.isAbsolute()) {
- throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
- }
-
- // Check if the file extension is "ini" (otherwise it is not picked up)
- IPath path = new Path(file.getCanonicalPath());
- if (!"ini".equals(path.getFileExtension())) { //$NON-NLS-1$
- path = path.addFileExtension("ini"); //$NON-NLS-1$
- }
-
- BufferedWriter writer = null;
- try {
- writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path.toFile()), "UTF-8")); //$NON-NLS-1$
- for (String attribute : data.keySet()) {
- writer.write(attribute);
- writer.write('=');
- writer.write(data.get(attribute).toString());
- writer.newLine();
- }
- } finally {
- writer.close();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#delete(java.net.URI)
- */
- @Override
- public boolean delete(URI uri) throws IOException {
- Assert.isNotNull(uri);
-
- // Only "file:" URIs are supported
- if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
- throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Create the file object from the given URI
- File file = new File(uri.normalize());
-
- // The file must be absolute
- if (!file.isAbsolute()) {
- throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
- }
-
- // Check if the file extension is "ini" (otherwise it is not picked up)
- IPath path = new Path(file.getCanonicalPath());
- if (!"ini".equals(path.getFileExtension())) { //$NON-NLS-1$
- path = path.addFileExtension("ini"); //$NON-NLS-1$
- }
-
- return path.toFile().delete();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#read(java.net.URI)
- */
- @Override
- public Map<String, Object> read(URI uri) throws IOException {
- Assert.isNotNull(uri);
-
- // Only "file:" URIs are supported
- if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
- throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Create the file object from the given URI
- File file = new File(uri.normalize());
-
- // The file must be absolute
- if (!file.isAbsolute()) {
- throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
- }
-
- return null;
- }
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/AdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/AdapterFactory.java
index ce13c9dab..ea3d08fd5 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/AdapterFactory.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/AdapterFactory.java
@@ -11,22 +11,22 @@ package org.eclipse.tcf.te.tcf.locator.internal.adapters;
import java.util.Map;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable2;
+import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProvider;
/**
* Static peers adapter factory implementation.
*/
public class AdapterFactory implements IAdapterFactory {
// The single instance adapter references
- private final IPersistable mapPersistableAdapter = new MapPersistableAdapter();
- private final IPersistable peerModelPersistableAdapter = new PeerModelPersistableAdapter();
+ private final IPersistableURIProvider peerModelPersistableURIProvider = new PeerPersistableURIProvider();
private static final Class<?>[] CLASSES = new Class[] {
- IPersistable.class,
- IPersistable2.class
+ IPersistableURIProvider.class
};
/* (non-Javadoc)
@@ -35,17 +35,13 @@ public class AdapterFactory implements IAdapterFactory {
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adaptableObject instanceof Map) {
- if (IPersistable.class.equals(adapterType)) {
- return mapPersistableAdapter;
+ if (IPersistableURIProvider.class.equals(adapterType)) {
+ Assert.isTrue(false);
}
}
-
- if (adaptableObject instanceof IPeerModel) {
- if (IPersistable.class.equals(adapterType)) {
- return peerModelPersistableAdapter;
- }
- if (IPersistable2.class.equals(adapterType)) {
- return peerModelPersistableAdapter;
+ if (adaptableObject instanceof IPeerModel || adaptableObject instanceof IPeer || adaptableObject instanceof IPeerModelProvider) {
+ if (IPersistableURIProvider.class.equals(adapterType)) {
+ return peerModelPersistableURIProvider;
}
}
return null;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/MapPersistableAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/MapPersistableAdapter.java
deleted file mode 100644
index ed71f2b76..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/MapPersistableAdapter.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * 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.tcf.locator.internal.adapters;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.tcf.protocol.IPeer;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable;
-import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator;
-
-/**
- * Persistable implementation handling peer attributes.
- */
-public class MapPersistableAdapter implements IPersistable {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getStorageID()
- */
- @Override
- public String getStorageID() {
- return "org.eclipse.tcf.te.tcf.locator.persistence"; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getURI(java.lang.Object)
- */
- @SuppressWarnings("unchecked")
- @Override
- public URI getURI(final Object data) {
- Assert.isNotNull(data);
-
- URI uri = null;
-
- // Only map objects are supported
- if (data instanceof Map) {
- // Get the name of the peer and make it a valid
- // file system name (no spaces etc).
- String name = ((Map<String, String>) data).get(IPeer.ATTR_NAME);
- if (name == null) name = ((Map<String, String>) data).get(IPeer.ATTR_ID);
- name = makeValidFileSystemName(name);
- // Get the URI from the name
- uri = getRoot().append(name).toFile().toURI();
- }
-
- return uri;
- }
-
- /**
- * Make a valid file system name from the given name.
- *
- * @param name The original name. Must not be <code>null</code>.
- * @return The valid file system name.
- */
- private String makeValidFileSystemName(String name) {
- Assert.isNotNull(name);
- return name.replaceAll("\\W", "_"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Returns the root location of the peers storage.
- *
- * @return The root location or <code>null</code> if it cannot be determined.
- */
- public IPath getRoot() {
- IPath location = null;
-
- // Try the bundles state location first (not available if launched with -data @none).
- try {
- IPath path = CoreBundleActivator.getDefault().getStateLocation().append(".peers"); //$NON-NLS-1$
- if (!path.toFile().exists()) path.toFile().mkdirs();
- if (path.toFile().canRead() && path.toFile().isDirectory()) {
- location = path;
- }
- } catch (IllegalStateException e) {
- // Workspace less environments (-data @none)
- // The users local peers lookup directory is $HOME/.tcf/.peers.
- IPath path = new Path(System.getProperty("user.home")).append(".tcf/.peers"); //$NON-NLS-1$ //$NON-NLS-2$
- if (!path.toFile().exists()) path.toFile().mkdirs();
- if (path.toFile().canRead() && path.toFile().isDirectory()) {
- location = path;
- }
- }
-
- return location;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getInterfaceType(java.lang.Object)
- */
- @Override
- public String getInterfaceTypeName(Object data) {
- if (data instanceof Map) {
- // No bundle id needed here, it's a POJO
- return Map.class.getName();
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#exportFrom(java.lang.Object)
- */
- @SuppressWarnings("unchecked")
- @Override
- public Map<String, Object> exportFrom(Object data) throws IOException {
- Assert.isNotNull(data);
-
- Map<String, Object> result = null;
-
- // Only map objects are supported
- if (data instanceof Map) {
- // Convert into a String/Object map to pass it on to the persistence delegates
- result = new LinkedHashMap<String, Object>();
- for (String key : ((Map<String, String>) data).keySet()) {
- if (!key.endsWith(".transient")) { //$NON-NLS-1$
- result.put(key, ((Map<String, String>) data).get(key));
- }
- }
- }
-
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#importTo(java.lang.Object, java.util.Map)
- */
- @Override
- public void importTo(Object data, Map<String, Object> external) throws IOException {
- Assert.isNotNull(data);
- Assert.isNotNull(external);
-
- // Only map objects are supported
- if (data instanceof Map) {
- @SuppressWarnings("unchecked")
- Map<String, String> map = (Map<String, String>)data;
- for (String key : external.keySet()) map.put(key, (String)external.get(key));
- }
- }
-
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/MapPersistableURIProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/MapPersistableURIProvider.java
new file mode 100644
index 000000000..b96822f40
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/MapPersistableURIProvider.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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.tcf.locator.internal.adapters;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider;
+import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator;
+
+/**
+ * Persistable implementation handling peer attributes.
+ */
+public class MapPersistableURIProvider implements IPersistableURIProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider#getURI(java.lang.Object)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public URI getURI(final Object context) {
+ Assert.isNotNull(context);
+
+ Assert.isNotNull(null);
+
+ URI uri = null;
+
+ // Only map objects are supported
+ if (context instanceof Map) {
+ // Get the name of the peer and make it a valid
+ // file system name (no spaces etc).
+ String name = ((Map<String, String>) context).get(IPeer.ATTR_NAME);
+ if (name == null) {
+ name = ((Map<String, String>) context).get(IPeer.ATTR_ID);
+ }
+ name = makeValidFileSystemName(name);
+ // Get the URI from the name
+ uri = getRoot().append(name).toFile().toURI();
+ }
+
+ return uri;
+ }
+
+ /**
+ * Make a valid file system name from the given name.
+ *
+ * @param name The original name. Must not be <code>null</code>.
+ * @return The valid file system name.
+ */
+ private String makeValidFileSystemName(String name) {
+ Assert.isNotNull(name);
+ return name.replaceAll("\\W", "_"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Returns the root location.
+ *
+ * @return The root location or <code>null</code> if it cannot be determined.
+ */
+ protected IPath getRoot() {
+ IPath location = null;
+
+ // Try the bundles state location first (not available if launched with -data @none).
+ try {
+ IPath path = CoreBundleActivator.getDefault().getStateLocation().append(".peers"); //$NON-NLS-1$
+ if (!path.toFile().exists()) {
+ path.toFile().mkdirs();
+ }
+ if (path.toFile().canRead() && path.toFile().isDirectory()) {
+ location = path;
+ }
+ } catch (IllegalStateException e) {
+ // Workspace less environments (-data @none)
+ // The users local peers lookup directory is $HOME/.tcf/.peers.
+ IPath path = new Path(System.getProperty("user.home")).append(".tcf/.peers"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (!path.toFile().exists()) {
+ path.toFile().mkdirs();
+ }
+ if (path.toFile().canRead() && path.toFile().isDirectory()) {
+ location = path;
+ }
+ }
+
+ return location;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerModelPersistableAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerModelPersistableAdapter.java
deleted file mode 100644
index edd3bd006..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerModelPersistableAdapter.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*******************************************************************************
- * 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.tcf.locator.internal.adapters;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.tcf.core.TransientPeer;
-import org.eclipse.tcf.protocol.IPeer;
-import org.eclipse.tcf.protocol.JSON;
-import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable2;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
-import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
-import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService;
-import org.eclipse.tcf.te.tcf.locator.model.Model;
-import org.eclipse.tcf.te.tcf.locator.nodes.PeerModel;
-
-/**
- * Persistable implementation handling peer attributes.
- */
-public class PeerModelPersistableAdapter implements IPersistable2 {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getStorageID()
- */
- @Override
- public String getStorageID() {
- return "org.eclipse.tcf.te.tcf.locator.persistence"; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getURI(java.lang.Object)
- */
- @Override
- public URI getURI(final Object data) {
- Assert.isNotNull(data);
-
- URI uri = null;
-
- // Only peer model objects are supported
- if (data instanceof IPeerModel) {
- // Get the URI the peer model has been created from
- final AtomicReference<URI> nodeURI = new AtomicReference<URI>();
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- String value = ((IPeerModel)data).getPeer().getAttributes().get(IPersistableNodeProperties.PROPERTY_URI);
- if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$
- nodeURI.set(URI.create(value.trim()));
- }
- }
- };
- if (Protocol.isDispatchThread()) {
- runnable.run();
- }
- else {
- Protocol.invokeAndWait(runnable);
- }
-
- if (nodeURI.get() != null) {
- uri = nodeURI.get();
- }
- }
-
- return uri;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getInterfaceType(java.lang.Object)
- */
- @Override
- public String getInterfaceTypeName(Object data) {
- if (data instanceof IPeerModel) {
- return CoreBundleActivator.getUniqueIdentifier() + ":" + IPeerModel.class.getName(); //$NON-NLS-1$
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#exportFrom(java.lang.Object)
- */
- @Override
- public Map<String, Object> exportFrom(final Object data) throws IOException {
- Assert.isNotNull(data);
-
- final AtomicReference<Map<String, String>> attributes = new AtomicReference<Map<String, String>>();
-
- // Only peer model objects are supported
- if (data instanceof IPeerModel) {
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- attributes.set(((IPeerModel)data).getPeer().getAttributes());
- }
- };
- if (Protocol.isDispatchThread()) {
- runnable.run();
- }
- else {
- Protocol.invokeAndWait(runnable);
- }
- }
-
- Map<String, Object> result = null;
- if (attributes.get() != null) {
- result = new HashMap<String, Object>();
- for (String key : attributes.get().keySet()) {
- if (!key.endsWith(".transient")) { //$NON-NLS-1$
- result.put(key, attributes.get().get(key));
- }
- }
- }
-
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#importTo(java.lang.Object, java.util.Map)
- */
- @Override
- public void importTo(final Object data, final Map<String, Object> external) throws IOException {
- Assert.isNotNull(data);
- Assert.isNotNull(external);
-
- // A direct import of the attributes in a peer is not possible.
- // A new peer with the new attributes needs to be created and set to the peer model.
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable2#exportStringFrom(java.lang.Object)
- */
- @Override
- public String exportStringFrom(final Object data) {
- final AtomicReference<String> encoded = new AtomicReference<String>();
-
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- try {
- Map<String, Object> attrs = exportFrom(data);
-
- // Remove all transient attributes
- String[] keys = attrs.keySet().toArray(new String[attrs.keySet().size()]);
- for (String key : keys) {
- if (key.endsWith(".transient")) { //$NON-NLS-1$
- attrs.remove(key);
- }
- }
-
- encoded.set(JSON.toJSON(attrs));
- }
- catch (IOException e) {
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "PeerModelPersistableAdapter export failure: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getDefault().getBundle()).log(status);
- }
- }
- }
- };
-
- if (Protocol.isDispatchThread()) {
- runnable.run();
- }
- else {
- Protocol.invokeAndWait(runnable);
- }
-
- return encoded.get() != null ? encoded.get() : ""; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable2#getEncodedClassName(java.lang.Object)
- */
- @Override
- public String getEncodedClassName(final Object data) {
- return IPeerModel.class.getName();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable2#importFrom(java.lang.String)
- */
- @Override
- public Object importFrom(final String external) throws IOException {
- Assert.isNotNull(external);
-
- final AtomicReference<IPeerModel> decoded = new AtomicReference<IPeerModel>();
- final AtomicReference<IOException> error = new AtomicReference<IOException>();
-
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- try {
- Object o = JSON.parseOne(external.getBytes("UTF-8")); //$NON-NLS-1$
- // The decoded object should be a map
- if (o instanceof Map) {
- @SuppressWarnings("unchecked")
- Map<String, String> attrs = (Map<String, String>)o;
-
- // Get the id of the decoded attributes
- String id = attrs.get("ID"); //$NON-NLS-1$
- if (id == null) {
- throw new IOException("PeerModelPersistableAdapter#import: Mandatory attribure 'ID' is missing."); //$NON-NLS-1$
- }
-
- // Lookup the id within the model
- IPeerModel candidate = Model.getModel().getService(ILocatorModelLookupService.class).lkupPeerModelById(id);
- if (candidate != null) {
- decoded.set(candidate);
- return;
- }
-
- // Not found in the model -> create a ghost object
- IPeer peer = new TransientPeer(attrs);
- IPeerModel peerModel = new PeerModel(Model.getModel(), peer);
- peerModel.setProperty(IModelNode.PROPERTY_IS_GHOST, true);
-
- decoded.set(peerModel);
- } else {
- throw new IOException("PeerModelPersistableAdapter#import: Object not of map type."); //$NON-NLS-1$
- }
- } catch (IOException e) {
- error.set(e);
- }
- }
- };
-
- if (Protocol.isDispatchThread()) {
- runnable.run();
- }
- else {
- Protocol.invokeAndWait(runnable);
- }
-
- if (error.get() != null) {
- throw error.get();
- }
-
- return decoded.get() != null ? decoded.get() : ""; //$NON-NLS-1$
- }
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerPersistableURIProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerPersistableURIProvider.java
new file mode 100644
index 000000000..6705c5234
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerPersistableURIProvider.java
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * 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.tcf.locator.internal.adapters;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.tcf.core.TransientPeer;
+import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.protocol.JSON;
+import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.te.core.adapters.ModelNodePersistableURIProvider;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProvider;
+import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService;
+import org.eclipse.tcf.te.tcf.locator.model.Model;
+import org.eclipse.tcf.te.tcf.locator.model.ModelLocationUtil;
+import org.eclipse.tcf.te.tcf.locator.nodes.PeerModel;
+
+/**
+ * Persistable implementation handling peer attributes.
+ */
+public class PeerPersistableURIProvider extends ModelNodePersistableURIProvider {
+
+ private IPeer getPeer(Object context) {
+ IPeer peer = null;
+
+ if (context instanceof IPeer) {
+ peer = (IPeer)context;
+ }
+ else if (context instanceof IPeerModel) {
+ peer = ((IPeerModel)context).getPeer();
+ }
+ else if (context instanceof IPeerModelProvider) {
+ peer = ((IPeerModelProvider)context).getPeerModel().getPeer();
+ }
+
+ return peer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider#getURI(java.lang.Object)
+ */
+ @Override
+ public URI getURI(final Object context) {
+ Assert.isNotNull(context);
+
+ URI uri = null;
+ final IPeer peer = getPeer(context);
+
+ if (peer != null) {
+ // Get the URI the peer model has been created from
+ final AtomicReference<URI> nodeURI = new AtomicReference<URI>();
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ String value = peer.getAttributes().get(IPersistableNodeProperties.PROPERTY_URI);
+ if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$
+ nodeURI.set(URI.create(value.trim()));
+ }
+ }
+ };
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
+
+ if (nodeURI.get() != null) {
+ uri = nodeURI.get();
+ }
+
+ if (uri == null) {
+ String name = peer.getName();
+ if (name == null) {
+ name = peer.getID();
+ }
+ name = makeValidFileSystemName(name);
+ // Get the URI from the name
+ uri = getRoot().append(name).toFile().toURI();
+
+ }
+ }
+
+ return uri;
+ }
+
+ /**
+ * Returns the root location of the peers storage.
+ *
+ * @return The root location or <code>null</code> if it cannot be determined.
+ */
+ @Override
+ public IPath getRoot() {
+ return ModelLocationUtil.getStaticPeersRootLocation();
+ }
+
+ public String exportStringFrom(final Object data) {
+ final AtomicReference<String> encoded = new AtomicReference<String>();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ // try {
+ // Map<String, Object> attrs = exportFrom(data);
+ //
+ // // Remove all transient attributes
+ // String[] keys = attrs.keySet().toArray(new String[attrs.keySet().size()]);
+ // for (String key : keys) {
+ // if (key.endsWith(".transient")) { //$NON-NLS-1$
+ // attrs.remove(key);
+ // }
+ // }
+ //
+ // encoded.set(JSON.toJSON(attrs));
+ // }
+ // catch (IOException e) {
+ // if (Platform.inDebugMode()) {
+ // IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ // "PeerPersistableURIProvider export failure: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ // Platform.getLog(CoreBundleActivator.getDefault().getBundle()).log(status);
+ // }
+ // }
+ }
+ };
+
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
+
+ return encoded.get() != null ? encoded.get() : ""; //$NON-NLS-1$
+ }
+
+ public Object importFrom(final String external) throws IOException {
+ Assert.isNotNull(external);
+
+ final AtomicReference<IPeerModel> decoded = new AtomicReference<IPeerModel>();
+ final AtomicReference<IOException> error = new AtomicReference<IOException>();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Object o = JSON.parseOne(external.getBytes("UTF-8")); //$NON-NLS-1$
+ // The decoded object should be a map
+ if (o instanceof Map) {
+ @SuppressWarnings("unchecked")
+ Map<String, String> attrs = (Map<String, String>)o;
+
+ // Get the id of the decoded attributes
+ String id = attrs.get("ID"); //$NON-NLS-1$
+ if (id == null) {
+ throw new IOException("PeerPersistableURIProvider#import: Mandatory attribure 'ID' is missing."); //$NON-NLS-1$
+ }
+
+ // Lookup the id within the model
+ IPeerModel candidate = Model.getModel().getService(ILocatorModelLookupService.class).lkupPeerModelById(id);
+ if (candidate != null) {
+ decoded.set(candidate);
+ return;
+ }
+
+ // Not found in the model -> create a ghost object
+ IPeer peer = new TransientPeer(attrs);
+ IPeerModel peerModel = new PeerModel(Model.getModel(), peer);
+ peerModel.setProperty(IModelNode.PROPERTY_IS_GHOST, true);
+
+ decoded.set(peerModel);
+ } else {
+ throw new IOException("PeerPersistableURIProvider#import: Object not of map type."); //$NON-NLS-1$
+ }
+ } catch (IOException e) {
+ error.set(e);
+ }
+ }
+ };
+
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
+
+ if (error.get() != null) {
+ throw error.get();
+ }
+
+ return decoded.get() != null ? decoded.get() : ""; //$NON-NLS-1$
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelLocationUtil.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelLocationUtil.java
new file mode 100644
index 000000000..2e79ae47d
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelLocationUtil.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.locator.model;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator;
+
+/**
+ * Peer model location utility implementation.
+ */
+public final class ModelLocationUtil {
+
+ /**
+ * Returns the local static peers storage root location.
+ *
+ * @return The root location or <code>null</code> if the location cannot be determined.
+ */
+ public static IPath getStaticPeersRootLocation() {
+ try {
+ File file = CoreBundleActivator.getDefault().getStateLocation().append(".peers").toFile(); //$NON-NLS-1$
+ if (file.canRead() && file.isDirectory()) {
+ return new Path(file.toString());
+ }
+ } catch (IllegalStateException e) {
+ /* ignored on purpose */
+ }
+
+ // The users local peers lookup directory is $HOME/.tcf/.peers.
+ File file = new Path(System.getProperty("user.home")).append(".tcf/.peers").toFile(); //$NON-NLS-1$ //$NON-NLS-2$
+ if (file.canRead() && file.isDirectory()) {
+ return new Path(file.toString());
+ }
+
+ return null;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/AbstractPropertiesToStringPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/AbstractPropertiesToStringPersistenceDelegate.java
new file mode 100644
index 000000000..2282b6e86
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/AbstractPropertiesToStringPersistenceDelegate.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.locator.persistence;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.protocol.JSON;
+import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.te.runtime.persistence.AbstractPropertiesPersistenceDelegate;
+
+/**
+ * AbstractPropertiesToStringPersistenceDelegate
+ * @author tobias.schwarz@windriver.com
+ */
+public abstract class AbstractPropertiesToStringPersistenceDelegate extends AbstractPropertiesPersistenceDelegate {
+
+ /**
+ * Constructor.
+ */
+ public AbstractPropertiesToStringPersistenceDelegate() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#write(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public Object write(final Object context, Object container, String key) throws IOException {
+ Assert.isNotNull(context);
+ Assert.isNotNull(container);
+
+ if (container instanceof String || String.class.equals(container)) {
+ final AtomicReference<String> encoded = new AtomicReference<String>();
+
+ Runnable runnable = new Runnable() {
+ @SuppressWarnings("synthetic-access")
+ @Override
+ public void run() {
+ try {
+ encoded.set(JSON.toJSON(toMap(context)));
+ }
+ catch (IOException e) {
+ }
+ }
+ };
+
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
+ return encoded.get();
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#read(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object read(final Object context, final Object container, String key) throws IOException {
+ Assert.isNotNull(context);
+ Assert.isNotNull(container);
+
+ if (container instanceof String) {
+ final AtomicReference<Object> decoded = new AtomicReference<Object>();
+
+ Runnable runnable = new Runnable() {
+ @SuppressWarnings("synthetic-access")
+ @Override
+ public void run() {
+ try {
+ Object o = JSON.parseOne(((String)container).getBytes("UTF-8")); //$NON-NLS-1$
+ if (o instanceof Map) {
+ decoded.set(fromMap((Map<String,Object>)o, container));
+ }
+ } catch (IOException e) {
+ }
+ }
+ };
+
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
+
+ return decoded.get();
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#delete(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public boolean delete(Object context, Object container, String key) throws IOException {
+ return false;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/PeerToStringPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/PeerToStringPersistenceDelegate.java
new file mode 100644
index 000000000..79111ab06
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/PeerToStringPersistenceDelegate.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tcf.locator.persistence;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.core.TransientPeer;
+import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProvider;
+import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService;
+import org.eclipse.tcf.te.tcf.locator.model.Model;
+import org.eclipse.tcf.te.tcf.locator.nodes.PeerModel;
+
+/**
+ * Peer to string persistence delegate implementation.
+ */
+public class PeerToStringPersistenceDelegate extends AbstractPropertiesToStringPersistenceDelegate {
+
+ /**
+ * Constructor.
+ */
+ public PeerToStringPersistenceDelegate() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#getPersistedClassName(java.lang.Object)
+ */
+ @Override
+ public Class<?> getPersistedClass(Object context) {
+ return IPeer.class;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.locator.persistence.AbstractPropertiesToStringPersistenceDelegate#read(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public Object read(final Object context, final Object container, String key) throws IOException {
+ Assert.isNotNull(context);
+ Assert.isNotNull(container);
+
+ final IPeer peer = (IPeer)super.read(context, container, key);
+
+ if (peer != null) {
+ if (context instanceof IPeer || IPeer.class.equals(context)) {
+ return peer;
+ }
+ else if (context instanceof Class && (((Class<?>)context).isAssignableFrom(IPeerModel.class))) {
+ final AtomicReference<IPeerModel> model = new AtomicReference<IPeerModel>();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ // Get the id of the decoded attributes
+ String id = peer.getID();
+ if (id != null) {
+ // Lookup the id within the model
+ IPeerModel peerModel = Model.getModel().getService(ILocatorModelLookupService.class).lkupPeerModelById(id);
+ if (peerModel == null) {
+ // Not found in the model -> create a ghost object
+ peerModel = new PeerModel(Model.getModel(), peer);
+ peerModel.setProperty(IModelNode.PROPERTY_IS_GHOST, true);
+ }
+
+ model.set(peerModel);
+ }
+ }
+ };
+
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
+
+ return model.get();
+ }
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#toMap(java.lang.Object)
+ */
+ @Override
+ protected Map<String, Object> toMap(final Object context) throws IOException {
+ IPeer peer = getPeer(context);
+ if (peer != null) {
+ return super.toMap(peer.getAttributes());
+ }
+
+ return new HashMap<String, Object>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#fromMap(java.util.Map, java.lang.Object)
+ */
+ @Override
+ protected Object fromMap(Map<String, Object> map, Object context) throws IOException {
+ Map<String,String> attrs = new HashMap<String,String>();
+ for (String key : map.keySet()) {
+ attrs.put(key, map.get(key).toString());
+ }
+
+ return new TransientPeer(attrs);
+ }
+
+ /**
+ * Get a peer from the given context.
+ *
+ * @param context The context. Mut not be <code>null</code>.
+ * @return The peer or <code>null</code>.
+ */
+ protected IPeer getPeer(Object context) {
+ IPeer peer = null;
+
+ if (context instanceof IPeer) {
+ peer = (IPeer)context;
+ }
+ else if (context instanceof IPeerModel) {
+ peer = ((IPeerModel)context).getPeer();
+ }
+ else if (context instanceof IPeerModelProvider) {
+ peer = ((IPeerModelProvider)context).getPeerModel().getPeer();
+ }
+
+ return peer;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/PeerToURIPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/PeerToURIPersistenceDelegate.java
new file mode 100644
index 000000000..0cd194c20
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/PeerToURIPersistenceDelegate.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.tcf.locator.persistence;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.tcf.core.TransientPeer;
+import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.te.runtime.persistence.AbstractPropertiesToURIPersistenceDelegate;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProvider;
+
+/**
+ * Static peers persistence delegate implementation.
+ */
+public class PeerToURIPersistenceDelegate extends AbstractPropertiesToURIPersistenceDelegate {
+
+ /**
+ * Constructor.
+ */
+ public PeerToURIPersistenceDelegate() {
+ super("ini"); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#getPersistedClassName(java.lang.Object)
+ */
+ @Override
+ public Class<?> getPersistedClass(Object context) {
+ return IPeer.class;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#toMap(java.lang.Object)
+ */
+ @Override
+ protected Map<String, Object> toMap(final Object context) throws IOException {
+ IPeer peer = getPeer(context);
+ if (peer != null) {
+ return super.toMap(peer.getAttributes());
+ }
+
+ return new HashMap<String, Object>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.properties.PropertiesToURIPersistenceDelegate#fromMap(java.util.Map, java.lang.Object)
+ */
+ @Override
+ protected Object fromMap(Map<String, Object> map, Object context) throws IOException {
+ Map<String,String> attrs = new HashMap<String,String>();
+ for (String key : map.keySet()) {
+ attrs.put(key, map.get(key).toString());
+ }
+
+ return new TransientPeer(attrs);
+ }
+
+ /**
+ * Get a peer from the given context.
+ *
+ * @param context The context. Mut not be <code>null</code>.
+ * @return The peer or <code>null</code>.
+ */
+ protected IPeer getPeer(Object context) {
+ IPeer peer = null;
+
+ if (context instanceof IPeer) {
+ peer = (IPeer)context;
+ }
+ else if (context instanceof IPeerModel) {
+ peer = ((IPeerModel)context).getPeer();
+ }
+ else if (context instanceof IPeerModelProvider) {
+ peer = ((IPeerModelProvider)context).getPeerModel().getPeer();
+ }
+
+ return peer;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java
index a7e9a733e..8b81a0756 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java
@@ -1,427 +1,429 @@
-/*******************************************************************************
- * 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.tcf.locator.services;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.tcf.core.TransientPeer;
-import org.eclipse.tcf.protocol.IPeer;
-import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.services.ILocator;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
-import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil;
-import org.eclipse.tcf.te.tcf.core.Tcf;
-import org.eclipse.tcf.te.tcf.locator.ScannerRunnable;
-import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProperties;
-import org.eclipse.tcf.te.tcf.locator.interfaces.preferences.IPreferenceKeys;
-import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService;
-import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService;
-import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService;
-import org.eclipse.tcf.te.tcf.locator.nodes.LocatorModel;
-import org.eclipse.tcf.te.tcf.locator.nodes.PeerModel;
-import org.eclipse.tcf.te.tcf.locator.nodes.PeerRedirector;
-
-
-/**
- * Default locator model refresh service implementation.
- */
-public class LocatorModelRefreshService extends AbstractLocatorModelService implements ILocatorModelRefreshService {
-
- /**
- * Constructor.
- *
- * @param parentModel The parent locator model instance. Must not be <code>null</code>.
- */
- public LocatorModelRefreshService(ILocatorModel parentModel) {
- super(parentModel);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.services.ILocatorModelRefreshService#refresh()
- */
- @Override
- public void refresh() {
- Assert.isTrue(Protocol.isDispatchThread());
-
- // Get the parent locator model
- ILocatorModel model = getLocatorModel();
-
- // If the parent model is already disposed, the service will drop out immediately
- if (model.isDisposed()) return;
-
- // If the TCF framework isn't initialized yet, the service will drop out immediately
- if (!Tcf.isRunning()) return;
-
- // Get the list of old children (update node instances where possible)
- final List<IPeerModel> oldChildren = new ArrayList<IPeerModel>(Arrays.asList(model.getPeers()));
-
- // Get the locator service
- ILocator locatorService = Protocol.getLocator();
- if (locatorService != null) {
- // Check for the locator listener to be created and registered
- if (model instanceof LocatorModel) ((LocatorModel)model).checkLocatorListener();
- // Get the map of peers known to the locator service.
- Map<String, IPeer> peers = locatorService.getPeers();
- // Process the peers
- processPeers(peers, oldChildren, model);
- }
-
- // Refresh the static peer definitions
- refreshStaticPeers(oldChildren, model);
-
- // If there are remaining old children, remove them from the model (non-recursive)
- for (IPeerModel oldChild : oldChildren) model.getService(ILocatorModelUpdateService.class).remove(oldChild);
- }
-
- /**
- * Process the given map of peers and update the given locator model.
- *
- * @param peers The map of peers to process. Must not be <code>null</code>.
- * @param oldChildren The list of old children. Must not be <code>null</code>.
- * @param model The locator model. Must not be <code>null</code>.
- */
- protected void processPeers(Map<String, IPeer> peers, List<IPeerModel> oldChildren, ILocatorModel model) {
- Assert.isNotNull(peers);
- Assert.isNotNull(oldChildren);
- Assert.isNotNull(model);
-
- for (String peerId : peers.keySet()) {
- // Get the peer instance for the current peer id
- IPeer peer = peers.get(peerId);
- // Try to find an existing peer node first
- IPeerModel peerNode = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(peerId);
- // And create a new one if we cannot find it
- if (peerNode == null) peerNode = new PeerModel(model, peer);
- else oldChildren.remove(peerNode);
- // Merge user configured properties between the peers
- model.getService(ILocatorModelUpdateService.class).mergeUserDefinedAttributes(peerNode, peer, false);
- // Validate the peer node before adding
- peerNode = model.validatePeerNodeForAdd(peerNode);
- if (peerNode != null) {
- // There is still the chance that the node we add is a static node and
- // there exist an dynamically discovered node with a different id but
- // for the same peer. Do this check only if the peer to add is a static one.
- String value = peerNode.getPeer().getAttributes().get("static.transient"); //$NON-NLS-1$
- boolean isStatic = value != null && Boolean.parseBoolean(value.trim());
- if (isStatic) {
- for (IPeerModel candidate : oldChildren) {
- if (peerNode.getPeer().getTransportName().equals(candidate.getPeer().getTransportName())) {
- // Same transport name
- if ("PIPE".equals(candidate.getPeer().getTransportName())) { //$NON-NLS-1$
- // Compare the pipe name
- String name1 = peerNode.getPeer().getAttributes().get("PipeName"); //$NON-NLS-1$
- String name2 = candidate.getPeer().getAttributes().get("PipeName"); //$NON-NLS-1$
- // Same pipe -> same node
- if (name1 != null && name1.equals(name2)) {
- // Merge user configured properties between the peers
- model.getService(ILocatorModelUpdateService.class).mergeUserDefinedAttributes(candidate, peerNode.getPeer(), true);
- peerNode = null;
- break;
- }
- } else if ("Loop".equals(candidate.getPeer().getTransportName())) { //$NON-NLS-1$
- // Merge user configured properties between the peers
- model.getService(ILocatorModelUpdateService.class).mergeUserDefinedAttributes(candidate, peerNode.getPeer(), true);
- peerNode = null;
- break;
- } else {
- // Compare IP_HOST and IP_Port;
- String ip1 = peerNode.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST);
- String ip2 = candidate.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST);
- if (IPAddressUtil.getInstance().isSameHost(ip1, ip2)) {
- // Compare the ports
- String port1 = peerNode.getPeer().getAttributes().get(IPeer.ATTR_IP_PORT);
- if (port1 == null || "".equals(port1)) port1 = "1534"; //$NON-NLS-1$ //$NON-NLS-2$
- String port2 = candidate.getPeer().getAttributes().get(IPeer.ATTR_IP_PORT);
- if (port2 == null || "".equals(port2)) port2 = "1534"; //$NON-NLS-1$ //$NON-NLS-2$
-
- if (port1.equals(port2)) {
- // Merge user configured properties between the peers
- model.getService(ILocatorModelUpdateService.class).mergeUserDefinedAttributes(candidate, peerNode.getPeer(), true);
- peerNode = null;
- break;
- }
- }
- }
- }
- }
- }
- if (peerNode != null) {
- // Add the peer node to model
- model.getService(ILocatorModelUpdateService.class).add(peerNode);
- // And schedule for immediate status update
- Runnable runnable = new ScannerRunnable(model.getScanner(), peerNode);
- Protocol.invokeLater(runnable);
- }
- }
- }
- }
-
- private final AtomicBoolean REFRESH_STATIC_PEERS_GUARD = new AtomicBoolean(false);
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService#refreshStaticPeers()
- */
- @Override
- public void refreshStaticPeers() {
- Assert.isTrue(Protocol.isDispatchThread());
-
- // This method might be called reentrant while processing. Return immediately
- // in this case.
- if (REFRESH_STATIC_PEERS_GUARD.get()) return;
- REFRESH_STATIC_PEERS_GUARD.set(true);
-
- // Get the parent locator model
- ILocatorModel model = getLocatorModel();
-
- // If the parent model is already disposed, the service will drop out immediately
- if (model.isDisposed()) return;
-
- // Get the list of old children (update node instances where possible)
- final List<IPeerModel> oldChildren = new ArrayList<IPeerModel>(Arrays.asList(model.getPeers()));
-
- // Refresh the static peer definitions
- refreshStaticPeers(oldChildren, model);
-
- REFRESH_STATIC_PEERS_GUARD.set(false);
- }
-
- /**
- * Refresh the static peer definitions.
- *
- * @param oldChildren The list of old children. Must not be <code>null</code>.
- * @param model The locator model. Must not be <code>null</code>.
- */
- protected void refreshStaticPeers(List<IPeerModel> oldChildren, ILocatorModel model) {
- Assert.isNotNull(oldChildren);
- Assert.isNotNull(model);
-
- // Get the root locations to lookup the static peer definitions
- File[] roots = getStaticPeerLookupDirectories();
- if (roots.length > 0) {
- // The map of peers created from the static definitions
- Map<String, IPeer> peers = new HashMap<String, IPeer>();
- // The list of peer attributes with postponed peer instance creation
- List<Map<String, String>> postponed = new ArrayList<Map<String,String>>();
- // Process the root locations
- for (File root : roots) {
- // List all "*.ini" files within the root location
- File[] candidates = root.listFiles(new FileFilter() {
- @Override
- public boolean accept(File pathname) {
- IPath path = new Path(pathname.getAbsolutePath());
- return path.getFileExtension() != null && path.getFileExtension().toLowerCase().equals("ini"); //$NON-NLS-1$
- }
- });
- // If there are ini files to read, process them
- if (candidates != null && candidates.length > 0) {
-
- for (File candidate : candidates) {
- try {
- Properties properties = new Properties();
-
- // Load the properties found in the candidate file into
- // the Properties object. The input stream passed to
- // the Properties.load(...) method needs to be closed
- // manually afterwards.
- InputStream is = null;
- try {
- is = new FileInputStream(candidate);
- properties.load(is);
- } finally {
- if (is != null) {
- try { is.close(); } catch (IOException e) { /* ignored on purpose */ }
- }
- }
-
- // Remember the file path within the properties
- properties.setProperty(IPersistableNodeProperties.PROPERTY_URI, candidate.getAbsoluteFile().toURI().toString());
- // Mark the node as static peer model node
- properties.setProperty("static.transient", "true"); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Validate the name attribute. If not set, set
- // it to the file name without the .ini extension.
- String name = properties.getProperty(IPeer.ATTR_NAME);
- if (name == null || "".equals(name.trim())) { //$NON-NLS-1$
- name = new Path(candidate.getAbsolutePath()).removeFileExtension().lastSegment();
- properties.setProperty(IPeer.ATTR_NAME, name);
- }
-
- // Validate the id attribute. If not set, generate one.
- String id = properties.getProperty(IPeer.ATTR_ID);
- if (id == null || "".equals(id.trim()) || "USR:".equals(id.trim())) { //$NON-NLS-1$ //$NON-NLS-2$
- String transport = properties.getProperty(IPeer.ATTR_TRANSPORT_NAME);
- String host = properties.getProperty(IPeer.ATTR_IP_HOST);
- String port = properties.getProperty(IPeer.ATTR_IP_PORT);
-
- if (transport != null && host != null && !(id != null && "USR:".equals(id.trim()))) { //$NON-NLS-1$
- id = transport.trim() + ":" + host.trim(); //$NON-NLS-1$
- id += port != null ? ":" + port.trim() : ":1534"; //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- id = "USR:" + System.currentTimeMillis(); //$NON-NLS-1$
- // If the key is not unique, we have to wait a little bit an try again
- while (peers.containsKey(id)) {
- try { Thread.sleep(20); } catch (InterruptedException e) { /* ignored on purpose */ }
- id = "USR:" + System.currentTimeMillis(); //$NON-NLS-1$
- }
- }
- properties.put(IPeer.ATTR_ID, id);
- }
-
- // Copy all string attributes
- Map<String, String> attrs = new HashMap<String, String>();
- for (Object key : properties.keySet()) {
- if (key instanceof String && properties.get(key) instanceof String) {
- attrs.put((String)key, (String)properties.get(key));
- }
- }
-
- // If the redirect property is not set, create the peer right away
- if (properties.get(IPeerModelProperties.PROP_REDIRECT_PROXY) == null) {
- // Construct the peer from the attributes
- IPeer peer = new TransientPeer(attrs);
- // Add the constructed peer to the peers map
- peers.put(peer.getID(), peer);
- } else {
- // Try to get the peer proxy
- String proxyId = properties.getProperty(IPeerModelProperties.PROP_REDIRECT_PROXY);
- IPeer proxy = peers.get(proxyId);
- if (proxy == null) {
- IPeerModel peerModel = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(proxyId);
- if (peerModel != null) proxy = peerModel.getPeer();
- }
-
- if (proxy != null) {
- // Construct the peer redirector
- PeerRedirector redirector = new PeerRedirector(proxy, attrs);
- // Add the redirector to the peers map
- peers.put(redirector.getID(), redirector);
- } else {
- // Postpone peer creation
- postponed.add(attrs);
- }
- }
- } catch (IOException e) {
- /* ignored on purpose */
- }
- }
- }
- }
-
- // Process postponed peers if there are any
- if (!postponed.isEmpty()) {
- for (Map<String, String> attrs : postponed) {
- String proxyId = attrs.get(IPeerModelProperties.PROP_REDIRECT_PROXY);
- IPeer proxy = proxyId != null ? peers.get(proxyId) : null;
- if (proxy == null) {
- IPeerModel peerModel = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(proxyId);
- if (peerModel != null) proxy = peerModel.getPeer();
- }
-
- if (proxy != null) {
- // Construct the peer redirector
- PeerRedirector redirector = new PeerRedirector(proxy, attrs);
- // Add the redirector to the peers map
- peers.put(redirector.getID(), redirector);
- } else {
- // Proxy not available -> reset redirection
- attrs.remove(IPeerModelProperties.PROP_REDIRECT_PROXY);
- // Construct the peer from the attributes
- IPeer peer = new TransientPeer(attrs);
- // Add the constructed peer to the peers map
- peers.put(peer.getID(), peer);
- }
- }
- }
-
- // Process the read peers
- if (!peers.isEmpty()) processPeers(peers, oldChildren, model);
-
- // Scan the peers for redirected ones ... and set up the peer model association
- for (String peerId : peers.keySet()) {
- IPeer peer = peers.get(peerId);
- if (!(peer instanceof PeerRedirector)) continue;
-
- // Get the peers peer model object
- IPeerModel peerModel = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(peerId);
- Assert.isNotNull(peerModel);
-
- // The peer is a peer redirector -> get the proxy peer id and proxy peer model
- String proxyPeerId = ((PeerRedirector)peer).getParent().getID();
- IPeerModel proxy = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(proxyPeerId);
- Assert.isNotNull(proxy);
-
- peerModel.setParent(proxy);
- model.getService(ILocatorModelUpdateService.class).addChild(peerModel);
- }
- }
- }
-
- /**
- * Returns the list of root locations to lookup for static peers definitions.
- *
- * @return The list of root locations or an empty list.
- */
- protected File[] getStaticPeerLookupDirectories() {
- // The list defining the root locations
- List<File> rootLocations = new ArrayList<File>();
-
- // Check on the peers root locations preference setting
- String roots = Platform.getPreferencesService().getString(CoreBundleActivator.getUniqueIdentifier(),
- IPreferenceKeys.PREF_STATIC_PEERS_ROOT_LOCATIONS,
- null, null);
- // If set, split it in its single components
- if (roots != null) {
- String[] candidates = roots.split(File.pathSeparator);
- // Check on each candidate to denote an existing directory
- for (String candidate : candidates) {
- File file = new File(candidate);
- if (file.canRead() && file.isDirectory() && !rootLocations.contains(file)) {
- rootLocations.add(file);
- }
- }
- } else {
- // Try the bundles state location first (not available if launched with -data @none).
- try {
- File file = CoreBundleActivator.getDefault().getStateLocation().append(".peers").toFile(); //$NON-NLS-1$
- if (file.canRead() && file.isDirectory() && !rootLocations.contains(file)) {
- rootLocations.add(file);
- }
- } catch (IllegalStateException e) {
- /* ignored on purpose */
- }
-
- // The users local peers lookup directory is $HOME/.tcf/.peers.
- File file = new Path(System.getProperty("user.home")).append(".tcf/.peers").toFile(); //$NON-NLS-1$ //$NON-NLS-2$
- if (file.canRead() && file.isDirectory() && !rootLocations.contains(file)) {
- rootLocations.add(file);
- }
- }
-
- return rootLocations.toArray(new File[rootLocations.size()]);
- }
-}
+/*******************************************************************************
+ * 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.tcf.locator.services;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.tcf.core.TransientPeer;
+import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.services.ILocator;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil;
+import org.eclipse.tcf.te.tcf.core.Tcf;
+import org.eclipse.tcf.te.tcf.locator.ScannerRunnable;
+import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProperties;
+import org.eclipse.tcf.te.tcf.locator.interfaces.preferences.IPreferenceKeys;
+import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService;
+import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService;
+import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService;
+import org.eclipse.tcf.te.tcf.locator.model.ModelLocationUtil;
+import org.eclipse.tcf.te.tcf.locator.nodes.LocatorModel;
+import org.eclipse.tcf.te.tcf.locator.nodes.PeerModel;
+import org.eclipse.tcf.te.tcf.locator.nodes.PeerRedirector;
+
+
+/**
+ * Default locator model refresh service implementation.
+ */
+public class LocatorModelRefreshService extends AbstractLocatorModelService implements ILocatorModelRefreshService {
+
+ /**
+ * Constructor.
+ *
+ * @param parentModel The parent locator model instance. Must not be <code>null</code>.
+ */
+ public LocatorModelRefreshService(ILocatorModel parentModel) {
+ super(parentModel);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.services.ILocatorModelRefreshService#refresh()
+ */
+ @Override
+ public void refresh() {
+ Assert.isTrue(Protocol.isDispatchThread());
+
+ // Get the parent locator model
+ ILocatorModel model = getLocatorModel();
+
+ // If the parent model is already disposed, the service will drop out immediately
+ if (model.isDisposed()) {
+ return;
+ }
+
+ // If the TCF framework isn't initialized yet, the service will drop out immediately
+ if (!Tcf.isRunning()) {
+ return;
+ }
+
+ // Get the list of old children (update node instances where possible)
+ final List<IPeerModel> oldChildren = new ArrayList<IPeerModel>(Arrays.asList(model.getPeers()));
+
+ // Get the locator service
+ ILocator locatorService = Protocol.getLocator();
+ if (locatorService != null) {
+ // Check for the locator listener to be created and registered
+ if (model instanceof LocatorModel) {
+ ((LocatorModel)model).checkLocatorListener();
+ }
+ // Get the map of peers known to the locator service.
+ Map<String, IPeer> peers = locatorService.getPeers();
+ // Process the peers
+ processPeers(peers, oldChildren, model);
+ }
+
+ // Refresh the static peer definitions
+ refreshStaticPeers(oldChildren, model);
+
+ // If there are remaining old children, remove them from the model (non-recursive)
+ for (IPeerModel oldChild : oldChildren) {
+ model.getService(ILocatorModelUpdateService.class).remove(oldChild);
+ }
+ }
+
+ /**
+ * Process the given map of peers and update the given locator model.
+ *
+ * @param peers The map of peers to process. Must not be <code>null</code>.
+ * @param oldChildren The list of old children. Must not be <code>null</code>.
+ * @param model The locator model. Must not be <code>null</code>.
+ */
+ protected void processPeers(Map<String, IPeer> peers, List<IPeerModel> oldChildren, ILocatorModel model) {
+ Assert.isNotNull(peers);
+ Assert.isNotNull(oldChildren);
+ Assert.isNotNull(model);
+
+ for (String peerId : peers.keySet()) {
+ // Get the peer instance for the current peer id
+ IPeer peer = peers.get(peerId);
+ // Try to find an existing peer node first
+ IPeerModel peerNode = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(peerId);
+ // And create a new one if we cannot find it
+ if (peerNode == null) {
+ peerNode = new PeerModel(model, peer);
+ }
+ else {
+ oldChildren.remove(peerNode);
+ }
+ // Merge user configured properties between the peers
+ model.getService(ILocatorModelUpdateService.class).mergeUserDefinedAttributes(peerNode, peer, false);
+ // Validate the peer node before adding
+ peerNode = model.validatePeerNodeForAdd(peerNode);
+ if (peerNode != null) {
+ // There is still the chance that the node we add is a static node and
+ // there exist an dynamically discovered node with a different id but
+ // for the same peer. Do this check only if the peer to add is a static one.
+ String value = peerNode.getPeer().getAttributes().get("static.transient"); //$NON-NLS-1$
+ boolean isStatic = value != null && Boolean.parseBoolean(value.trim());
+ if (isStatic) {
+ for (IPeerModel candidate : oldChildren) {
+ if (peerNode.getPeer().getTransportName() != null && peerNode.getPeer().getTransportName().equals(candidate.getPeer().getTransportName())) {
+ // Same transport name
+ if ("PIPE".equals(candidate.getPeer().getTransportName())) { //$NON-NLS-1$
+ // Compare the pipe name
+ String name1 = peerNode.getPeer().getAttributes().get("PipeName"); //$NON-NLS-1$
+ String name2 = candidate.getPeer().getAttributes().get("PipeName"); //$NON-NLS-1$
+ // Same pipe -> same node
+ if (name1 != null && name1.equals(name2)) {
+ // Merge user configured properties between the peers
+ model.getService(ILocatorModelUpdateService.class).mergeUserDefinedAttributes(candidate, peerNode.getPeer(), true);
+ peerNode = null;
+ break;
+ }
+ } else if ("Loop".equals(candidate.getPeer().getTransportName())) { //$NON-NLS-1$
+ // Merge user configured properties between the peers
+ model.getService(ILocatorModelUpdateService.class).mergeUserDefinedAttributes(candidate, peerNode.getPeer(), true);
+ peerNode = null;
+ break;
+ } else {
+ // Compare IP_HOST and IP_Port;
+ String ip1 = peerNode.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST);
+ String ip2 = candidate.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST);
+ if (IPAddressUtil.getInstance().isSameHost(ip1, ip2)) {
+ // Compare the ports
+ String port1 = peerNode.getPeer().getAttributes().get(IPeer.ATTR_IP_PORT);
+ if (port1 == null || "".equals(port1)) { //$NON-NLS-1$
+ port1 = "1534"; //$NON-NLS-1$
+ }
+ String port2 = candidate.getPeer().getAttributes().get(IPeer.ATTR_IP_PORT);
+ if (port2 == null || "".equals(port2)) { //$NON-NLS-1$
+ port2 = "1534"; //$NON-NLS-1$
+ }
+
+ if (port1.equals(port2)) {
+ // Merge user configured properties between the peers
+ model.getService(ILocatorModelUpdateService.class).mergeUserDefinedAttributes(candidate, peerNode.getPeer(), true);
+ peerNode = null;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ if (peerNode != null) {
+ // Add the peer node to model
+ model.getService(ILocatorModelUpdateService.class).add(peerNode);
+ // And schedule for immediate status update
+ Runnable runnable = new ScannerRunnable(model.getScanner(), peerNode);
+ Protocol.invokeLater(runnable);
+ }
+ }
+ }
+ }
+
+ private final AtomicBoolean REFRESH_STATIC_PEERS_GUARD = new AtomicBoolean(false);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService#refreshStaticPeers()
+ */
+ @Override
+ public void refreshStaticPeers() {
+ Assert.isTrue(Protocol.isDispatchThread());
+
+ // This method might be called reentrant while processing. Return immediately
+ // in this case.
+ if (REFRESH_STATIC_PEERS_GUARD.get()) {
+ return;
+ }
+ REFRESH_STATIC_PEERS_GUARD.set(true);
+
+ // Get the parent locator model
+ ILocatorModel model = getLocatorModel();
+
+ // If the parent model is already disposed, the service will drop out immediately
+ if (model.isDisposed()) {
+ return;
+ }
+
+ // Get the list of old children (update node instances where possible)
+ final List<IPeerModel> oldChildren = new ArrayList<IPeerModel>(Arrays.asList(model.getPeers()));
+
+ // Refresh the static peer definitions
+ refreshStaticPeers(oldChildren, model);
+
+ REFRESH_STATIC_PEERS_GUARD.set(false);
+ }
+
+ /**
+ * Refresh the static peer definitions.
+ *
+ * @param oldChildren The list of old children. Must not be <code>null</code>.
+ * @param model The locator model. Must not be <code>null</code>.
+ */
+ protected void refreshStaticPeers(List<IPeerModel> oldChildren, ILocatorModel model) {
+ Assert.isNotNull(oldChildren);
+ Assert.isNotNull(model);
+
+ // Get the root locations to lookup the static peer definitions
+ File[] roots = getStaticPeerLookupDirectories();
+ if (roots.length > 0) {
+ // The map of peers created from the static definitions
+ Map<String, IPeer> peers = new HashMap<String, IPeer>();
+ // The list of peer attributes with postponed peer instance creation
+ List<Map<String, String>> postponed = new ArrayList<Map<String,String>>();
+ // Process the root locations
+ for (File root : roots) {
+ // List all "*.ini" files within the root location
+ File[] candidates = root.listFiles(new FileFilter() {
+ @Override
+ public boolean accept(File pathname) {
+ IPath path = new Path(pathname.getAbsolutePath());
+ return path.getFileExtension() != null && path.getFileExtension().toLowerCase().equals("ini"); //$NON-NLS-1$
+ }
+ });
+ // If there are ini files to read, process them
+ if (candidates != null && candidates.length > 0) {
+
+ for (File candidate : candidates) {
+ try {
+ IURIPersistenceService service = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ IPeer tempPeer = (IPeer)service.read(candidate.getAbsoluteFile().toURI(), IPeer.class);
+
+ Map<String,String> attrs = new HashMap<String, String>(tempPeer.getAttributes());
+
+ // Remember the file path within the properties
+ attrs.put(IPersistableNodeProperties.PROPERTY_URI, candidate.getAbsoluteFile().toURI().toString());
+ // Mark the node as static peer model node
+ attrs.put("static.transient", "true"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // Validate the name attribute. If not set, set
+ // it to the file name without the .ini extension.
+ String name = attrs.get(IPeer.ATTR_NAME);
+ if (name == null || "".equals(name.trim())) { //$NON-NLS-1$
+ name = new Path(candidate.getAbsolutePath()).removeFileExtension().lastSegment();
+ attrs.put(IPeer.ATTR_NAME, name);
+ }
+
+ // Validate the id attribute. If not set, generate one.
+ String id = attrs.get(IPeer.ATTR_ID);
+ if (id == null || "".equals(id.trim()) || "USR:".equals(id.trim())) { //$NON-NLS-1$ //$NON-NLS-2$
+ String transport = attrs.get(IPeer.ATTR_TRANSPORT_NAME);
+ String host = attrs.get(IPeer.ATTR_IP_HOST);
+ String port = attrs.get(IPeer.ATTR_IP_PORT);
+
+ if (transport != null && host != null && !(id != null && "USR:".equals(id.trim()))) { //$NON-NLS-1$
+ id = transport.trim() + ":" + host.trim(); //$NON-NLS-1$
+ id += port != null ? ":" + port.trim() : ":1534"; //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ id = "USR:" + System.currentTimeMillis(); //$NON-NLS-1$
+ // If the key is not unique, we have to wait a little bit an try again
+ while (peers.containsKey(id)) {
+ try { Thread.sleep(20); } catch (InterruptedException e) { /* ignored on purpose */ }
+ id = "USR:" + System.currentTimeMillis(); //$NON-NLS-1$
+ }
+ }
+ attrs.put(IPeer.ATTR_ID, id);
+ }
+
+ // If the redirect property is not set, create the peer right away
+ if (attrs.get(IPeerModelProperties.PROP_REDIRECT_PROXY) == null) {
+ // Construct the peer from the attributes
+ IPeer peer = new TransientPeer(attrs);
+ // Add the constructed peer to the peers map
+ peers.put(peer.getID(), peer);
+ } else {
+ // Try to get the peer proxy
+ String proxyId = attrs.get(IPeerModelProperties.PROP_REDIRECT_PROXY);
+ IPeer proxy = peers.get(proxyId);
+ if (proxy == null) {
+ IPeerModel peerModel = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(proxyId);
+ if (peerModel != null) {
+ proxy = peerModel.getPeer();
+ }
+ }
+
+ if (proxy != null) {
+ // Construct the peer redirector
+ PeerRedirector redirector = new PeerRedirector(proxy, attrs);
+ // Add the redirector to the peers map
+ peers.put(redirector.getID(), redirector);
+ } else {
+ // Postpone peer creation
+ postponed.add(attrs);
+ }
+ }
+ } catch (IOException e) {
+ /* ignored on purpose */
+ }
+ }
+ }
+ }
+
+ // Process postponed peers if there are any
+ if (!postponed.isEmpty()) {
+ for (Map<String, String> attrs : postponed) {
+ String proxyId = attrs.get(IPeerModelProperties.PROP_REDIRECT_PROXY);
+ IPeer proxy = proxyId != null ? peers.get(proxyId) : null;
+ if (proxy == null) {
+ IPeerModel peerModel = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(proxyId);
+ if (peerModel != null) {
+ proxy = peerModel.getPeer();
+ }
+ }
+
+ if (proxy != null) {
+ // Construct the peer redirector
+ PeerRedirector redirector = new PeerRedirector(proxy, attrs);
+ // Add the redirector to the peers map
+ peers.put(redirector.getID(), redirector);
+ } else {
+ // Proxy not available -> reset redirection
+ attrs.remove(IPeerModelProperties.PROP_REDIRECT_PROXY);
+ // Construct the peer from the attributes
+ IPeer peer = new TransientPeer(attrs);
+ // Add the constructed peer to the peers map
+ peers.put(peer.getID(), peer);
+ }
+ }
+ }
+
+ // Process the read peers
+ if (!peers.isEmpty()) {
+ processPeers(peers, oldChildren, model);
+ }
+
+ // Scan the peers for redirected ones ... and set up the peer model association
+ for (String peerId : peers.keySet()) {
+ IPeer peer = peers.get(peerId);
+ if (!(peer instanceof PeerRedirector)) {
+ continue;
+ }
+
+ // Get the peers peer model object
+ IPeerModel peerModel = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(peerId);
+ Assert.isNotNull(peerModel);
+
+ // The peer is a peer redirector -> get the proxy peer id and proxy peer model
+ String proxyPeerId = ((PeerRedirector)peer).getParent().getID();
+ IPeerModel proxy = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(proxyPeerId);
+ Assert.isNotNull(proxy);
+
+ peerModel.setParent(proxy);
+ model.getService(ILocatorModelUpdateService.class).addChild(peerModel);
+ }
+ }
+ }
+
+ /**
+ * Returns the list of root locations to lookup for static peers definitions.
+ *
+ * @return The list of root locations or an empty list.
+ */
+ protected File[] getStaticPeerLookupDirectories() {
+ // The list defining the root locations
+ List<File> rootLocations = new ArrayList<File>();
+
+ // Check on the peers root locations preference setting
+ String roots = Platform.getPreferencesService().getString(CoreBundleActivator.getUniqueIdentifier(),
+ IPreferenceKeys.PREF_STATIC_PEERS_ROOT_LOCATIONS,
+ null, null);
+ // If set, split it in its single components
+ if (roots != null) {
+ String[] candidates = roots.split(File.pathSeparator);
+ // Check on each candidate to denote an existing directory
+ for (String candidate : candidates) {
+ File file = new File(candidate);
+ if (file.canRead() && file.isDirectory() && !rootLocations.contains(file)) {
+ rootLocations.add(file);
+ }
+ }
+ }
+
+ // always add default root location
+ IPath defaultPath = ModelLocationUtil.getStaticPeersRootLocation();
+ if (defaultPath != null) {
+ File file = defaultPath.toFile();
+ if (file.canRead() && file.isDirectory() && !rootLocations.contains(file)) {
+ rootLocations.add(file);
+ }
+ }
+
+ return rootLocations.toArray(new File[rootLocations.size()]);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/AttributesSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/AttributesSection.java
index b5e8ace70..7dfc2f7c4 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/AttributesSection.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/AttributesSection.java
@@ -25,7 +25,7 @@ import org.eclipse.tcf.core.TransientPeer;
import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
@@ -59,10 +59,10 @@ public class AttributesSection extends AbstractSection {
* to add to the table.
*/
private static final String[] BANNED_NAMES = new String[] {
- IPeer.ATTR_ID, IPeer.ATTR_AGENT_ID, IPeer.ATTR_SERVICE_MANGER_ID, "ServerManagerID", //$NON-NLS-1$
- IPeer.ATTR_NAME, IPeer.ATTR_TRANSPORT_NAME, IPeer.ATTR_IP_HOST,
- IPeer.ATTR_IP_PORT, "PipeName" //$NON-NLS-1$
- };
+ IPeer.ATTR_ID, IPeer.ATTR_AGENT_ID, IPeer.ATTR_SERVICE_MANGER_ID, "ServerManagerID", //$NON-NLS-1$
+ IPeer.ATTR_NAME, IPeer.ATTR_TRANSPORT_NAME, IPeer.ATTR_IP_HOST,
+ IPeer.ATTR_IP_PORT, "PipeName" //$NON-NLS-1$
+ };
/*
* The list of filtered attributes. This attributes are filtered from the data given to the
@@ -70,10 +70,10 @@ public class AttributesSection extends AbstractSection {
* overview page.
*/
private static final String[] FILTERED_NAMES = new String [] {
- IPeer.ATTR_ID, IPeer.ATTR_NAME,
- IPeer.ATTR_TRANSPORT_NAME, IPeer.ATTR_IP_HOST, IPeer.ATTR_IP_PORT,
- "PipeName" //$NON-NLS-1$
- };
+ IPeer.ATTR_ID, IPeer.ATTR_NAME,
+ IPeer.ATTR_TRANSPORT_NAME, IPeer.ATTR_IP_HOST, IPeer.ATTR_IP_PORT,
+ "PipeName" //$NON-NLS-1$
+ };
/**
* Constructor.
@@ -103,7 +103,7 @@ public class AttributesSection extends AbstractSection {
if (PeerAttributesTablePart.class.equals(adapter)) {
return tablePart;
}
- return super.getAdapter(adapter);
+ return super.getAdapter(adapter);
}
/* (non-Javadoc)
@@ -150,7 +150,7 @@ public class AttributesSection extends AbstractSection {
if (active) {
// Leave everything unchanged if the page is in dirty state
if (getManagedForm().getContainer() instanceof AbstractEditorPage
- && !((AbstractEditorPage)getManagedForm().getContainer()).isDirty()) {
+ && !((AbstractEditorPage)getManagedForm().getContainer()).isDirty()) {
Object node = ((AbstractEditorPage)getManagedForm().getContainer()).getEditorInputNode();
if (node instanceof IPeerModel) {
setupData((IPeerModel)node);
@@ -176,7 +176,9 @@ public class AttributesSection extends AbstractSection {
wc.clearProperties();
// If no data is available, we are done
- if (node == null) return;
+ if (node == null) {
+ return;
+ }
// Thread access to the model is limited to the executors thread.
// Copy the data over to the working copy to ease the access.
@@ -216,7 +218,9 @@ public class AttributesSection extends AbstractSection {
}
// Pass on to the table part
- if (tablePart != null) tablePart.setAttributes(attributes);
+ if (tablePart != null) {
+ tablePart.setAttributes(attributes);
+ }
// Adjust the control enablement
updateEnablement();
@@ -232,7 +236,9 @@ public class AttributesSection extends AbstractSection {
*/
public void extractData(final IPeerModel node) {
// If no data is available, we are done
- if (node == null) return;
+ if (node == null) {
+ return;
+ }
// Extract the table part attributes into the working copy
// Properties not longer available in the table part attributes
@@ -274,14 +280,18 @@ public class AttributesSection extends AbstractSection {
}
}
// Remove the disappeared properties
- for (String key : removed) attributes.remove(key);
+ for (String key : removed) {
+ attributes.remove(key);
+ }
// Create the new peer
IPeer newPeer = oldPeer instanceof PeerRedirector ? new PeerRedirector(((PeerRedirector)oldPeer).getParent(), attributes) : new TransientPeer(attributes);
// Update the peer node instance (silently)
boolean changed = node.setChangeEventsEnabled(false);
node.setProperty(IPeerModelProperties.PROP_INSTANCE, newPeer);
- if (changed) node.setChangeEventsEnabled(true);
+ if (changed) {
+ node.setChangeEventsEnabled(true);
+ }
}
});
}
@@ -294,10 +304,12 @@ public class AttributesSection extends AbstractSection {
// Remember the current dirty state
boolean needsSaving = isDirty();
// Call the super implementation (resets the dirty state)
- super.commit(onSave);
+ super.commit(onSave);
// Nothing to do if not on save or saving is not needed
- if (!onSave || !needsSaving) return;
+ if (!onSave || !needsSaving) {
+ return;
+ }
// Extract the data into the original data node
extractData(od);
@@ -308,10 +320,12 @@ public class AttributesSection extends AbstractSection {
if (!odc.equals(wc)) {
try {
// Get the persistence service
- IPersistenceService persistenceService = ServiceManager.getInstance().getService(IPersistenceService.class);
- if (persistenceService == null) throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ }
// Save the peer node to the new persistence storage
- persistenceService.write(od.getPeer().getAttributes());
+ uRIPersistenceService.write(od.getPeer(), null);
} catch (IOException e) {
// Pass on to the editor page
}
@@ -377,9 +391,15 @@ public class AttributesSection extends AbstractSection {
}
}
};
- if (Protocol.isDispatchThread()) runnable.run();
- else Protocol.invokeAndWait(runnable);
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
- if (tablePart != null) tablePart.setReadOnly(!isStatic.get() || isRemote.get());
+ if (tablePart != null) {
+ tablePart.setReadOnly(!isStatic.get() || isRemote.get());
+ }
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/GeneralInformationSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/GeneralInformationSection.java
index 118d052c1..3d2aeac8c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/GeneralInformationSection.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/GeneralInformationSection.java
@@ -10,7 +10,6 @@
package org.eclipse.tcf.te.tcf.ui.editor.sections;
import java.io.IOException;
-import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -29,7 +28,7 @@ import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
@@ -290,21 +289,21 @@ public class GeneralInformationSection extends AbstractSection {
// Update the (managed) attributes from the working copy
attributes.put(IPeer.ATTR_NAME, wc.getStringProperty(IPeer.ATTR_NAME));
// Update the persistence storage URI (if set)
- if (attributes.containsKey(IPersistableNodeProperties.PROPERTY_URI)) {
- IPersistenceService persistenceService = ServiceManager.getInstance().getService(IPersistenceService.class);
- if (persistenceService != null) {
- URI uri = null;
- try {
- uri = persistenceService.getURI(attributes);
- } catch (IOException e) { /* ignored on purpose */ }
- if (uri != null) {
- attributes.put(IPersistableNodeProperties.PROPERTY_URI, uri.toString());
- }
- else {
- attributes.remove(IPersistableNodeProperties.PROPERTY_URI);
- }
- }
- }
+ // if (attributes.containsKey(IPersistableNodeProperties.PROPERTY_URI)) {
+ // IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ // if (uRIPersistenceService != null) {
+ // URI uri = null;
+ // try {
+ // uri = uRIPersistenceService.getURI(attributes);
+ // } catch (IOException e) { /* ignored on purpose */ }
+ // if (uri != null) {
+ // attributes.put(IPersistableNodeProperties.PROPERTY_URI, uri.toString());
+ // }
+ // else {
+ attributes.remove(IPersistableNodeProperties.PROPERTY_URI);
+ // }
+ // }
+ // }
// Create the new peer
IPeer newPeer = oldPeer instanceof PeerRedirector ? new PeerRedirector(((PeerRedirector)oldPeer).getParent(), attributes) : new TransientPeer(attributes);
// Update the peer node instance (silently)
@@ -364,15 +363,18 @@ public class GeneralInformationSection extends AbstractSection {
if (!oldName.equals(wc.getStringProperty(IPeer.ATTR_NAME))) {
try {
// Get the persistence service
- IPersistenceService persistenceService = ServiceManager.getInstance().getService(IPersistenceService.class);
- if (persistenceService == null)
- {
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
}
// Remove the old persistence storage using the original data copy
- persistenceService.delete(odc.getProperties());
+ Map<String,String> oldData = new HashMap<String, String>();
+ for (String key : odc.getProperties().keySet()) {
+ oldData.put(key, odc.getStringProperty(key));
+ }
+ uRIPersistenceService.delete(new TransientPeer(oldData), null);
// Save the peer node to the new persistence storage
- persistenceService.write(od.getPeer().getAttributes());
+ uRIPersistenceService.write(od.getPeer(), null);
} catch (IOException e) {
// Pass on to the editor page
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/TransportSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/TransportSection.java
index c03baae96..2dcde8398 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/TransportSection.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/TransportSection.java
@@ -27,7 +27,7 @@ import org.eclipse.tcf.protocol.IChannel;
import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.tcf.core.Tcf;
@@ -100,7 +100,7 @@ public class TransportSection extends AbstractSection {
if (TransportSectionTypePanelControl.class.equals(adapter)) {
return transportTypePanelControl;
}
- return super.getAdapter(adapter);
+ return super.getAdapter(adapter);
}
/* (non-Javadoc)
@@ -163,7 +163,7 @@ public class TransportSection extends AbstractSection {
if (active) {
// Leave everything unchanged if the page is in dirty state
if (getManagedForm().getContainer() instanceof AbstractEditorPage
- && !((AbstractEditorPage)getManagedForm().getContainer()).isDirty()) {
+ && !((AbstractEditorPage)getManagedForm().getContainer()).isDirty()) {
Object node = ((AbstractEditorPage)getManagedForm().getContainer()).getEditorInputNode();
if (node instanceof IPeerModel) {
setupData((IPeerModel)node);
@@ -189,7 +189,9 @@ public class TransportSection extends AbstractSection {
wc.clearProperties();
// If no data is available, we are done
- if (node == null) return;
+ if (node == null) {
+ return;
+ }
// Thread access to the model is limited to the executors thread.
// Copy the data over to the working copy to ease the access.
@@ -208,7 +210,9 @@ public class TransportSection extends AbstractSection {
for (String id : transportTypePanelControl.getConfigurationPanelIds()) {
IWizardConfigurationPanel panel = transportTypePanelControl.getConfigurationPanel(id);
- if (panel instanceof IDataExchangeNode3) ((IDataExchangeNode3)panel).copyData(src, odc);
+ if (panel instanceof IDataExchangeNode3) {
+ ((IDataExchangeNode3)panel).copyData(src, odc);
+ }
}
}
@@ -227,7 +231,9 @@ public class TransportSection extends AbstractSection {
if (transportTypePanelControl != null) {
transportTypePanelControl.showConfigurationPanel(transportType);
IWizardConfigurationPanel panel = transportTypePanelControl.getConfigurationPanel(transportType);
- if (panel instanceof IDataExchangeNode) ((IDataExchangeNode)panel).setupData(wc);
+ if (panel instanceof IDataExchangeNode) {
+ ((IDataExchangeNode)panel).setupData(wc);
+ }
}
}
}
@@ -246,7 +252,9 @@ public class TransportSection extends AbstractSection {
*/
public void extractData(final IPeerModel node) {
// If no data is available, we are done
- if (node == null) return;
+ if (node == null) {
+ return;
+ }
// The list of removed attributes
final List<String> removed = new ArrayList<String>();
@@ -259,7 +267,9 @@ public class TransportSection extends AbstractSection {
// Get the current transport type configuration panel
IWizardConfigurationPanel panel = transportTypePanelControl.getConfigurationPanel(oldTransportType);
// And clean out the current transport type specific attributes from the working copy
- if (panel instanceof IDataExchangeNode3) ((IDataExchangeNode3)panel).removeData(wc);
+ if (panel instanceof IDataExchangeNode3) {
+ ((IDataExchangeNode3)panel).removeData(wc);
+ }
}
// Get the new transport type from the widget
@@ -269,17 +279,23 @@ public class TransportSection extends AbstractSection {
// Get the new transport type configuration panel
IWizardConfigurationPanel panel = transportTypePanelControl.getConfigurationPanel(transportType);
// And extract the new attributes into the working copy
- if (panel instanceof IDataExchangeNode) ((IDataExchangeNode)panel).extractData(wc);
+ if (panel instanceof IDataExchangeNode) {
+ ((IDataExchangeNode)panel).extractData(wc);
+ }
// If the data has not changed compared to the original data copy,
// we are done here and return immediately
- if (odc.equals(wc)) return;
+ if (odc.equals(wc)) {
+ return;
+ }
// Get the new key set from the working copy
Set<String> newKeySet = wc.getProperties().keySet();
// Everything from the old key set not found in the new key set is a removed attribute
for (String key : currentKeySet) {
- if (!newKeySet.contains(key)) removed.add(key);
+ if (!newKeySet.contains(key)) {
+ removed.add(key);
+ }
}
// Copy the working copy data back to the original properties container
@@ -291,7 +307,9 @@ public class TransportSection extends AbstractSection {
// Create a write able copy of the peer attributes
Map<String, String> attributes = new HashMap<String, String>(oldPeer.getAttributes());
// Clean out the removed attributes
- for (String key : removed) attributes.remove(key);
+ for (String key : removed) {
+ attributes.remove(key);
+ }
// Update with the current configured attributes
for (String key : wc.getProperties().keySet()) {
String value = wc.getStringProperty(key);
@@ -304,7 +322,9 @@ public class TransportSection extends AbstractSection {
// If there is still a open channel to the old peer, close it by force
IChannel channel = Tcf.getChannelManager().getChannel(oldPeer);
- if (channel != null) channel.close();
+ if (channel != null) {
+ channel.close();
+ }
// Create the new peer
IPeer newPeer = oldPeer instanceof PeerRedirector ? new PeerRedirector(((PeerRedirector)oldPeer).getParent(), attributes) : new TransientPeer(attributes);
@@ -319,7 +339,9 @@ public class TransportSection extends AbstractSection {
node.setProperty("dns.name.transient", null); //$NON-NLS-1$
node.setProperty("dns.lastIP.transient", null); //$NON-NLS-1$
node.setProperty("dns.skip.transient", null); //$NON-NLS-1$
- if (changed) node.setChangeEventsEnabled(true);
+ if (changed) {
+ node.setChangeEventsEnabled(true);
+ }
}
});
}
@@ -329,7 +351,7 @@ public class TransportSection extends AbstractSection {
*/
@Override
public boolean isValid() {
- boolean valid = super.isValid();
+ boolean valid = super.isValid();
if (transportTypeControl != null) {
valid &= transportTypeControl.isValid();
@@ -356,10 +378,12 @@ public class TransportSection extends AbstractSection {
// Remember the current dirty state
boolean needsSaving = isDirty();
// Call the super implementation (resets the dirty state)
- super.commit(onSave);
+ super.commit(onSave);
// Nothing to do if not on save or saving is not needed
- if (!onSave || !needsSaving) return;
+ if (!onSave || !needsSaving) {
+ return;
+ }
// Extract the data into the original data node
extractData(od);
@@ -369,10 +393,12 @@ public class TransportSection extends AbstractSection {
if (!odc.equals(wc)) {
try {
// Get the persistence service
- IPersistenceService persistenceService = ServiceManager.getInstance().getService(IPersistenceService.class);
- if (persistenceService == null) throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ }
// Save the peer node to the new persistence storage
- persistenceService.write(od.getPeer().getAttributes());
+ uRIPersistenceService.write(od.getPeer(), null);
} catch (IOException e) {
// Pass on to the editor page
}
@@ -412,7 +438,9 @@ public class TransportSection extends AbstractSection {
if (transportTypePanelControl != null) {
IWizardConfigurationPanel panel = transportTypePanelControl.getConfigurationPanel(transportType);
- if (panel != null) isDirty |= panel.dataChanged(odc, e);
+ if (panel != null) {
+ isDirty |= panel.dataChanged(odc, e);
+ }
}
}
@@ -443,15 +471,21 @@ public class TransportSection extends AbstractSection {
}
}
};
- if (Protocol.isDispatchThread()) runnable.run();
- else Protocol.invokeAndWait(runnable);
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
// The transport type control is enabled for static peers
if (transportTypeControl != null) {
SWTControlUtil.setEnabled(transportTypeControl.getEditFieldControl(), isStatic.get() && !isRemote.get());
if (transportTypePanelControl != null) {
IWizardConfigurationPanel panel = transportTypePanelControl.getConfigurationPanel(transportTypeControl.getSelectedTransportType());
- if (panel != null) panel.setEnabled(isStatic.get() && !isRemote.get());
+ if (panel != null) {
+ panel.setEnabled(isStatic.get() && !isRemote.get());
+ }
}
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RedirectHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RedirectHandler.java
index fc7e9b197..97ec5f9ff 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RedirectHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RedirectHandler.java
@@ -29,9 +29,10 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
+import org.eclipse.tcf.core.TransientPeer;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerManager;
@@ -84,8 +85,10 @@ public class RedirectHandler extends AbstractHandler {
filter.add(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (peerModel.equals(element)) return false;
- return true;
+ if (peerModel.equals(element)) {
+ return false;
+ }
+ return true;
}
});
@@ -149,9 +152,11 @@ public class RedirectHandler extends AbstractHandler {
attributes.put(IPeerModelProperties.PROP_REDIRECT_PROXY, proxy.getPeerId());
try {
- IPersistenceService persistenceService = ServiceManager.getInstance().getService(IPersistenceService.class);
- if (persistenceService == null) throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
- persistenceService.write(attributes);
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ }
+ uRIPersistenceService.write(new TransientPeer(attributes), null);
// Create a peer redirector
PeerRedirector redirector = new PeerRedirector(proxy.getPeer(), attributes);
@@ -165,14 +170,14 @@ public class RedirectHandler extends AbstractHandler {
// Trigger a refresh of the locator model in a later dispatch cycle
Protocol.invokeLater(new Runnable() {
@Override
- public void run() {
+ public void run() {
Model.getModel().getService(ILocatorModelRefreshService.class).refresh();
}
});
} catch (IOException e) {
// Create the status
IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
- Messages.RedirectHandler_error_redirectFailed, e);
+ Messages.RedirectHandler_error_redirectFailed, e);
// Fill in the status handler custom data
IPropertiesContainer data = new PropertiesContainer();
@@ -182,7 +187,9 @@ public class RedirectHandler extends AbstractHandler {
// Get the status handler
IStatusHandler[] handler = StatusHandlerManager.getInstance().getHandler(peerModel);
- if (handler.length > 0) handler[0].handleStatus(status, data, null);
+ if (handler.length > 0) {
+ handler[0].handleStatus(status, data, null);
+ }
}
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/ResetRedirectHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/ResetRedirectHandler.java
index 86638a190..c52dc0382 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/ResetRedirectHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/ResetRedirectHandler.java
@@ -25,7 +25,7 @@ import org.eclipse.tcf.core.TransientPeer;
import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerManager;
@@ -92,12 +92,14 @@ public class ResetRedirectHandler extends AbstractHandler {
try {
// Save it
- IPersistenceService persistenceService = ServiceManager.getInstance().getService(IPersistenceService.class);
- if (persistenceService == null) throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
- persistenceService.write(attributes);
-
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ }
// Create a peer
IPeer peer = new TransientPeer(attributes);
+ uRIPersistenceService.write(peer, null);
+
// And update the instance
peerModel.setProperty(IPeerModelProperties.PROP_INSTANCE, peer);
@@ -108,14 +110,14 @@ public class ResetRedirectHandler extends AbstractHandler {
// Trigger a refresh of the locator model in a later dispatch cycle
Protocol.invokeLater(new Runnable() {
@Override
- public void run() {
+ public void run() {
Model.getModel().getService(ILocatorModelRefreshService.class).refresh();
}
});
} catch (IOException e) {
// Create the status
IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
- Messages.ResetRedirectHandler_error_resetRedirectFailed, e);
+ Messages.ResetRedirectHandler_error_resetRedirectFailed, e);
// Fill in the status handler custom data
IPropertiesContainer data = new PropertiesContainer();
@@ -125,7 +127,9 @@ public class ResetRedirectHandler extends AbstractHandler {
// Get the status handler
IStatusHandler[] handler = StatusHandlerManager.getInstance().getHandler(peerModel);
- if (handler.length > 0) handler[0].handleStatus(status, data, null);
+ if (handler.length > 0) {
+ handler[0].handleStatus(status, data, null);
+ }
}
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/DeleteHandlerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/DeleteHandlerDelegate.java
index c6aeb3c75..73da18be1 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/DeleteHandlerDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/DeleteHandlerDelegate.java
@@ -18,7 +18,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerManager;
@@ -47,17 +47,21 @@ public class DeleteHandlerDelegate implements IDeleteHandlerDelegate {
final AtomicBoolean canDelete = new AtomicBoolean();
Runnable runnable = new Runnable() {
- @Override
- public void run() {
- String value = ((IPeerModel)element).getPeer().getAttributes().get("static.transient"); //$NON-NLS-1$
- canDelete.set(value != null && Boolean.parseBoolean(value.trim()));
- }
- };
+ @Override
+ public void run() {
+ String value = ((IPeerModel)element).getPeer().getAttributes().get("static.transient"); //$NON-NLS-1$
+ canDelete.set(value != null && Boolean.parseBoolean(value.trim()));
+ }
+ };
- if (Protocol.isDispatchThread()) runnable.run();
- else Protocol.invokeAndWait(runnable);
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
- return canDelete.get();
+ return canDelete.get();
}
return false;
}
@@ -72,13 +76,15 @@ public class DeleteHandlerDelegate implements IDeleteHandlerDelegate {
if (canDelete(element)) {
try {
- IPersistenceService service = ServiceManager.getInstance().getService(IPersistenceService.class);
- if (service == null) throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
- service.delete(element);
+ IURIPersistenceService service = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (service == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ }
+ service.delete(element, null);
} catch (IOException e) {
// Create the status
IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
- Messages.DeleteHandler_error_deleteFailed, e);
+ Messages.DeleteHandler_error_deleteFailed, e);
// Fill in the status handler custom data
IPropertiesContainer data = new PropertiesContainer();
@@ -88,7 +94,9 @@ public class DeleteHandlerDelegate implements IDeleteHandlerDelegate {
// Get the status handler
IStatusHandler[] handler = StatusHandlerManager.getInstance().getHandler(element);
- if (handler.length > 0) handler[0].handleStatus(status, data, null);
+ if (handler.length > 0) {
+ handler[0].handleStatus(status, data, null);
+ }
}
// Get the locator model
@@ -107,7 +115,9 @@ public class DeleteHandlerDelegate implements IDeleteHandlerDelegate {
}
}
} else {
- if (callback != null) callback.done(this, Status.OK_STATUS);
+ if (callback != null) {
+ callback.done(this, Status.OK_STATUS);
+ }
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/categories/CategoryManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/categories/CategoryManager.java
index 026af3a88..c17a3d6b6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/categories/CategoryManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/categories/CategoryManager.java
@@ -21,9 +21,10 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.tcf.core.TransientPeer;
import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService;
@@ -150,7 +151,9 @@ public class CategoryManager {
// If the peer node is a static node already, there is nothing to do here
String value = node.getPeer().getAttributes().get("static.transient"); //$NON-NLS-1$
boolean isStatic = value != null && Boolean.parseBoolean(value.trim());
- if (isStatic) return;
+ if (isStatic) {
+ return;
+ }
// Not a static node yet, copy the peer attributes
Map<String, String> attrs = new HashMap<String, String>();
@@ -165,20 +168,26 @@ public class CategoryManager {
// Persist the attributes
try {
- IPersistenceService persistenceService = ServiceManager.getInstance().getService(IPersistenceService.class);
- if (persistenceService == null) throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
- persistenceService.write(attrs);
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ }
+ uRIPersistenceService.write(new TransientPeer(attrs), null);
Model.getModel().getService(ILocatorModelRefreshService.class).refresh();
} catch (IOException e) {
IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
- NLS.bind(Messages.CategoryManager_dnd_failed, e.getLocalizedMessage()), e);
+ NLS.bind(Messages.CategoryManager_dnd_failed, e.getLocalizedMessage()), e);
UIPlugin.getDefault().getLog().log(status);
}
}
};
- if (Protocol.isDispatchThread()) runnable.run();
- else Protocol.invokeAndWait(runnable);
+ if (Protocol.isDispatchThread()) {
+ runnable.run();
+ }
+ else {
+ Protocol.invokeAndWait(runnable);
+ }
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/NewTargetWizard.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/NewTargetWizard.java
index 8fbfbbacd..dd5b156f5 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/NewTargetWizard.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/NewTargetWizard.java
@@ -21,9 +21,10 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.tcf.core.TransientPeer;
import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
@@ -65,9 +66,11 @@ public class NewTargetWizard extends AbstractWizard implements INewWizard {
try {
// Save the new peer
- IPersistenceService persistenceService = ServiceManager.getInstance().getService(IPersistenceService.class);
- if (persistenceService == null) throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
- persistenceService.write(peerAttributes);
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ }
+ uRIPersistenceService.write(new TransientPeer(peerAttributes), null);
// Get the locator model
final ILocatorModel model = Model.getModel();
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractPartWithButtons.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractPartWithButtons.java
index 2329978cd..8f1463a4e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractPartWithButtons.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractPartWithButtons.java
@@ -86,7 +86,9 @@ public abstract class AbstractPartWithButtons extends AbstractPart {
* @return The buttons panel composite or <code>null</code>.
*/
protected Composite createButtonsPanel(Composite parent, FormToolkit toolkit) {
- if (labels.length == 0) return null;
+ if (labels.length == 0) {
+ return null;
+ }
buttons = new Button[labels.length];
@@ -113,6 +115,7 @@ public abstract class AbstractPartWithButtons extends AbstractPart {
button.setFont(JFaceResources.getDialogFont());
button.setText(labels[i]);
button.setData(Integer.valueOf(i));
+ button.setBackground(panel.getBackground());
button.addSelectionListener(listener);
onButtonCreated(button);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractStructuredViewerSection.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractStructuredViewerSection.java
index 5589c4f9a..4b67370fc 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractStructuredViewerSection.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractStructuredViewerSection.java
@@ -53,6 +53,8 @@ public abstract class AbstractStructuredViewerSection extends AbstractSection {
viewerPart = createViewerPart(labels);
viewerPart.setMinSize(50, 50);
+ getSection().setBackground(parent.getBackground());
+
createClient(getSection(), form.getToolkit());
}
@@ -151,6 +153,8 @@ public abstract class AbstractStructuredViewerSection extends AbstractSection {
*/
@Override
public void setFocus() {
- if (viewerPart != null) viewerPart.getViewer().getControl().setFocus();
+ if (viewerPart != null) {
+ viewerPart.getViewer().getControl().setFocus();
+ }
}
}

Back to the top