Skip to content

Commit

Permalink
Bug 465453 - Create extension point to set ESOperationModifier
Browse files Browse the repository at this point in the history
Change-Id: I9990cfdd612393c01cbf6c7f3f79bedafb104d1e
  • Loading branch information
edgarmueller committed May 26, 2015
1 parent 807c31c commit 5eaa63f
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ This option is available on the server as well as on the client side.
</documentation>
</annotation>
</attribute>
<attribute name="operationModifier" type="string">
<annotation>
<documentation>

</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.eclipse.emf.emfstore.client.handler.ESOperationModifier"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@
public interface ESOperationModifier {

/**
* <p>
* ID of the {@link ESOperationModifier} option.
* </p>
*
* This option is not in use anymore and has been replaced by the change recording option
* {@code org.eclipse.emf.emfstore.client.changeRecordingOptions.operationModifier}.
*/
@Deprecated
String ID = "org.eclipse.emf.emfstore.client.handler.operationModifier"; //$NON-NLS-1$

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2012-2013 EclipseSource Muenchen GmbH 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
Expand All @@ -14,8 +14,10 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.emfstore.client.ESServer;
import org.eclipse.emf.emfstore.client.handler.ESChecksumErrorHandler;
import org.eclipse.emf.emfstore.client.handler.ESOperationModifier;
import org.eclipse.emf.emfstore.client.provider.ESClientConfigurationProvider;
import org.eclipse.emf.emfstore.common.extensionpoint.ESExtensionElement;
import org.eclipse.emf.emfstore.common.extensionpoint.ESExtensionPoint;
Expand All @@ -26,6 +28,7 @@
import org.eclipse.emf.emfstore.internal.client.model.connectionmanager.KeyStoreManager;
import org.eclipse.emf.emfstore.internal.client.model.impl.api.ESServerImpl;
import org.eclipse.emf.emfstore.internal.client.model.util.ChecksumErrorHandler;
import org.eclipse.emf.emfstore.internal.server.model.versioning.operations.AbstractOperation;

import com.google.common.base.Optional;

Expand All @@ -51,6 +54,7 @@ public class Behavior {
private static final String DENY_ADD_CUT_ELEMENTS_TO_MODELELEMENTS_FEATURE_EXTENSION_POINT_ATTRIBUTE_NAME = "denyAddCutElementsToModelElements"; //$NON-NLS-1$
private static final String USE_IN_MEMORY_CHANGE_PACKAGE = "useInMemoryChangePackage"; //$NON-NLS-1$
private static final String CHANGEPACKAGE_FRAGMENT_SIZE = "changePackageFragmentSize"; //$NON-NLS-1$
private static final String OPERATION_MODIFIER = "operationModifier"; //$NON-NLS-1$

private static Boolean isAutoSaveActive;
private static Boolean isRerecordingActive;
Expand All @@ -59,6 +63,7 @@ public class Behavior {
private static Boolean isDenyAddCutElementsToModelElementsFeatureActive;
private static Boolean isUseMemoryChangePackageActive;
private static Optional<Integer> changePackageFragmentSize;
private static ESOperationModifier operationModifier;

private ESChecksumErrorHandler checksumErrorHandler;

Expand Down Expand Up @@ -230,7 +235,7 @@ public boolean useInMemoryChangePackage() {
public Optional<Integer> getChangePackageFragmentSize() {
if (changePackageFragmentSize == null) {
final Integer fragmentSize = new ESExtensionPoint(RESOURCE_OPTIONS_EXTENSION_POINT_NAME)
.getInteger(CHANGEPACKAGE_FRAGMENT_SIZE);
.getInteger(CHANGEPACKAGE_FRAGMENT_SIZE);
if (fragmentSize == null) {
changePackageFragmentSize = Optional.absent();
} else {
Expand All @@ -241,6 +246,30 @@ public Optional<Integer> getChangePackageFragmentSize() {
return changePackageFragmentSize;
}

/**
* Returns the operation modifier.
*
* @return the operation modifier in use
*/
public ESOperationModifier getOperationModifier() {
if (operationModifier == null) {
final ESOperationModifier modifier = new ESExtensionPoint(RESOURCE_OPTIONS_EXTENSION_POINT_NAME)
.getClass(OPERATION_MODIFIER, ESOperationModifier.class);
if (modifier == null) {
operationModifier = new ESOperationModifier() {
// return operations unaltered
public List<AbstractOperation> modify(List<AbstractOperation> operations, Command command) {
return operations;
}
};
} else {
operationModifier = modifier;
}
}

return operationModifier;
}

/**
* Sets the fragment size to be used when splitting change packages.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,23 @@ public OperationManager(ProjectSpaceBase projectSpace) {
}

private void configureOperationRecorder() {
final OperationRecorderConfig config = operationRecorder.getConfig();

// incoming cross-references are cut off by default
operationRecorder.getConfig().setCutOffIncomingCrossReferences(
config.setCutOffIncomingCrossReferences(
Configuration.getClientBehavior().isCutOffIncomingCrossReferencesActivated());

// usage of commands is not forced by default
operationRecorder.getConfig()
config
.setForceCommands(
Configuration.getClientBehavior().isForceCommandsActived());

// cut elements are added automatically as regular model elements by default
operationRecorder.getConfig().setDenyAddCutElementsToModelElements(
config.setDenyAddCutElementsToModelElements(
Configuration.getClientBehavior().isDenyAddCutElementsToModelElementsFeatureActived());

config.setOperationModifier(
Configuration.getClientBehavior().getOperationModifier());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,10 @@ public void run() {
}

private List<AbstractOperation> modifyOperations(List<AbstractOperation> operations, Command command) {
if (config.getOperationModificator() == null) {
if (operations.isEmpty() || config.getOperationModifier() == null) {
return operations;
}
return config.getOperationModificator().modify(operations, command);
return config.getOperationModifier().modify(operations, command);
}

private void deleteOutgoingCrossReferencesOfContainmentTree(Set<EObject> allEObjects) {
Expand Down Expand Up @@ -565,10 +565,9 @@ private void deleteOutgoingCrossReferencesOfContainmentTree(Set<EObject> allEObj
// deleted
if (reference.isMany()) {
@SuppressWarnings("unchecked")
final Set<EObject> referencesToRemove =
filterAllNonContained(
(List<EObject>) modelElement.eGet(reference),
allEObjects);
final Set<EObject> referencesToRemove = filterAllNonContained(
(List<EObject>) modelElement.eGet(reference),
allEObjects);
if (referencesToRemove.size() > 0) {
settingsToUnset.add(
new SettingWithElementsToRemove(
Expand Down Expand Up @@ -596,8 +595,7 @@ private void unsetAll(final List<SettingWithElementsToRemove> settingsToUnset) {

if (feature.isMany()) {
@SuppressWarnings("unchecked")
final List<EObject> referencedElements =
(List<EObject>) setting.getEObject().eGet(feature);
final List<EObject> referencedElements = (List<EObject>) setting.getEObject().eGet(feature);
referencedElements.removeAll(referencesToRemove);
} else {
setting.getEObject().eSet(feature, null);
Expand Down Expand Up @@ -771,7 +769,8 @@ private List<ReferenceOperation> extractReferenceOperationsForDelete(EObject del
l.add(operation);
continue;
}
if (operation instanceof CompositeOperation && ((CompositeOperation) operation).getMainOperation() != null) {
if (operation instanceof CompositeOperation
&& ((CompositeOperation) operation).getMainOperation() != null) {
final CompositeOperation compositeOperation = (CompositeOperation) operation;
boolean doesNotBelongToDelete = false;
for (final AbstractOperation subOperation : compositeOperation.getSubOperations()) {
Expand Down Expand Up @@ -1005,7 +1004,8 @@ public ProjectSpace getProjectSpace() {
* @see org.eclipse.emf.emfstore.client.observer.ESUpdateObserver#inspectChanges(org.eclipse.emf.emfstore.client.ESLocalProject,
* java.util.List, org.eclipse.core.runtime.IProgressMonitor)
*/
public boolean inspectChanges(ESLocalProject project, List<ESChangePackage> changePackages, IProgressMonitor monitor) {
public boolean inspectChanges(ESLocalProject project, List<ESChangePackage> changePackages,
IProgressMonitor monitor) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
******************************************************************************/
package org.eclipse.emf.emfstore.internal.client.model.impl;

import java.util.List;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.emfstore.client.handler.ESOperationModifier;
import org.eclipse.emf.emfstore.internal.common.ExtensionRegistry;
import org.eclipse.emf.emfstore.internal.server.model.versioning.operations.AbstractOperation;

/**
* Encapsulates configuration options for the operation recorder.
Expand All @@ -30,6 +25,7 @@ public class OperationRecorderConfig {
private boolean isRollBackInCaseOfCommandFailure;
private boolean isForceCommands;
private boolean isEmitOperationsUponCommandCompletion = true;
private ESOperationModifier operationModifier;

/**
* Whether to cut off incoming cross references upon deletion.
Expand All @@ -55,7 +51,7 @@ public Boolean isDenyAddCutElementsToModelElements() {
* Whether the usage of commands should be enforced.
*
* @return
* true, if the usage of commands is mandatory, false otherwise
* true, if the usage of commands is mandatory, false otherwise
*/
public Boolean isForceCommands() {
return isForceCommands;
Expand Down Expand Up @@ -140,20 +136,21 @@ public void setEmitOperationsUponCommandCompletion(Boolean shouldEmitOperationsU
}

/**
* Returns the operation modificator.
* Set the operation modifier that enables to modify operations whenever they have been recored
*
* @param operationModifier
* the operation modifier to be set
*/
public void setOperationModifier(ESOperationModifier operationModifier) {
this.operationModifier = operationModifier;
}

/**
* Returns the operation modifier in use.
*
* @return the operation modificator in use
* @return the operation in use
*/
public ESOperationModifier getOperationModificator() {
return ExtensionRegistry.INSTANCE.get(
ESOperationModifier.ID,
ESOperationModifier.class,
new ESOperationModifier() {
// return operations unaltered
public List<AbstractOperation> modify(List<AbstractOperation> operations, Command command) {
return operations;
}
},
true);
public ESOperationModifier getOperationModifier() {
return operationModifier;
}
}

0 comments on commit 5eaa63f

Please sign in to comment.