Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2006-05-19 21:06:13 +0000
committerMichael Valenta2006-05-19 21:06:13 +0000
commitbd2b77aab35ea6312305ce43d8ce2c4067a68878 (patch)
treef3a3121b6b7fb1f127758e308d80a8ef71e1772b /examples
parent50414e5f30d00cd2c6864679e6679b116143545e (diff)
downloadeclipse.platform.team-bd2b77aab35ea6312305ce43d8ce2c4067a68878.tar.gz
eclipse.platform.team-bd2b77aab35ea6312305ce43d8ce2c4067a68878.tar.xz
eclipse.platform.team-bd2b77aab35ea6312305ce43d8ce2c4067a68878.zip
Working on model example
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectDefinitionFile.java10
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelMergeActionHandler.java121
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncActionProvider.java49
3 files changed, 134 insertions, 46 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectDefinitionFile.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectDefinitionFile.java
index 1b12e5e20..f416cc964 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectDefinitionFile.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectDefinitionFile.java
@@ -158,4 +158,14 @@ public class ModelObjectDefinitionFile extends ModelFile {
writeLines((String[]) paths.toArray(new String[paths.size()]));
}
+ public boolean hasMoe(IFile file) throws CoreException {
+ ModelObjectElementFile[] files = getModelObjectElementFiles();
+ for (int i = 0; i < files.length; i++) {
+ ModelObjectElementFile child = files[i];
+ if (child.getResource().equals(file))
+ return true;
+ }
+ return false;
+ }
+
}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelMergeActionHandler.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelMergeActionHandler.java
new file mode 100644
index 000000000..eb402e606
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelMergeActionHandler.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.examples.model.ui.mapping;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.*;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.team.core.diff.*;
+import org.eclipse.team.core.mapping.IMergeContext;
+import org.eclipse.team.examples.model.ModelObjectDefinitionFile;
+import org.eclipse.team.examples.model.ModelObjectElementFile;
+import org.eclipse.team.internal.ui.mapping.ResourceModelProviderOperation;
+import org.eclipse.team.ui.mapping.MergeActionHandler;
+import org.eclipse.team.ui.mapping.SynchronizationOperation;
+import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
+
+public class ModelMergeActionHandler extends MergeActionHandler {
+
+ /*
+ * Operation to merge model elements. We're using an internal superclass to save on copying
+ * code.
+ */
+ private final class ModelSynchronizeOperation extends ResourceModelProviderOperation {
+ public ModelSynchronizeOperation(ISynchronizePageConfiguration configuration, IStructuredSelection selection) {
+ super(configuration, selection);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.mapping.SynchronizationOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ // We need to perform special handling for any MOE file whose parent MOD is not included in the merge
+ try {
+ IMergeContext context = (IMergeContext)getContext();
+ IDiff[] diffs = getTargetDiffs();
+ ModelObjectElementFile[] moeMerges = getMoeOnlyMerges();
+ IStatus status = context.merge(diffs, overwrite, monitor);
+ if (!status.isOK())
+ throw new CoreException(status);
+ // For now, just cycle through each lonely MOE and update the parent
+ for (int i = 0; i < moeMerges.length; i++) {
+ ModelObjectElementFile file = moeMerges[i];
+ ModelObjectDefinitionFile modFile = (ModelObjectDefinitionFile)file.getParent();
+ if (file.getResource().exists() && !modFile.hasMoe((IFile)file.getResource()))
+ modFile.addMoe((IFile)file.getResource());
+ else
+ modFile.remove(file);
+ }
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ private ModelObjectElementFile[] getMoeOnlyMerges() {
+ List result = new ArrayList();
+ Object[] elements = getElements();
+ for (int i = 0; i < elements.length; i++) {
+ Object object = elements[i];
+ if (object instanceof ModelObjectElementFile) {
+ ModelObjectElementFile moeFile = (ModelObjectElementFile) object;
+ result.add(moeFile);
+ }
+ }
+ return (ModelObjectElementFile[]) result.toArray(new ModelObjectElementFile[result.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.mapping.ResourceModelProviderOperation#getDiffFilter()
+ */
+ protected FastDiffFilter getDiffFilter() {
+ return new FastDiffFilter() {
+ public boolean select(IDiff node) {
+ if (node instanceof IThreeWayDiff) {
+ IThreeWayDiff twd = (IThreeWayDiff) node;
+ if ((twd.getDirection() == IThreeWayDiff.OUTGOING && overwrite) || twd.getDirection() == IThreeWayDiff.CONFLICTING || twd.getDirection() == IThreeWayDiff.INCOMING) {
+ return true;
+ }
+ return false;
+ }
+ // Overwrite should always be available for two-way diffs
+ return overwrite;
+ }
+ };
+ }
+ }
+
+ final boolean overwrite;
+ private SynchronizationOperation operation;
+
+ public ModelMergeActionHandler(ISynchronizePageConfiguration configuration, boolean overwrite) {
+ super(configuration);
+ this.overwrite = overwrite;
+ }
+
+ protected SynchronizationOperation getOperation() {
+ if (operation == null) {
+ operation = new ModelSynchronizeOperation(getConfiguration(), getStructuredSelection());
+ }
+ return operation;
+ }
+
+ protected void updateEnablement(IStructuredSelection selection) {
+ synchronized (this) {
+ operation = null;
+ }
+ super.updateEnablement(selection);
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncActionProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncActionProvider.java
index 9a5c042f1..dd1345bf1 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncActionProvider.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncActionProvider.java
@@ -10,9 +10,6 @@
*******************************************************************************/
package org.eclipse.team.examples.model.ui.mapping;
-import org.eclipse.core.commands.*;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.team.ui.mapping.MergeActionHandler;
import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
@@ -20,46 +17,6 @@ import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
* The action provider that is used for synchronizations.
*/
public class ModelSyncActionProvider extends SynchronizationActionProvider {
-
- /** Delegate for merge action handlers */
- private final class ActionHandlerDelegate extends AbstractHandler {
-
- /** The delegate handler */
- private final IHandler fDelegateHandler;
-
- /**
- * Creates a new synchronization handler delegate.
- *
- * @param handler
- * the delegate handler
- */
- public ActionHandlerDelegate(final IHandler handler) {
- Assert.isNotNull(handler);
- fDelegateHandler= handler;
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- fDelegateHandler.dispose();
- super.dispose();
- }
-
- /**
- * {@inheritDoc}
- */
- public Object execute(final ExecutionEvent event) throws ExecutionException {
- return fDelegateHandler.execute(event);
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isEnabled() {
- return fDelegateHandler.isEnabled();
- }
- }
public ModelSyncActionProvider() {
super();
@@ -71,10 +28,10 @@ public class ModelSyncActionProvider extends SynchronizationActionProvider {
protected void initialize() {
super.initialize();
final ISynchronizePageConfiguration configuration= getSynchronizePageConfiguration();
- // TODO: We should provide custom handlers that ensure that the MOD files get updated properly
+ // We provide custom handlers that ensure that the MOD files get updated properly
// when MOE files are merged.
- registerHandler(MERGE_ACTION_ID, new ActionHandlerDelegate(MergeActionHandler.getDefaultHandler(MERGE_ACTION_ID, configuration)));
- registerHandler(OVERWRITE_ACTION_ID, new ActionHandlerDelegate(MergeActionHandler.getDefaultHandler(OVERWRITE_ACTION_ID, configuration)));
+ registerHandler(MERGE_ACTION_ID, new ModelMergeActionHandler(configuration, false));
+ registerHandler(OVERWRITE_ACTION_ID, new ModelMergeActionHandler(configuration, false));
// We can just use the default mark as merged handler
}
}

Back to the top