Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Noyrit2014-01-08 10:10:49 +0000
committerFlorian Noyrit2014-01-08 10:10:49 +0000
commitfa26cd6de836db49f40558f0d415358281139e56 (patch)
treec9ed40c013ea9a7c08b9a5fadec5a45d02f4529c /plugins
parent5c7398079addc9e27785bc913dec6bec1f9ae36a (diff)
downloadorg.eclipse.papyrus-fa26cd6de836db49f40558f0d415358281139e56.tar.gz
org.eclipse.papyrus-fa26cd6de836db49f40558f0d415358281139e56.tar.xz
org.eclipse.papyrus-fa26cd6de836db49f40558f0d415358281139e56.zip
Correct the replace action in search to not depend on the new
refactoring framework. The refactoring framework will be commited later.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/META-INF/MANIFEST.MF3
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java19
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceTransformationOnElement.java141
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceRefactoring.java151
4 files changed, 11 insertions, 303 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/META-INF/MANIFEST.MF b/plugins/uml/org.eclipse.papyrus.uml.search.ui/META-INF/MANIFEST.MF
index e8ffabe1ce2..07874c97887 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/META-INF/MANIFEST.MF
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/META-INF/MANIFEST.MF
@@ -22,8 +22,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ocl.examples.xtext.essentialocl;bundle-version="3.3.0",
org.eclipse.ocl.examples.xtext.essentialocl.ui;bundle-version="3.3.0",
org.eclipse.ocl.examples.xtext.console,
- org.eclipse.ltk.ui.refactoring;bundle-version="3.7.100",
- org.eclipse.papyrus.infra.refactoring;bundle-version="1.0.0"
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.7.100"
Export-Package: org.eclipse.papyrus.uml.search.ui.actions,
org.eclipse.papyrus.uml.search.ui.providers,
org.eclipse.papyrus.uml.search.ui.query,
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java
index acc8bd97fc8..47aa2a5c67e 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java
@@ -14,8 +14,7 @@
package org.eclipse.papyrus.uml.search.ui.actions;
import org.eclipse.jface.action.Action;
-import org.eclipse.papyrus.infra.refactoring.core.PapyrusRefactoringOperation;
-import org.eclipse.papyrus.uml.search.ui.dialogs.ReplaceRefactoring;
+import org.eclipse.papyrus.uml.search.ui.dialogs.ReplaceDialog;
import org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage;
import org.eclipse.swt.widgets.Shell;
@@ -25,18 +24,21 @@ public class ReplaceAction extends Action {
private final Object[] fSelection;
+ private final Shell fShell;
+
/**
* Creates the replace action to be
*
* @param shell
- * the parent shell
+ * the parent shell
* @param resultPage
- * .getInput()
- * the file search page to
+ * .getInput()
+ * the file search page to
* @param selection
- * the selected entries or <code>null</code> to replace all
+ * the selected entries or <code>null</code> to replace all
*/
public ReplaceAction(Shell shell, PapyrusSearchResultPage resultPage, Object[] selection) {
+ fShell = shell;
fResultPage = resultPage;
fSelection = selection;
}
@@ -49,10 +51,9 @@ public class ReplaceAction extends Action {
@Override
public void run() {
+ ReplaceDialog replaceDialog = new ReplaceDialog(fShell, fResultPage, fSelection);
+ replaceDialog.open();
- ReplaceRefactoring replaceRef = new ReplaceRefactoring(fResultPage, fSelection);
- PapyrusRefactoringOperation refactoringOperation = new PapyrusRefactoringOperation(replaceRef);
- refactoringOperation.run();
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceTransformationOnElement.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceTransformationOnElement.java
deleted file mode 100644
index c38b44f5a59..00000000000
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceTransformationOnElement.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.search.ui.actions;
-
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.papyrus.infra.refactoring.refactoringOnElement.ITransformationOnElement;
-import org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery;
-import org.eclipse.papyrus.views.search.regex.PatternHelper;
-import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
-import org.eclipse.papyrus.views.search.results.AttributeMatch;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-
-
-public class ReplaceTransformationOnElement implements ITransformationOnElement {
-
- /**
- * The {@link AbstractResultEntry} list representing textual matches with the String pattern to be replaced.
- */
- private Set<AbstractResultEntry> fAttributeMatchList;
-
- /**
- * The {@link AbstractPapyrusQuery} representing the search of matches.
- */
- private AbstractPapyrusQuery fQuery;
-
- /**
- * The string that should replace the String pattern to be replaced.
- */
- private String fNewString;
-
-
- public ReplaceTransformationOnElement(Set<AbstractResultEntry> toProcess, AbstractPapyrusQuery query, String newString) {
- fAttributeMatchList = toProcess;
- fQuery = query;
- fNewString = newString;
- }
-
-
- public void transformationToExecute(EObject element) {
- for(AbstractResultEntry match : fAttributeMatchList) {
- if(match.getSource() instanceof EObject && match instanceof AttributeMatch){
- AttributeMatch attributeMatch=(AttributeMatch) match;
- if(EcoreUtil.equals(element, (EObject)match.getSource())) {
-
- if(attributeMatch.getMetaAttribute() instanceof EAttribute) {
- Object value = element.eGet((EAttribute)attributeMatch.getMetaAttribute());
- if(value != null) {
- if(value instanceof String) {
- String originalvalue = (String)value;
- Pattern pattern = PatternHelper.getInstance().createPattern(fQuery.getSearchQueryText(), fQuery.isCaseSensitive(), fQuery.isRegularExpression());
-
- String newValue = computeReplacementString(pattern, originalvalue, fNewString);
-
- element.eSet((EAttribute)attributeMatch.getMetaAttribute(), newValue);
-
- }
- }
- }
-
- else if(attributeMatch.getMetaAttribute() instanceof Property) {
- Property source = (Property)attributeMatch.getMetaAttribute();
- Class containingClass = source.getClass_();
- if(containingClass instanceof Stereotype) {
- if(element instanceof Element) {
- Stereotype stereotype = ((Element)element).getAppliedStereotype(containingClass.getQualifiedName());
- Object tagValue = ((Element)element).getValue(stereotype, source.getName());
- if(tagValue instanceof String) {
- Object value = tagValue;
-
- if(value != null) {
- if(value instanceof String) {
- String originalvalue = (String)value;
- Pattern pattern = PatternHelper.getInstance().createPattern(fQuery.getSearchQueryText(), fQuery.isCaseSensitive(), fQuery.isRegularExpression());
-
- String newValue = computeReplacementString(pattern, originalvalue, fNewString);
-
- ((Element)element).setValue(stereotype, source.getName(), newValue);
-
- }
- }
-
- }
- }
- }
- }
- }
- }
- }
- }
-
-
- /**
- * Compute the replacement.
- * @param pattern The pattern that we will us to compute the replacement.
- * @param originalText The String to be modified.
- * @param replacementText The String to append.
- * @return The new String.
- */
- private String computeReplacementString(Pattern pattern, String originalText, String replacementText) throws PatternSyntaxException {
- if(pattern != null) {
- try {
-
- Matcher matcher = pattern.matcher(originalText);
- StringBuffer sb = new StringBuffer();
- matcher.reset();
- if(matcher.find()) {
- matcher.appendReplacement(sb, replacementText);
- } else {
- return null;
- }
- matcher.appendTail(sb);
- return sb.toString();
- } catch (IndexOutOfBoundsException ex) {
- throw new PatternSyntaxException(ex.getLocalizedMessage(), replacementText, -1);
- }
- }
- return replacementText;
- }
-
-}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceRefactoring.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceRefactoring.java
deleted file mode 100644
index 51a8d4f79b6..00000000000
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceRefactoring.java
+++ /dev/null
@@ -1,151 +0,0 @@
-package org.eclipse.papyrus.uml.search.ui.dialogs;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.papyrus.infra.refactoring.refactoringOnElement.AbstractTransformationOnElement;
-import org.eclipse.papyrus.infra.refactoring.refactoringOnElement.ITransformationOnElement;
-import org.eclipse.papyrus.uml.search.ui.Messages;
-import org.eclipse.papyrus.uml.search.ui.actions.ReplaceTransformationOnElement;
-import org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage;
-import org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery;
-import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
-import org.eclipse.papyrus.views.search.results.AttributeMatch;
-import org.eclipse.papyrus.views.search.utils.MatchUtils;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-
-
-public class ReplaceRefactoring extends AbstractTransformationOnElement {
-
- private Text fNewValueText;
-
- private Text fOldValueText;
-
- private PapyrusSearchResultPage fResultPage;
-
- private AbstractPapyrusQuery fQuery;
-
- private Object[] fSelection;
-
- private Set<AbstractResultEntry> fListMatch;
-
-
-
- public ReplaceRefactoring(PapyrusSearchResultPage resultPage, Object[] selection) {
- super(Messages.ReplaceRefactoring_0);
- fResultPage = resultPage;
- fSelection = selection;
- fQuery = (AbstractPapyrusQuery)fResultPage.getInput().getQuery();
- initListMatches();
-
-
- }
-
-
- private Text createNameField(Composite result) {
- Text field = new Text(result, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
- field.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- return field;
- }
-
-
-
- @Override
- public RefactoringStatus checkFinalConditions() {
- RefactoringStatus status = new RefactoringStatus();
- if(fNewValueText.getText().isEmpty()) {
- status.merge(RefactoringStatus.createFatalErrorStatus(Messages.ReplaceRefactoring_1));
- } else if(fNewValueText.getText().equals(fQuery.getSearchQueryText())) {
- status.merge(RefactoringStatus.createFatalErrorStatus(Messages.ReplaceRefactoring_2));
-
- }
- return status;
- }
-
- @Override
- public void createControl(Composite parent) {
-
-
- GridLayout layout = new GridLayout();
-
-
- Composite composite = new Composite(parent, SWT.NONE);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- layout.numColumns = 2;
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
-
- setControl(composite);
-
- Label label = new Label(composite, SWT.NONE);
- label.setText(Messages.ReplaceRefactoring_3);
- fOldValueText = createNameField(composite);
- fOldValueText.setFocus();
- fOldValueText.setText(fQuery.getSearchQueryText());
- fOldValueText.setEnabled(false);
-
-
- label = new Label(composite, SWT.NONE);
- label.setText(Messages.ReplaceRefactoring_4);
-
- fNewValueText = createNameField(composite);
-
- GridData data = new GridData();
- data.horizontalAlignment = SWT.END;
-
- }
-
-
-
- private void initListMatches() {
- fListMatch = new HashSet<AbstractResultEntry>();
- if(fSelection == null) {
- for(AbstractResultEntry resultEntry : MatchUtils.getMatches(fResultPage.getInput(), false)) {
- if(resultEntry instanceof AttributeMatch) {
- fListMatch.add((AttributeMatch)resultEntry);
- }
- }
- } else {
- for(Object selected : Arrays.asList(fSelection)) {
- if(selected instanceof AttributeMatch) {
- fListMatch.add((AttributeMatch)selected);
- }
- }
-
- }
-
- }
-
- @Override
- public Collection<EObject> getElementsListToTransform() {
- List<EObject> toProcess = new ArrayList<EObject>();
- for(AbstractResultEntry match : fListMatch) {
- if(match.getSource() instanceof EObject) {
- if(!toProcess.contains(match.getSource())) {
- toProcess.add((EObject)match.getSource());
- }
-
- }
- }
- return toProcess;
- }
-
- @Override
- public ITransformationOnElement getTransformationOnElement() {
-
- return new ReplaceTransformationOnElement(fListMatch, fQuery, fNewValueText.getText());
-
- }
-}

Back to the top