diff options
author | Tobias Schwarz | 2014-04-09 13:35:56 +0000 |
---|---|---|
committer | Tobias Schwarz | 2014-04-09 13:35:56 +0000 |
commit | 87d617e8fb906aabfebc268bb0a65fca5111f393 (patch) | |
tree | 3d29ceba3ec2eb39dc89544738f09b84c54a521c | |
parent | ac3614fec55fd49e54d58da00492b21f1f35460a (diff) | |
download | org.eclipse.tcf-87d617e8fb906aabfebc268bb0a65fca5111f393.tar.gz org.eclipse.tcf-87d617e8fb906aabfebc268bb0a65fca5111f393.tar.xz org.eclipse.tcf-87d617e8fb906aabfebc268bb0a65fca5111f393.zip |
Target Explorer: rework action history
20 files changed, 408 insertions, 51 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.properties index c3dd1eb04..26913a684 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.properties @@ -11,4 +11,5 @@ pluginName = Target Explorer, Core providerName = Eclipse.org - Target Explorer +SaveToHistoryStep.name=Save History SetConnectStateStep.name=Set Connect State
\ No newline at end of file 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 22b79bd8a..5b4bd0c1d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.core/plugin.xml @@ -30,6 +30,10 @@ label="%SetConnectStateStep.name" class="org.eclipse.tcf.te.core.steps.SetConnectStateStep"> </step> + <step id="org.eclipse.tcf.te.core.saveToHistoryStep" + label="%SaveToHistoryStep.name" + class="org.eclipse.tcf.te.core.steps.SaveToHistoryStep"> + </step> </extension> <!-- Reusable core expression fragments --> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/steps/SaveToHistoryStep.java b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/steps/SaveToHistoryStep.java new file mode 100644 index 000000000..d8ff4dc69 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/steps/SaveToHistoryStep.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2014 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.steps; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Status; +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.history.HistoryManager; +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.IStepAttributes; +import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; +import org.eclipse.tcf.te.runtime.stepper.steps.AbstractStep; + +/** + * SaveToHistoryStep + */ +public class SaveToHistoryStep extends AbstractStep { + + public static final String PARAMETER_HISTORY_ID = "historyId"; //$NON-NLS-1$ + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStep#validateExecute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public void validateExecute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor) throws CoreException { + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStep#execute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) + */ + @Override + public void execute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor, ICallback callback) { + String historyId = getParameters().get(PARAMETER_HISTORY_ID); + if (historyId == null) { + historyId = StepperAttributeUtil.getStringProperty(IStepAttributes.ATTR_HISTORY_ID, fullQualifiedId, data); + } + String initialData = StepperAttributeUtil.getStringProperty(IStepAttributes.ATTR_HISTORY_DATA, fullQualifiedId, data); + if (historyId != null && initialData != null && initialData.trim().length() > 0) { + HistoryManager.getInstance().add(historyId, initialData.trim()); + } + + callback.done(this, Status.OK_STATUS); + } +} 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 261daa67f..f80a94507 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 @@ -20,4 +20,5 @@ Export-Package: org.eclipse.tcf.te.runtime.persistence, org.eclipse.tcf.te.runtime.persistence.history, org.eclipse.tcf.te.runtime.persistence.interfaces, org.eclipse.tcf.te.runtime.persistence.internal;x-internal:=true, - org.eclipse.tcf.te.runtime.persistence.services + org.eclipse.tcf.te.runtime.persistence.services, + org.eclipse.tcf.te.runtime.persistence.utils diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java index a6c685fca..d9b673608 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IPath; @@ -187,7 +188,8 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I data.put(VARIABLES, variables); } } - return data; + Map<String, Object> sorted = new TreeMap<String, Object>(data); + return sorted; } catch (Exception e) { diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/history/HistoryManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/history/HistoryManager.java index b44ab4a69..3e29fe54c 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/history/HistoryManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/history/HistoryManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2012 - 2014 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 @@ -103,23 +103,41 @@ public class HistoryManager { /** * Get the history for a given history id. * @param historyId The history id. - * @return The list of ids within the history ids list or an empty list. + * @return The list of entries within the history ids list or an empty list. */ public String[] getHistory(String historyId) { Assert.isNotNull(historyId); - List<String> ids = history.get(historyId); - if (ids == null) { - ids = new ArrayList<String>(); + List<String> entries = history.get(historyId); + if (entries == null) { + entries = new ArrayList<String>(); } - return ids.toArray(new String[ids.size()]); + return entries.toArray(new String[entries.size()]); + } + + /** + * Get all history ids matching the given id pattern. + * @param historyIdPattern The history id regex pattern. + * @return The list of history ids matching the given pattern or an empty list. + */ + public String[] getMatchingHistoryIds(String historyIdPattern) { + Assert.isNotNull(historyIdPattern); + + List<String> historyIds = new ArrayList<String>(); + for (String historyId : history.keySet()) { + if (historyId.matches(historyIdPattern)) { + historyIds.add(historyId); + } + } + + return historyIds.toArray(new String[historyIds.size()]); } /** * Get the fist entry of a history ids list. * @param historyId The history id. - * @return The first entry of the history ids list or null if no history is available for that id. + * @return The first entry for the given history ids or null if no history is available for that id. */ public String getFirst(String historyId) { String[] history = getHistory(historyId); @@ -130,26 +148,39 @@ public class HistoryManager { * Add a new history entry to the top of the history ids list. * If the list size exceeds the HISTORY_LENGTH, the last element of the list will be removed. * @param historyId The history id. - * @param id The id to be added to the top of history ids list. + * @param entry The entry to be added to the top of history ids list. * @return <code>true</code> if the id */ - public boolean add(String historyId, String id) { + public boolean add(String historyId, String entry) { + return add(historyId, entry, HISTORY_LENGTH); + } + + /** + * Add a new history entry to the top of the history ids list. + * If the list size exceeds the HISTORY_LENGTH, the last element of the list will be removed. + * @param historyId The history id. + * @param entry The id to be added to the top of history ids list. + * @param historyLength The maximum length of the history. + * @return <code>true</code> if the entry was added + */ + public boolean add(String historyId, String entry, int historyLength) { Assert.isNotNull(historyId); - Assert.isNotNull(id); + Assert.isNotNull(entry); + Assert.isTrue(historyLength > 0); List<String> ids = history.get(historyId); if (ids == null) { ids = new ArrayList<String>(); history.put(historyId, ids); } - if (ids.contains(id)) { - ids.remove(id); + if (ids.contains(entry)) { + ids.remove(entry); } - ids.add(0, id); + ids.add(0, entry); - while (ids.size() > HISTORY_LENGTH) { - ids.remove(HISTORY_LENGTH); + while (ids.size() > historyLength) { + ids.remove(historyLength); } flush(); @@ -163,18 +194,30 @@ public class HistoryManager { * Set a new list of history entries to the history ids list. * If the list size exceeds the HISTORY_LENGTH, the last element of the list will be removed. * @param historyId The history id. - * @param ids The ids to be set to the history ids list. - * @return <code>true</code> if the id + * @param entries The entries to be set to the history ids list. + * @return <code>true</code> if the entries were added + */ + public void set(String historyId, String[] entries) { + set(historyId, entries, HISTORY_LENGTH); + } + + /** + * Set a new list of history entries to the history ids list. + * If the list size exceeds the HISTORY_LENGTH, the last element of the list will be removed. + * @param historyId The history id. + * @param entries The entries to be set to the history ids list. + * @param historyLength The maximum length of the history. + * @return <code>true</code> if the entries were set */ - public void set(String historyId, String[] ids) { + public void set(String historyId, String[] entries, int historyLength) { Assert.isNotNull(historyId); - Assert.isNotNull(ids); + Assert.isNotNull(entries); - history.put(historyId, Arrays.asList(ids)); + history.put(historyId, Arrays.asList(entries)); List<String> newIds = history.get(historyId); - while (newIds.size() > HISTORY_LENGTH) { - newIds.remove(HISTORY_LENGTH); + while (newIds.size() > historyLength) { + newIds.remove(historyLength); } flush(); @@ -185,18 +228,18 @@ public class HistoryManager { /** * Remove a id from the history ids list. * @param historyId The history id. - * @param id The id to be removed from the history ids list. - * @return <code>true</code> if the id was removed from the history ids list. + * @param entry The entry to be removed from the history ids list. + * @return <code>true</code> if the entry was removed from the history ids list. */ - public boolean remove(String historyId, String id) { + public boolean remove(String historyId, String entry) { Assert.isNotNull(historyId); - Assert.isNotNull(id); + Assert.isNotNull(entry); boolean removed = false; List<String> ids = history.get(historyId); if (ids != null) { - removed |= ids.remove(id); + removed |= ids.remove(entry); if (ids.isEmpty()) { history.remove(historyId); } @@ -215,11 +258,15 @@ public class HistoryManager { * @param historyId The history id. **/ public void clear(String historyId) { - Assert.isNotNull(historyId); - - List<String> ids = history.remove(historyId); + List<String> entries = null; + if (historyId == null) { + history.clear(); + } + else { + entries = history.remove(historyId); + } - if (ids != null) { + if (entries != null || historyId == null) { flush(); EventManager.getInstance().fireEvent(new ChangeEvent(this, ChangeEvent.ID_REMOVED, historyId, historyId)); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/utils/DataHelper.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/utils/DataHelper.java new file mode 100644 index 000000000..d1c4f418d --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/utils/DataHelper.java @@ -0,0 +1,95 @@ +/** + * DataHelper.java + * Created on Aug 21, 2013 + * + * Copyright (c) 2013 Wind River Systems, Inc. + * + * The right to copy, distribute, modify, or otherwise make use + * of this software may be licensed only pursuant to the terms + * of an applicable Wind River license agreement. + */ +package org.eclipse.tcf.te.runtime.persistence.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; +import org.eclipse.tcf.te.runtime.persistence.PersistenceManager; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate; +import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; + +/** + * Data helper for de/encoding. + */ +public class DataHelper { + + /** + * Encode a properties container to a string. + * @param data The properties container. + * @return String representing the properties container. + */ + public static final String encodePropertiesContainer(IPropertiesContainer data) { + try { + if (data != null && !data.isEmpty()) { + IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(Map.class, String.class); + return (String)delegate.write(data, String.class); + } + } + catch (Exception e) { + } + return null; + } + + /** + * Decode a string encoded properties container. + * @param encoded The string encoded properties container. + * @return Properties container. + */ + public static final IPropertiesContainer decodePropertiesContainer(String encoded) { + if (encoded != null && encoded.trim().length() > 0) { + try { + IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(Map.class, String.class); + return (IPropertiesContainer)delegate.read(IPropertiesContainer.class, encoded); + } + catch (Exception e) { + } + } + return new PropertiesContainer(); + } + + /** + * Convert all keys of the map to lower case. + * @param list The list of maps to convert. + * @return List with new maps with lowercase keys. + */ + public static List<Map<String,Object>> keysToLowerCase(List<Map<String,Object>> list) { + List<Map<String, Object>> paramListLowerCase = new ArrayList<Map<String,Object>>(); + for (Map<String, Object> map : list) { + paramListLowerCase.add(keysToLowerCase(map)); + } + return paramListLowerCase; + } + + /** + * Convert all keys of the map to lower case. + * @param map The map to convert. + * @return New map with lowercase keys. + */ + @SuppressWarnings("unchecked") + public static Map<String,Object> keysToLowerCase(Map<String,Object> map) { + Map<String, Object> mapLowerCase = new HashMap<String, Object>(); + for (String key : map.keySet()) { + Object value = map.get(key); + if (value instanceof Map) { + value = keysToLowerCase((Map<String,Object>)value); + } + else if (value instanceof List) { + value = keysToLowerCase((List<Map<String,Object>>)value); + } + mapLowerCase.put(key.toLowerCase(), value); + } + return mapLowerCase; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/META-INF/MANIFEST.MF index aefb32ec7..8e314c15c 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", org.eclipse.tcf.te.runtime.concurrent;bundle-version="1.3.0", org.eclipse.tcf.te.runtime.model;bundle-version="1.3.0", org.eclipse.tcf.te.runtime.services;bundle-version="1.3.0", - org.eclipse.tcf.te.runtime.statushandler;bundle-version="1.3.0" + org.eclipse.tcf.te.runtime.statushandler;bundle-version="1.3.0", + org.eclipse.tcf.te.runtime.persistence;bundle-version="1.3.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Bundle-Localization: plugin diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/interfaces/IStepAttributes.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/interfaces/IStepAttributes.java index b94de8a91..2853044de 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/interfaces/IStepAttributes.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/interfaces/IStepAttributes.java @@ -33,4 +33,22 @@ public interface IStepAttributes { * The running job operation. */ public static final String ATTR_STEPPER_JOB_OPERATION = ATTR_PREFIX + ".stepper_job_operation"; //$NON-NLS-1$ + + /** + * The id to persist the data of stepper execution to the history. + * If this attribute is not set, it is filled automatically with <stepGroupId>@<stepContextId> + */ + public static final String ATTR_HISTORY_ID = ATTR_PREFIX + ".history_id"; //$NON-NLS-1$ + + /** + * The data to persist to the history. + * If this attribute is not set, it is filled automatically with the given stepper data. + */ + public static final String ATTR_HISTORY_DATA = ATTR_PREFIX + ".history_data"; //$NON-NLS-1$ + + /** + * The number of entries in the history. + * If this attribute is not set, the history manager default is used. + */ + public static final String ATTR_HISTORY_COUNT = ATTR_PREFIX + ".history_count"; //$NON-NLS-1$ } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/job/StepperJob.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/job/StepperJob.java index 9f9abfa90..f3df21e69 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/job/StepperJob.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/job/StepperJob.java @@ -165,9 +165,6 @@ public final class StepperJob extends Job { Map<String,List<Job>> jobs = getJobs(stepContext.getContextObject()); addJob(jobs, this, operation); setJobs(jobs, stepContext.getContextObject()); - - data.setProperty(IStepAttributes.ATTR_STEPPER_JOB, this); - data.setProperty(IStepAttributes.ATTR_STEPPER_JOB_OPERATION, operation); } public static Map<String,List<Job>> getJobs(Object context) { diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/stepper/Stepper.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/stepper/Stepper.java index dd776cc7b..eb3e870d2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/stepper/Stepper.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/stepper/Stepper.java @@ -28,12 +28,15 @@ import org.eclipse.tcf.te.runtime.callback.Callback; 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; +import org.eclipse.tcf.te.runtime.persistence.history.HistoryManager; +import org.eclipse.tcf.te.runtime.persistence.utils.DataHelper; import org.eclipse.tcf.te.runtime.stepper.FullQualifiedId; import org.eclipse.tcf.te.runtime.stepper.StepperManager; import org.eclipse.tcf.te.runtime.stepper.activator.CoreBundleActivator; import org.eclipse.tcf.te.runtime.stepper.extensions.StepExecutor; import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStep; +import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepAttributes; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepExecutor; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepGroup; @@ -45,7 +48,7 @@ import org.eclipse.tcf.te.runtime.stepper.nls.Messages; import org.eclipse.tcf.te.runtime.utils.StatusHelper; /** - * An abstract stepper implementation. + * Stepper implementation. */ public class Stepper implements IStepper { @@ -169,6 +172,13 @@ public class Stepper implements IStepper { // but not finished yet this.finished = false; + if (!data.containsKey(IStepAttributes.ATTR_HISTORY_DATA)) { + data.setProperty(IStepAttributes.ATTR_HISTORY_DATA, DataHelper.encodePropertiesContainer(data)); + } + if (!data.containsKey(IStepAttributes.ATTR_HISTORY_ID)) { + data.setProperty(IStepAttributes.ATTR_HISTORY_ID, stepGroupId + "@" + context.getId()); //$NON-NLS-1$ + } + // call the hook for the subclasses to initialize themselves onInitialize(this.data, fullQualifiedId, this.monitor); @@ -343,6 +353,19 @@ public class Stepper implements IStepper { // Severe status objects are errors or cancellation. List<IStatus> statusContainer = new ArrayList<IStatus>(); + // save execution to history + String historyId = data.getStringProperty(IStepAttributes.ATTR_HISTORY_ID); + String historyData = data.getStringProperty(IStepAttributes.ATTR_HISTORY_DATA); + int historyCount = data.getIntProperty(IStepAttributes.ATTR_HISTORY_COUNT); + if (historyId != null && historyData != null) { + if (historyCount > 0) { + HistoryManager.getInstance().add(historyId, historyData, historyCount); + } + else { + HistoryManager.getInstance().add(historyId, historyData); + } + } + // start execution internalExecute(statusContainer); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/properties/PropertiesContainer.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/properties/PropertiesContainer.java index 377f45a1b..075ac7d9d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/properties/PropertiesContainer.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/properties/PropertiesContainer.java @@ -12,7 +12,6 @@ package org.eclipse.tcf.te.runtime.properties; import java.util.Collections; import java.util.EventObject; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; @@ -47,7 +46,7 @@ public class PropertiesContainer extends PlatformObject implements IPropertiesCo /** * The custom properties map. The keys are always strings, the value might be any object. */ - private Map<String, Object> properties = new LinkedHashMap<String, Object>(); + private Map<String, Object> properties = new HashMap<String, Object>(); /** * Constructor. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/IStepGroupIds.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/IStepGroupIds.java new file mode 100644 index 000000000..67901f948 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/IStepGroupIds.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2014 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.interfaces; + +/** + * IStepGroupIds + */ +public interface IStepGroupIds { + + public static final String CONNECT = "org.eclipse.tcf.te.tcf.locator.connectStepGroup"; //$NON-NLS-1$ + public static final String DISCONNECT = "org.eclipse.tcf.te.tcf.locator.disconnectStepGroup"; //$NON-NLS-1$ +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IStepperServiceOperations.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/IStepperServiceOperations.java index a91f6c2e6..b1bc5254d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IStepperServiceOperations.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/IStepperServiceOperations.java @@ -8,7 +8,7 @@ * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.tcf.locator.interfaces.services; +package org.eclipse.tcf.te.tcf.locator.interfaces; /** * IStepperServiceOperations diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerNode.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerNode.java index a938f2dfb..7ea2f6150 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerNode.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerNode.java @@ -30,11 +30,11 @@ import org.eclipse.tcf.te.runtime.services.interfaces.IService; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepperOperationService; import org.eclipse.tcf.te.runtime.stepper.utils.StepperHelper; import org.eclipse.tcf.te.runtime.utils.StatusHelper; +import org.eclipse.tcf.te.tcf.locator.interfaces.IStepperServiceOperations; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProvider; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IStepperServiceOperations; /** diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/StepperOperationService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/StepperOperationService.java index 9bde66f54..36de4937d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/StepperOperationService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/StepperOperationService.java @@ -12,8 +12,9 @@ package org.eclipse.tcf.te.tcf.locator.services; import org.eclipse.core.runtime.Assert; import org.eclipse.tcf.te.core.interfaces.IConnectable; +import org.eclipse.tcf.te.tcf.locator.interfaces.IStepGroupIds; +import org.eclipse.tcf.te.tcf.locator.interfaces.IStepperServiceOperations; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IStepperServiceOperations; /** * Connect/disconnect stepper operation service implementation. @@ -43,10 +44,10 @@ public class StepperOperationService extends org.eclipse.tcf.te.runtime.stepper. Assert.isTrue(context instanceof IPeerNode); if (IStepperServiceOperations.CONNECT.equals(operation)) { - return "org.eclipse.tcf.te.tcf.locator.connectStepGroup"; //$NON-NLS-1$ + return IStepGroupIds.CONNECT; } if (IStepperServiceOperations.DISCONNECT.equals(operation)) { - return "org.eclipse.tcf.te.tcf.locator.disconnectStepGroup"; //$NON-NLS-1$ + return IStepGroupIds.DISCONNECT; } return null; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/utils/PeerDataHelper.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/utils/PeerDataHelper.java new file mode 100644 index 000000000..0be97110b --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/utils/PeerDataHelper.java @@ -0,0 +1,66 @@ +/** + * PeerDataHelper.java + * Created on Aug 21, 2013 + * + * Copyright (c) 2013 Wind River Systems, Inc. + * + * The right to copy, distribute, modify, or otherwise make use + * of this software may be licensed only pursuant to the terms + * of an applicable Wind River license agreement. + */ +package org.eclipse.tcf.te.tcf.locator.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.te.runtime.persistence.PersistenceManager; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; + +/** + * Data helper for de/encoding . + */ +public class PeerDataHelper { + + /** + * Encode an array of peer nodes to a string. + * @param contexts The array of peer nodes. + * @return String representing the array of peer nodes. + */ + public static final String encodeContextList(IPeerNode[] contexts) { + try { + if (contexts != null && contexts.length > 0) { + IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(IPeer.class, String.class); + return (String)delegate.writeList(contexts, String.class); + } + } + catch (Exception e) { + } + return null; + } + + /** + * Decode a string encoded array of peer nodes. + * @param encoded The string encoded peer nodes. + * @return Array of peer nodes. + */ + public static final IPeerNode[] decodeContextList(String encoded) { + try { + if (encoded != null && encoded.trim().length() > 0) { + IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(IPeer.class, String.class); + Object[] input = delegate.readList(IPeerNode.class, encoded); + List<IPeerNode> peers = new ArrayList<IPeerNode>(); + for (Object object : input) { + if (object instanceof IPeerNode) { + peers.add((IPeerNode)object); + } + } + return peers.toArray(new IPeerNode[peers.size()]); + } + } + catch (Exception e) { + } + return new IPeerNode[0]; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/interfaces/IDefaultContextToolbarDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/interfaces/IDefaultContextToolbarDelegate.java index 71ef4cbee..4f13ac45b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/interfaces/IDefaultContextToolbarDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/interfaces/IDefaultContextToolbarDelegate.java @@ -20,8 +20,15 @@ public interface IDefaultContextToolbarDelegate { /** * Returns a list of new configuration wizard ids to show * in the context selector toolbar contribution. - * @param context - * @return + * @param context The selected default context. + * @return Array of ids. */ public String[] getToolbarNewConfigWizardIds(Object context); + + /** + * Returns a list if history ids that should be used to diaply the "recently used actions" in the toolbar actions sub menu. + * @param context The selected default context. + * @return Array of ids. + */ + public String[] getToolbarHistoryIds(Object context); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/AbstractNewConfigWizard.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/AbstractNewConfigWizard.java index c87286132..f82e84922 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/AbstractNewConfigWizard.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/AbstractNewConfigWizard.java @@ -22,10 +22,10 @@ import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepperOperationService; import org.eclipse.tcf.te.runtime.stepper.job.StepperJob; import org.eclipse.tcf.te.runtime.utils.StatusHelper; +import org.eclipse.tcf.te.tcf.locator.interfaces.IStepperServiceOperations; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IStepperServiceOperations; import org.eclipse.tcf.te.tcf.ui.activator.UIPlugin; import org.eclipse.tcf.te.ui.wizards.AbstractWizard; import org.eclipse.ui.INewWizard; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractStepperCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractStepperCommandHandler.java index cdddaad27..a174b9db6 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractStepperCommandHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractStepperCommandHandler.java @@ -61,7 +61,7 @@ public abstract class AbstractStepperCommandHandler extends AbstractCommandHandl return null; } - Object context = getContext(event, data); + Object context = getContext(data); IStepperOperationService stepperOperationService = getStepperService(context, operation); if (stepperOperationService != null) { @@ -71,16 +71,36 @@ public abstract class AbstractStepperCommandHandler extends AbstractCommandHandl boolean isCancelable = stepperOperationService.isCancelable(context, operation); if (stepGroupId != null && stepContext != null) { - scheduleStepperJob(stepContext, data, stepGroupId, name, isCancelable); + scheduleStepperJob(stepContext, cleanupData(data), stepGroupId, name, isCancelable); } } return null; } + /** + * Get the data from dialog or history. + * @param event + * @return + */ abstract protected IPropertiesContainer getData(ExecutionEvent event); - abstract protected Object getContext(ExecutionEvent event, IPropertiesContainer data); + /** + * Get the context from the data. + * @param data + * @return + */ + abstract protected Object getContext(IPropertiesContainer data); + + /** + * Cleanup the stepper data. + * I.e. remove temporary properties that are not needed for the stepper and should also not stored in the stepper history. + * @param data + * @return + */ + protected IPropertiesContainer cleanupData(IPropertiesContainer data) { + return data; + } /** * Get the stepper service for the given context and operation. |