diff options
author | Shuai Li | 2015-02-27 12:32:47 +0000 |
---|---|---|
committer | Shuai Li | 2015-03-11 17:07:16 +0000 |
commit | 1abca4be4770c6675e48ae7e8e7e9f35908f86e8 (patch) | |
tree | eb7d006621e25e6ad9752c2e2daedd7f3cb5545b | |
parent | 9173f56602ecbc75928f3ea01fc5c9d3289109f0 (diff) | |
download | org.eclipse.papyrus-1abca4be4770c6675e48ae7e8e7e9f35908f86e8.tar.gz org.eclipse.papyrus-1abca4be4770c6675e48ae7e8e7e9f35908f86e8.tar.xz org.eclipse.papyrus-1abca4be4770c6675e48ae7e8e7e9f35908f86e8.zip |
Bug 461822 - [Search] Results display performance and monitoring
Bug 432834 - [Performances - Search] The search operation loads models
into the active ModelSet
- Added progress monitor
- Delay search results refresh to avoid UI getting stuck
- Also fixes modelset bug
Change-Id: I8fa0244225c4cb4f11209a6b2cf14bcf52585242
Signed-off-by: Shuai Li <shuai.li@cea.fr>
10 files changed, 1105 insertions, 747 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java index e87fea2f84f..f59da1ce8da 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java @@ -75,6 +75,7 @@ import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeContentProvide import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeElement; import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeLabelProvider; import org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery; +import org.eclipse.papyrus.uml.search.ui.query.CompositePapyrusQuery; import org.eclipse.papyrus.uml.search.ui.query.CompositePapyrusQueryProvider; import org.eclipse.papyrus.uml.search.ui.query.PapyrusOCLQuery; import org.eclipse.papyrus.uml.search.ui.query.QueryInfo; @@ -1067,14 +1068,27 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla if (queryKind.getSelectionIndex() == TEXT_QUERY_KIND) { if (validateRegex()) { Collection<URI> scope = ScopeCollector.getInstance().computeSearchScope(container); - ISearchQuery query; + AbstractPapyrusQuery compositeQuery; if (searchKind.getSelectionIndex() == SIMPLE_SEARCH) { if (searchQueryText.getText().length() == 0) { MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_29, Messages.PapyrusSearchPage_30); return false; } else { - QueryInfo info = new QueryInfo(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), btnSearchAllStringAttributes.getSelection(), scope); - query = CompositePapyrusQueryProvider.getInstance().createSimpleSearchQuery(info); + // One query per di file to avoid one single slow query on many files + ArrayList<AbstractPapyrusQuery> queries = new ArrayList<AbstractPapyrusQuery>(scope.size()); + boolean delay = scope.size() > 1 ? false : true; + + for (URI uri : scope) { + Collection<URI> singleScope = new HashSet<URI>(); + singleScope.add(uri); + + QueryInfo info = new QueryInfo(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), btnSearchAllStringAttributes.getSelection(), singleScope, delay); + ISearchQuery query = CompositePapyrusQueryProvider.getInstance().createSimpleSearchQuery(info); + + queries.add((AbstractPapyrusQuery) query); + } + + compositeQuery = CompositePapyrusQuery.compose(queries); } } else { @@ -1113,13 +1127,26 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_31, Messages.PapyrusSearchPage_32); return false; } else { - QueryInfo info = new QueryInfo(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), participantsToEvaluate, scope, fBtnSearchForAllSelected.getSelection(), fBtnSearchForAnySelected.getSelection()); - query = CompositePapyrusQueryProvider.getInstance().createAdvancedSearchQuery(info); + // One query per di file to avoid one single slow query on many files + ArrayList<AbstractPapyrusQuery> queries = new ArrayList<AbstractPapyrusQuery>(scope.size()); + boolean delay = scope.size() > 1 ? false : true; + + for (URI uri : scope) { + Collection<URI> singleScope = new HashSet<URI>(); + singleScope.add(uri); + + QueryInfo info = new QueryInfo(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), participantsToEvaluate, singleScope, fBtnSearchForAllSelected.getSelection(), fBtnSearchForAnySelected.getSelection(), delay); + ISearchQuery query = CompositePapyrusQueryProvider.getInstance().createAdvancedSearchQuery(info); + + queries.add((AbstractPapyrusQuery) query); + } + + compositeQuery = CompositePapyrusQuery.compose(queries); } } - if (query.canRunInBackground()) { - NewSearchUI.runQueryInBackground(query); + if (compositeQuery.canRunInBackground()) { + NewSearchUI.runQueryInBackground(compositeQuery); } return true; diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchResultPage.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchResultPage.java index 79a9a260763..050b252a676 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchResultPage.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchResultPage.java @@ -1,209 +1,207 @@ -/*****************************************************************************
- * 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.pages;
-
-import java.util.Set;
-
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.OpenEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
-import org.eclipse.papyrus.uml.search.ui.Activator;
-import org.eclipse.papyrus.uml.search.ui.Messages;
-import org.eclipse.papyrus.uml.search.ui.actions.FilterTypesAction;
-import org.eclipse.papyrus.uml.search.ui.providers.ResultContentProvider;
-import org.eclipse.papyrus.uml.search.ui.providers.ResultLabelProvider;
-import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
-import org.eclipse.papyrus.views.search.scope.ScopeEntry;
-import org.eclipse.papyrus.views.search.utils.MatchUtils;
-import org.eclipse.search.ui.IContextMenuConstants;
-import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
-import org.eclipse.search.ui.text.Match;
-import org.eclipse.search2.internal.ui.SearchView;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PartInitException;
-
-/**
- *
- * Papyrus specific search results page
- *
- */
-public class PapyrusSearchResultPage extends AbstractTextSearchViewPage implements IResourceChangeListener {
-
- ResultContentProvider fContentProvider = null;
-
- private IAction fFiltertypesAction = null;
-
- private static final int DEFAULT_ELEMENT_LIMIT = 1000;
-
- public PapyrusSearchResultPage() {
-
- super(FLAG_LAYOUT_TREE);
- setElementLimit(new Integer(DEFAULT_ELEMENT_LIMIT));
- fFiltertypesAction = new FilterTypesAction(this);
-
- ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
- }
-
-
-
- @Override
- public Match[] getDisplayedMatches(Object element) {
-
- Set<AbstractResultEntry> results = MatchUtils.getMatches(this.getInput(), true);
-
- if (element instanceof AbstractResultEntry) {
- AbstractResultEntry resultEntry = (AbstractResultEntry) element;
-
- if (results.contains(resultEntry)) {
-
- return new Match[] { resultEntry };
-
- }
- return new Match[0];
- } else {
- return super.getDisplayedMatches(element);
- }
- }
-
- @Override
- public int getDisplayedMatchCount(Object element) {
-
- if (element instanceof AbstractResultEntry) {
- AbstractResultEntry resultEntry = (AbstractResultEntry) element;
-
- Set<AbstractResultEntry> results = MatchUtils.getMatches(this.getInput(), true);
- if (results.contains(resultEntry)) {
- return 1;
- }
-
- return 0;
- } else {
- return super.getDisplayedMatchCount(element);
- }
- }
-
- @Override
- protected void fillToolbar(IToolBarManager tbm) {
- super.fillToolbar(tbm);
- tbm.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, fFiltertypesAction);
- }
-
- @Override
- protected void handleOpen(OpenEvent event) {
-
- ISelection selection = event.getSelection();
- if (!selection.isEmpty()) {
- if (selection instanceof IStructuredSelection) {
- Object firstElement = ((IStructuredSelection) selection).getFirstElement();
-
- if (firstElement instanceof AbstractResultEntry) {
- AbstractResultEntry resultEntry = (AbstractResultEntry) firstElement;
- ScopeEntry scopeEntry = (ScopeEntry) resultEntry.getElement();
- if (scopeEntry != null && scopeEntry.getServicesRegistry() != null) {
- try {
- OpenElementService service = scopeEntry.getServicesRegistry().getService(OpenElementService.class);
- resultEntry.openElement(service);
- } catch (ServiceException e) {
- // Activator.log.error(Messages.PapyrusSearchResultPage_0 + resultEntry.elementToOpen(), e);
- } catch (PartInitException e) {
- Activator.log.error(Messages.PapyrusSearchResultPage_1, e);
- }
- }
-
- }
-
- }
-
- }
-
- // super.handleOpen(event);
- }
-
- @Override
- protected void elementsChanged(Object[] objects) {
- if (fContentProvider != null) {
- fContentProvider.elementsChanged(objects);
- }
- }
-
-
- @SuppressWarnings("unchecked")
- @Override
- protected void evaluateChangedElements(Match[] matches, @SuppressWarnings("rawtypes") Set changedElements) {
- for (int i = 0; i < matches.length; i++) {
- changedElements.add(matches[i]);
- }
-
- }
-
- @Override
- protected void clear() {
- if (fContentProvider != null) {
- fContentProvider.clear();
- }
- }
-
- @Override
- protected void configureTreeViewer(TreeViewer viewer) {
- viewer.setContentProvider(new ResultContentProvider(this, viewer));
- viewer.setLabelProvider(new ResultLabelProvider());
- fContentProvider = (ResultContentProvider) viewer.getContentProvider();
-
- }
-
- @Override
- protected void configureTableViewer(TableViewer viewer) {
-
- }
-
- public void resourceChanged(IResourceChangeEvent event) {
-
- if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
-
- if (this.getInput() != null && this.getViewer().getInput() != null && this.getViewPart() != null) {
-
-
-
- Display.getDefault().asyncExec(new Runnable() {
-
- public void run() {
- ((SearchView) getViewPart()).showSearchResult(getInput());
- getViewer().refresh();
- }
- });
- }
- }
-
-
-
-
-
- }
-
- @Override
- public void dispose() {
-
- super.dispose();
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
- }
-}
+/***************************************************************************** + * 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.pages; + +import java.util.Set; + +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.OpenEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService; +import org.eclipse.papyrus.uml.search.ui.Activator; +import org.eclipse.papyrus.uml.search.ui.Messages; +import org.eclipse.papyrus.uml.search.ui.actions.FilterTypesAction; +import org.eclipse.papyrus.uml.search.ui.providers.ResultContentProvider; +import org.eclipse.papyrus.uml.search.ui.providers.ResultLabelProvider; +import org.eclipse.papyrus.views.search.results.AbstractResultEntry; +import org.eclipse.papyrus.views.search.scope.ScopeEntry; +import org.eclipse.papyrus.views.search.utils.MatchUtils; +import org.eclipse.search.ui.IContextMenuConstants; +import org.eclipse.search.ui.text.AbstractTextSearchViewPage; +import org.eclipse.search.ui.text.Match; +import org.eclipse.search2.internal.ui.SearchView; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PartInitException; + +/** + * + * Papyrus specific search results page + * + */ +public class PapyrusSearchResultPage extends AbstractTextSearchViewPage implements IResourceChangeListener { + + ResultContentProvider fContentProvider = null; + + private IAction fFiltertypesAction = null; + + private static final int DEFAULT_ELEMENT_LIMIT = 1000; + + public PapyrusSearchResultPage() { + + super(FLAG_LAYOUT_TREE); + setElementLimit(new Integer(DEFAULT_ELEMENT_LIMIT)); + fFiltertypesAction = new FilterTypesAction(this); + + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + } + + + + @Override + public Match[] getDisplayedMatches(Object element) { + + Set<AbstractResultEntry> results = MatchUtils.getMatches(this.getInput(), true); + + if (element instanceof AbstractResultEntry) { + AbstractResultEntry resultEntry = (AbstractResultEntry) element; + + if (results.contains(resultEntry)) { + + return new Match[] { resultEntry }; + + } + return new Match[0]; + } else { + return super.getDisplayedMatches(element); + } + } + + @Override + public int getDisplayedMatchCount(Object element) { + + if (element instanceof AbstractResultEntry) { + AbstractResultEntry resultEntry = (AbstractResultEntry) element; + + Set<AbstractResultEntry> results = MatchUtils.getMatches(this.getInput(), true); + if (results.contains(resultEntry)) { + return 1; + } + + return 0; + } else { + return super.getDisplayedMatchCount(element); + } + } + + @Override + protected void fillToolbar(IToolBarManager tbm) { + super.fillToolbar(tbm); + tbm.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, fFiltertypesAction); + } + + @Override + protected void handleOpen(OpenEvent event) { + ISelection selection = event.getSelection(); + if (!selection.isEmpty()) { + if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + + if (firstElement instanceof AbstractResultEntry) { + AbstractResultEntry resultEntry = (AbstractResultEntry) firstElement; + ScopeEntry scopeEntry = (ScopeEntry) resultEntry.getElement(); + if (scopeEntry != null && scopeEntry.getServicesRegistry() != null) { + try { + OpenElementService service = scopeEntry.getServicesRegistry().getService(OpenElementService.class); + resultEntry.openElement(service); + } catch (ServiceException e) { + // Activator.log.error(Messages.PapyrusSearchResultPage_0 + resultEntry.elementToOpen(), e); + } catch (PartInitException e) { + Activator.log.error(Messages.PapyrusSearchResultPage_1, e); + } + } + + } + + } + + } + + // super.handleOpen(event); + } + + @Override + protected void elementsChanged(Object[] objects) { + if (fContentProvider != null) { + fContentProvider.elementsChanged(objects); + } + } + + + @SuppressWarnings("unchecked") + @Override + protected void evaluateChangedElements(Match[] matches, @SuppressWarnings("rawtypes") Set changedElements) { + for (int i = 0; i < matches.length; i++) { + changedElements.add(matches[i]); + } + } + + @Override + protected void clear() { + if (fContentProvider != null) { + fContentProvider.clear(); + } + } + + @Override + protected void configureTreeViewer(TreeViewer viewer) { + viewer.setContentProvider(new ResultContentProvider(this, viewer)); + viewer.setLabelProvider(new ResultLabelProvider()); + fContentProvider = (ResultContentProvider) viewer.getContentProvider(); + + } + + @Override + protected void configureTableViewer(TableViewer viewer) { + + } + + public void resourceChanged(IResourceChangeEvent event) { + + if (event.getType() == IResourceChangeEvent.POST_CHANGE) { + + if (this.getInput() != null && this.getViewer().getInput() != null && this.getViewPart() != null) { + + + + Display.getDefault().asyncExec(new Runnable() { + + public void run() { + ((SearchView) getViewPart()).showSearchResult(getInput()); + getViewer().refresh(); + } + }); + } + } + + + + + + } + + @Override + public void dispose() { + + super.dispose(); + ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + } +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/AbstractPapyrusQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/AbstractPapyrusQuery.java index 915f99eeda9..d1c6e4a1f22 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/AbstractPapyrusQuery.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/AbstractPapyrusQuery.java @@ -1,85 +1,101 @@ -/*****************************************************************************
- * Copyright (c) 2013 CEA LIST 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:
- * CEA LIST - Initial API and implementation
- * Christian W. Damus (CEA LIST) - Fix leaking of all UML models in search results
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.search.ui.query;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult;
-import org.eclipse.search.ui.ISearchQuery;
-
-/**
- *
- * Papyrus specific search query
- *
- */
-public abstract class AbstractPapyrusQuery implements ISearchQuery {
-
- /**
- * Getter for the text query
- *
- * @return the the query text
- */
- public abstract String getSearchQueryText();
-
- public boolean isCaseSensitive() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isRegularExpression() {
- // TODO Auto-generated method stub
- return false;
- }
-
- //
- // Nested types
- //
-
- public static final class Empty extends AbstractPapyrusQuery {
- public static final Empty INSTANCE = new Empty();
-
- private Empty() {
- super();
- }
-
- public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
- return Status.OK_STATUS;
- }
-
- public String getLabel() {
- return "Empty Papyrus Search";
- }
-
- public boolean canRerun() {
- return true;
- }
-
- public boolean canRunInBackground() {
- return true;
- }
-
- public PapyrusSearchResult getSearchResult() {
- return new PapyrusSearchResult(this);
- }
-
- @Override
- public String getSearchQueryText() {
- return "";
- }
-
- }
-}
+/***************************************************************************** + * Copyright (c) 2013 CEA LIST 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: + * CEA LIST - Initial API and implementation + * Christian W. Damus (CEA LIST) - Fix leaking of all UML models in search results + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.search.ui.query; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult; +import org.eclipse.search.ui.ISearchQuery; + +/** + * + * Papyrus specific search query + * + */ +public abstract class AbstractPapyrusQuery implements ISearchQuery { + + /** + * Sleep SLEEP_MILLISECONDS every NUMBER_ADDS_BEFORE_SLEEP of adds (events fired to update UI) + * so UI does not get stuck + */ + public static final int NUMBER_ADDS_BEFORE_SLEEP = 100; + public static final int SLEEP_MILLISECONDS = 500; + + /** + * Display results every BUFFER_SIZE + */ + public static final int BUFFER_SIZE = 100; + + protected boolean delay = false; + + protected SubMonitor progressMonitor; + + /** + * Getter for the text query + * + * @return the the query text + */ + public abstract String getSearchQueryText(); + + public boolean isCaseSensitive() { + // TODO Auto-generated method stub + return false; + } + + public boolean isRegularExpression() { + // TODO Auto-generated method stub + return false; + } + + // + // Nested types + // + + public static final class Empty extends AbstractPapyrusQuery { + public static final Empty INSTANCE = new Empty(); + + private Empty() { + super(); + } + + public IStatus run(IProgressMonitor monitor) throws OperationCanceledException { + return Status.OK_STATUS; + } + + public String getLabel() { + return "Empty Papyrus Search"; + } + + public boolean canRerun() { + return true; + } + + public boolean canRunInBackground() { + return true; + } + + public PapyrusSearchResult getSearchResult() { + return new PapyrusSearchResult(this); + } + + @Override + public String getSearchQueryText() { + return ""; + } + } +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/CompositePapyrusQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/CompositePapyrusQuery.java index d798a055d59..f6ef5ab0131 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/CompositePapyrusQuery.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/CompositePapyrusQuery.java @@ -106,15 +106,16 @@ public class CompositePapyrusQuery extends AbstractPapyrusQuery { public IStatus run(IProgressMonitor monitor) throws OperationCanceledException { List<IStatus> result = new java.util.ArrayList<IStatus>(queries.size()); + SubMonitor sub = SubMonitor.convert(monitor, queries.size()); + sub.beginTask("Searching in Models", queries.size()); + searchResult.clear(); - - SubMonitor sub = SubMonitor.convert(monitor, result.size()); for (AbstractPapyrusQuery next : queries) { IStatus status = next.run(sub.newChild(1)); if (!status.isOK()) { result.add(status); } - + searchResult.addSearchResult((AbstractTextSearchResult) next.getSearchResult()); } @@ -149,7 +150,25 @@ public class CompositePapyrusQuery extends AbstractPapyrusQuery { for (int i = 0; i < elements.length; i++) { Match[] matches = searchResult.getMatches(elements[i]); searchResults.putAll(searchResult, Arrays.asList(matches)); - addMatches(matches); // I need them, too + + int adds = 0; + for (Match match : matches) { + addMatch(match); + + /** Every 100 events fired (prompting 100 results display operation), + * sleep 100ms so the UI doesn't get stuck + */ + adds++; + if (adds >= NUMBER_ADDS_BEFORE_SLEEP) { + adds = 0; + try { + Thread.sleep(SLEEP_MILLISECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + //addMatches(matches); // I need them, too } if (!searchResults.containsKey(searchResult)) { diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java index 1ce83929836..6ab604a539c 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java @@ -27,6 +27,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubMonitor; import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EAttribute; @@ -97,8 +98,12 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { private HashMap<EObject, List<EAttribute>> participantsList; protected Set<AbstractResultEntry> fResults = null; - - + + /* + * Buffer contains matches to manually display. + * The buffer should be cleared after the display operation. + */ + //protected Set<AbstractResultEntry> buffer = null; private HashMap<Stereotype, ArrayList<Property>> stereotypeList; @@ -110,11 +115,53 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { private boolean searchForAnySter; + public PapyrusAdvancedQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, Collection<ScopeEntry> scopeEntries, Object[] participantsChecked, boolean searchForAllSter, boolean searchForAnySter) { + this.propertyList = new ArrayList<Property>(); + this.sources = new HashSet<Object>(); + this.searchQueryText = searchQueryText; + this.isCaseSensitive = isCaseSensitive; + this.isRegularExpression = isRegularExpression; + this.scopeEntries = scopeEntries; + this.participantsChecked = participantsChecked; + this.searchForAllSter = searchForAllSter; + this.searchForAnySter = searchForAnySter; + results = new PapyrusSearchResult(this); + participantsList = new HashMap<EObject, List<EAttribute>>(); + stereotypeList = new HashMap<Stereotype, ArrayList<Property>>(); + for (Object participant : this.participantsChecked) { + if (participant instanceof ParticipantTypeElement) { + if (((ParticipantTypeElement) participant).getElement() instanceof ENamedElement) { + List<EAttribute> attributesChecked = new ArrayList<EAttribute>(); + for (Object attributesFound : this.participantsChecked) { + if (attributesFound instanceof ParticipantTypeAttribute) { + if (((ParticipantTypeAttribute) attributesFound).getParent() == participant) { + attributesChecked.add((EAttribute) ((ParticipantTypeAttribute) attributesFound).getElement()); + } + } + } + participantsList.put(((ParticipantTypeElement) participant).getElement(), attributesChecked); + } else if (((ParticipantTypeElement) participant).getElement() instanceof Stereotype) { + ArrayList<Property> attributesChecked = new ArrayList<Property>(); + for (Object attributesFound : this.participantsChecked) { + if (attributesFound instanceof ParticipantTypeAttribute) { + if (((ParticipantTypeAttribute) attributesFound).getParent() == participant) { + attributesChecked.add((Property) ((ParticipantTypeAttribute) attributesFound).getElement()); + } + } + } + stereotypeList.put((Stereotype) ((ParticipantTypeElement) participant).getElement(), attributesChecked); + } + } + } - public PapyrusAdvancedQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, Collection<ScopeEntry> scopeEntries, Object[] participantsChecked, boolean searchForAllSter, boolean searchForAnySter) { + fResults = new HashSet<AbstractResultEntry>(); + //buffer = new HashSet<AbstractResultEntry>(BUFFER_SIZE); + } + + public PapyrusAdvancedQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, Collection<ScopeEntry> scopeEntries, Object[] participantsChecked, boolean searchForAllSter, boolean searchForAnySter, boolean delay) { this.propertyList = new ArrayList<Property>(); this.sources = new HashSet<Object>(); this.searchQueryText = searchQueryText; @@ -124,6 +171,7 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { this.participantsChecked = participantsChecked; this.searchForAllSter = searchForAllSter; this.searchForAnySter = searchForAnySter; + this.delay = delay; results = new PapyrusSearchResult(this); participantsList = new HashMap<EObject, List<EAttribute>>(); @@ -157,9 +205,13 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { } fResults = new HashSet<AbstractResultEntry>(); + //buffer = new HashSet<AbstractResultEntry>(BUFFER_SIZE); } public IStatus run(IProgressMonitor monitor) throws OperationCanceledException { + progressMonitor = SubMonitor.convert(monitor, scopeEntries.size() * 4); + progressMonitor.subTask("Searching"); + results.removeAll(); fResults.clear(); @@ -171,8 +223,13 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { EObject root = umlModel.lookupRoot(); Collection<EObject> participants = ParticipantValidator.getInstance().getParticipants(root, participantsList.keySet().toArray()); + + progressMonitor.worked(1); + Collection<EObject> stereotypedParticipants = ParticipantValidator.getInstance().getParticipantsStereotype(root, stereotypeList.keySet().toArray()); + progressMonitor.worked(1); + if (searchForAllSter) { if (participantsList.keySet().size() == 0) { stereotypedParticipants = getElementsWithAllSter(stereotypedParticipants); @@ -205,13 +262,15 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { evaluate(participants, scopeEntry); evaluateStereotypes(stereotypedParticipants, scopeEntry); } + + progressMonitor.worked(1); } } catch (NotFoundException e) { Activator.log.error(Messages.PapyrusQuery_0 + scopeEntry.getModelSet(), e); } } - monitor.done(); + //progressMonitor.done(); return Status.OK_STATUS; } @@ -289,16 +348,21 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { if (m.matches()) { int offset = m.start(); int length = m.end() - m.start(); + ModelMatch match = new AttributeMatch(offset, length, participant, scopeEntry, attribute, stereotype); fResults.add(match); + //addToBuffer(match); } } else { while (m.find()) { int offset = m.start(); int length = m.end() - m.start(); + AttributeMatch match = new AttributeMatch(offset, length, participant, scopeEntry, attribute, stereotype); + fResults.add(match); + //addToBuffer(match); } } @@ -308,6 +372,7 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { // ModelMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute); // // fResults.add(match); + // //addToBuffer(match); // } } @@ -320,11 +385,11 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { protected void evaluate(Collection<EObject> participants, ScopeEntry scopeEntry) { - for (EObject participant : participants) { if (searchQueryText.equals("")) { //$NON-NLS-1$ fResults.add(new ModelElementMatch(participant, scopeEntry)); + //addToBuffer(new ModelElementMatch(participant, scopeEntry)); } else { String query = searchQueryText; if (searchQueryText.equals("")) { //$NON-NLS-1$ @@ -368,7 +433,7 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { if (searchQueryText.equals("")) { //$NON-NLS-1$ fResults.add(new ModelElementMatch(participant, scopeEntry)); - + //addToBuffer(new ModelElementMatch(participant, scopeEntry)); } else { String query = searchQueryText; if (searchQueryText.equals("")) { //$NON-NLS-1$ @@ -485,6 +550,7 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { Object semanticElement = viewersMappings.get(containingModelSet).get(view); ViewerMatch viewMatch = new ViewerMatch(view, scopeEntry, semanticElement); fResults.add(viewMatch); + //addToBuffer(viewMatch); } } @@ -506,11 +572,75 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery { } public ISearchResult getSearchResult() { + int adds = 0; + + if (progressMonitor != null) { + progressMonitor.setWorkRemaining(fResults.size()); + progressMonitor.subTask("Displaying Results"); + } + + for (AbstractResultEntry match : fResults) { results.addMatch(match); + + if (progressMonitor != null) { + progressMonitor.worked(1); + } + + + if (delay) { + /** Every 100 events fired (prompting 100 results display operation), + * sleep 100ms so the UI doesn't get stuck + */ + adds++; + if (adds >= NUMBER_ADDS_BEFORE_SLEEP) { + adds = 0; + try { + Thread.sleep(SLEEP_MILLISECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } } + + if (progressMonitor != null) { + progressMonitor.done(); + } + return results; } + + /* + * Method to call to manually display search results + * E.g. every 100 evaluations. + * This way the results are displayed progressively + * as the query is running. + */ + /*private void displaySearchResult() { + for (AbstractResultEntry match : buffer) { + results.addMatch(match); + } + + try { + Thread.sleep(SLEEP_MILLISECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }*/ + + /* + * Display results as they fill the buffer + * Not used at the moment + */ + /*private void addToBuffer(AbstractResultEntry match) { + buffer.add(match); + + if (buffer.size() > BUFFER_SIZE) { + displaySearchResult(); + buffer.clear(); + } + }*/ /** * Getter for the text query diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusOCLQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusOCLQuery.java index 05fa2d4af7a..9c8ae625571 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusOCLQuery.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusOCLQuery.java @@ -1,424 +1,423 @@ -/*****************************************************************************
- * Copyright (c) 2013, 2014 CEA LIST 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:
- * CEA LIST - Initial API and implementation
- * Christian W. Damus (CEA) - bug 434681
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.search.ui.query;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.BasicMonitor;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.ocl.examples.xtext.console.messages.ConsoleMessages;
-import org.eclipse.ocl.pivot.ExpressionInOCL;
-import org.eclipse.ocl.pivot.evaluation.EvaluationEnvironment;
-import org.eclipse.ocl.pivot.evaluation.EvaluationVisitor;
-import org.eclipse.ocl.pivot.evaluation.ModelManager;
-import org.eclipse.ocl.pivot.resource.CSResource;
-import org.eclipse.ocl.pivot.utilities.ClassUtil;
-import org.eclipse.ocl.pivot.utilities.EnvironmentFactory;
-import org.eclipse.ocl.pivot.utilities.ParserContext;
-import org.eclipse.ocl.pivot.utilities.ParserException;
-import org.eclipse.ocl.pivot.utilities.PivotUtil;
-import org.eclipse.ocl.pivot.utilities.ValueUtil;
-import org.eclipse.ocl.pivot.values.CollectionValue;
-import org.eclipse.ocl.pivot.values.InvalidValueException;
-import org.eclipse.ocl.xtext.base.ui.model.BaseDocument;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.papyrus.uml.search.ui.Messages;
-import org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult;
-import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
-import org.eclipse.papyrus.views.search.results.ModelElementMatch;
-import org.eclipse.papyrus.views.search.results.ModelMatch;
-import org.eclipse.papyrus.views.search.scope.ScopeEntry;
-import org.eclipse.search.ui.ISearchResult;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.progress.IProgressService;
-import org.eclipse.xtext.resource.XtextResource;
-import org.eclipse.xtext.util.concurrent.IUnitOfWork;
-
-/**
- *
- * Papyrus specific search query
- *
- */
-public class PapyrusOCLQuery extends AbstractPapyrusQuery {
-
-
- private EObject contextObject;
-
- private PapyrusSearchResult results;
-
- private ScopeEntry scopeEntry;
-
- private BaseDocument queryEditorDocument;
-
- private ParserContext parserContext;
-
- private EnvironmentFactory environmentFactory;
-
- private ModelManager modelManager;
-
- protected Set<AbstractResultEntry> fResults = null;
-
- public PapyrusOCLQuery(BaseDocument queryEditorDocument, ParserContext parserContext, EnvironmentFactory environmentFactory, ModelManager modelManager, EObject contextObject, ScopeEntry scopeEntry) {
- this.queryEditorDocument = queryEditorDocument;
- this.contextObject = contextObject;
- this.scopeEntry = scopeEntry;
- this.parserContext = parserContext;
- this.environmentFactory = environmentFactory;
- this.modelManager = modelManager;
-
- Collection<ScopeEntry> scopeEntries = new ArrayList<ScopeEntry>();
- scopeEntries.add(scopeEntry);
- results = new PapyrusSearchResult(this);
- fResults = new HashSet<AbstractResultEntry>();
- }
-
-
- protected boolean evaluate(final String expression) {
-
- if ((expression == null) || (expression.trim().length() <= 0)) {
- MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusOCLQuery_0, Messages.PapyrusOCLQuery_1);
- return false;
- }
-
- boolean result = true;
- try {
-
-
- @SuppressWarnings("unused") IDocument doc = queryEditorDocument;
-
- final BaseDocument editorDocument = queryEditorDocument;
- Object value = null;
- try {
-
- value = editorDocument.readOnly(new IUnitOfWork<Object, XtextResource>() {
-
- public Object exec(XtextResource state) throws Exception {
- assert state != null;
- @SuppressWarnings("unused") IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
- EvaluationRunnable runnable = new EvaluationRunnable((CSResource) state, expression);
- runnable.run(new NullProgressMonitor());
- // progressService.busyCursorWhile(runnable);
- return runnable.getValue();
- }
- });
- } catch (Exception e) {
- // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getMessage());
- }
- if (value instanceof InvalidValueException) {
- InvalidValueException exception = (InvalidValueException) value;
- // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", exception.getMessage());
- Throwable cause = exception.getCause();
- if ((cause != null) && (cause != exception)) {
- // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", cause.getMessage());
- }
- } else if (value != null) {
- CollectionValue collectionValue = ValueUtil.isCollectionValue(value);
- if (collectionValue != null) {
- for (Object elementValue : collectionValue.iterable()) {
- if (elementValue instanceof EObject) {
- ModelMatch match = new ModelElementMatch(elementValue, scopeEntry);
- fResults.add(match);
- }
- // System.err.println("Found : " + ValuesUtil.stringValueOf(elementValue));
- }
- } else {
- if (value instanceof EObject) {
- ModelMatch match = new ModelElementMatch(value, scopeEntry);
- fResults.add(match);
- }
- // System.err.println("Found : " + ValuesUtil.stringValueOf(value));
- }
- } else {
- // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", ValuesUtil.stringValueOf(value));
-
- }
-
- } catch (Exception e) {
- result = false;
-
- if (e.getLocalizedMessage() == null) {
- // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getClass().getName());
- } else {
- // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getLocalizedMessage());
- }
- }
-
- return result;
- }
-
- private class EvaluationRunnable implements IRunnableWithProgress {
-
- private final CSResource resource;
-
- private final String expression;
-
- private Object value = null;
-
- public EvaluationRunnable(CSResource resource, String expression) {
- this.resource = resource;
- this.expression = expression;
- }
-
- public Object getValue() {
- return value;
- }
-
- public void run(final IProgressMonitor monitor) {
- monitor.beginTask(NLS.bind(ConsoleMessages.Progress_Title, expression), 10);
- monitor.subTask(ConsoleMessages.Progress_Synchronising);
- monitor.worked(1);
-
-
- ExpressionInOCL expressionInOCL;
- try {
- PivotUtil.checkResourceErrors("", resource); //$NON-NLS-1$
- expressionInOCL = parserContext.getExpression(resource);
- } catch (ParserException e) {
- value = new InvalidValueException(e, ConsoleMessages.Result_ParsingFailure);
- return;
- }
- if (expressionInOCL != null) {
- // monitor.worked(2);
- monitor.subTask(ConsoleMessages.Progress_Extent);
- ModelManager modelManager2 = modelManager;
- if (modelManager2 == null) {
- // let the evaluation environment create one
- modelManager2 = modelManager = environmentFactory.createModelManager(contextObject);
- }
- EvaluationEnvironment evaluationEnvironment = environmentFactory.createEvaluationEnvironment(expressionInOCL, modelManager2);
- Object contextValue = environmentFactory.getIdResolver().boxedValueOf(contextObject);
- evaluationEnvironment.add(ClassUtil.nonNullModel(expressionInOCL.getOwnedContext()), contextValue);
- monitor.worked(2);
- monitor.subTask(ConsoleMessages.Progress_Evaluating);
- try {
- // metamodelManager.setMonitor(monitor);
- EvaluationVisitor evaluationVisitor = environmentFactory.createEvaluationVisitor(evaluationEnvironment);
- evaluationVisitor.setMonitor(BasicMonitor.toMonitor(monitor));
- // evaluationVisitor.setLogger(new DomainLogger() {
- //
- // public void append(final @NonNull String message) {
- // OCLConsolePage.this.getControl().getDisplay().asyncExec(new Runnable() {
- //
- // public void run() {
- // OCLConsolePage.this.append(message, ColorManager.DEFAULT, false);
- // }
- // });
- // }
- // });
- value = evaluationVisitor.visitExpressionInOCL(expressionInOCL);
- } catch (InvalidValueException e) {
- value = e;
- } catch (Exception e) {
- value = new InvalidValueException(e, ConsoleMessages.Result_EvaluationFailure);
- } finally {
- // metamodelManager.setMonitor(null);
- }
- }
- monitor.worked(4);
- }
- }
-
- public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
- results.removeAll();
- fResults.clear();
-
- evaluate(queryEditorDocument.get().trim());
-
- monitor.done();
-
- return Status.OK_STATUS;
- }
-
- /**
- * Evaluate if the value matches the pattern
- *
- * @param value
- * the value to evaluate
- * @param attribute
- * the attribute has the value
- * @param pattern
- * the pattern that is searched
- * @param participant
- * the element that contains the value
- * @param scopeEntry
- * the scopeEntry that contains the participant
- */
- protected void evaluateAndAddToResult(String value, Object attribute, Pattern pattern, Object participant, ScopeEntry scopeEntry) {
-
- value = value != null ? value : ""; //$NON-NLS-1$
-
- @SuppressWarnings("unused") Matcher m = pattern.matcher(value);
-
- // if(isRegularExpression) {
- // if(m.matches()) {
- // int start = m.start();
- // int end = m.end();
- // ModelMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute);
- //
- // fResults.add(match);
- // }
- // } else {
- // while(m.find()) {
- // int start = m.start();
- // int end = m.end();
- // AttributeMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute);
- // fResults.add(match);
- // }
- // }
-
-
- }
-
- /**
- * Try to find elements that match in the participants
- *
- * @param participants
- * @param scopeEntry
- */
- protected void evaluate(Collection<EObject> participants, ScopeEntry scopeEntry) {
-
- // for(EObject participant : participants) {
- //
- // String query = searchQueryText;
- // if(searchQueryText.equals("")) { //$NON-NLS-1$
- // query = ".*"; //$NON-NLS-1$
- // }
- //
- // Pattern pattern = PatternHelper.getInstance().createPattern(query, isCaseSensitive, isRegularExpression);
- //
- // if(pattern != null) {
- // if(searchAllStringAttributes) {
- //
- // for(EAttribute attribute : participant.eClass().getEAllAttributes()) {
- // Object value = participant.eGet(attribute);
- //
- // if(value instanceof String) {
- // String stringValue = (String)value;
- // evaluateAndAddToResult(stringValue, attribute, pattern, participant, scopeEntry);
- // }
- // }
- //
- // } else {
- // if(participant instanceof NamedElement) {
- // String umlElementName = ((NamedElement)participant).getName();
- // umlElementName = umlElementName != null ? umlElementName : ""; //$NON-NLS-1$
- //
- // evaluateAndAddToResult(umlElementName, UMLPackage.eINSTANCE.getNamedElement_Name(), pattern, participant, scopeEntry);
- // }
- // }
- // if(searchStereotypeAttributes) {
- // if(participant instanceof Element) {
- // EList<Stereotype> stereotypes = ((Element)participant).getAppliedStereotypes();
- // for(Stereotype stereotype : stereotypes) {
- // for(Property stereotypeProperty : stereotype.getAllAttributes()) {
- // if(!stereotypeProperty.getName().startsWith("base_")) {
- // Object value = ((Element)participant).getValue(stereotype, stereotypeProperty.getName());
- // if(value != null) {
- //
- // if(value instanceof String) {
- // String stringValue = (String)value;
- // evaluateAndAddToResult(stringValue, stereotypeProperty, pattern, participant, scopeEntry);
- // }
- // }
- // }
- // }
- //
- // }
- // }
- // }
- //
- // }
- // }
- //
- // //Now, find in diagram and others the elements we found
- // ViewerSearchService viewerSearcherService = new ViewerSearchService();
- // try {
- // viewerSearcherService.startService();
- //
- // //Get sources elements that matched
- // Set<Object> sources = new HashSet<Object>();
- // for(AbstractResultEntry match : fResults) {
- // if(match instanceof AttributeMatch) {
- // sources.add(((AttributeMatch)match).getTarget());
- // } else {
- // sources.add(match.getSource());
- // }
- // }
- //
- // //Get viewer of these sources
- // Map<Object, Map<Object, Object>> viewersMappings = viewerSearcherService.getViewers(sources, scopeEntry.getModelSet());
- //
- // //Add viewers to results
- // for(Object containingModelSet : viewersMappings.keySet()) {
- // for(Object view : viewersMappings.get(containingModelSet).keySet()) {
- // Object semanticElement = viewersMappings.get(containingModelSet).get(view);
- // ViewerMatch viewMatch = new ViewerMatch(view, scopeEntry, semanticElement);
- // fResults.add(viewMatch);
- // }
- // }
- //
- // } catch (ServiceException e) {
- // Activator.log.error(Messages.PapyrusQuery_5 + scopeEntry.getModelSet(), e);
- // }
- }
-
- public String getLabel() {
- return Messages.PapyrusQuery_6;
- }
-
- public boolean canRerun() {
- return false;
- }
-
- public boolean canRunInBackground() {
- return true;
- }
-
- public ISearchResult getSearchResult() {
- for (AbstractResultEntry match : fResults) {
- results.addMatch(match);
- }
- return results;
- }
-
- /**
- * Getter for the text query
- *
- * @return the the query text
- */
- @Override
- public String getSearchQueryText() {
- if (queryEditorDocument.get().length() > 25) {
- return queryEditorDocument.get().subSequence(0, 25) + "..."; //$NON-NLS-1$
- } else {
- return queryEditorDocument.get();
- }
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2013, 2014 CEA LIST 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: + * CEA LIST - Initial API and implementation + * Christian W. Damus (CEA) - bug 434681 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.search.ui.query; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.util.BasicMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.text.IDocument; +import org.eclipse.ocl.examples.xtext.console.messages.ConsoleMessages; +import org.eclipse.ocl.pivot.ExpressionInOCL; +import org.eclipse.ocl.pivot.evaluation.EvaluationEnvironment; +import org.eclipse.ocl.pivot.evaluation.EvaluationVisitor; +import org.eclipse.ocl.pivot.evaluation.ModelManager; +import org.eclipse.ocl.pivot.resource.CSResource; +import org.eclipse.ocl.pivot.utilities.ClassUtil; +import org.eclipse.ocl.pivot.utilities.EnvironmentFactory; +import org.eclipse.ocl.pivot.utilities.ParserContext; +import org.eclipse.ocl.pivot.utilities.ParserException; +import org.eclipse.ocl.pivot.utilities.PivotUtil; +import org.eclipse.ocl.pivot.utilities.ValueUtil; +import org.eclipse.ocl.pivot.values.CollectionValue; +import org.eclipse.ocl.pivot.values.InvalidValueException; +import org.eclipse.ocl.xtext.base.ui.model.BaseDocument; +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.uml.search.ui.Messages; +import org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult; +import org.eclipse.papyrus.views.search.results.AbstractResultEntry; +import org.eclipse.papyrus.views.search.results.ModelElementMatch; +import org.eclipse.papyrus.views.search.results.ModelMatch; +import org.eclipse.papyrus.views.search.scope.ScopeEntry; +import org.eclipse.search.ui.ISearchResult; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.progress.IProgressService; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.util.concurrent.IUnitOfWork; + +/** + * + * Papyrus specific search query + * + */ +public class PapyrusOCLQuery extends AbstractPapyrusQuery { + + + private EObject contextObject; + + private PapyrusSearchResult results; + + private ScopeEntry scopeEntry; + + private BaseDocument queryEditorDocument; + + private ParserContext parserContext; + + private EnvironmentFactory environmentFactory; + + private ModelManager modelManager; + + protected Set<AbstractResultEntry> fResults = null; + + public PapyrusOCLQuery(BaseDocument queryEditorDocument, ParserContext parserContext, EnvironmentFactory environmentFactory, ModelManager modelManager, EObject contextObject, ScopeEntry scopeEntry) { + this.queryEditorDocument = queryEditorDocument; + this.contextObject = contextObject; + this.scopeEntry = scopeEntry; + this.parserContext = parserContext; + this.environmentFactory = environmentFactory; + this.modelManager = modelManager; + + Collection<ScopeEntry> scopeEntries = new ArrayList<ScopeEntry>(); + scopeEntries.add(scopeEntry); + results = new PapyrusSearchResult(this); + fResults = new HashSet<AbstractResultEntry>(); + } + + + protected boolean evaluate(final String expression) { + + if ((expression == null) || (expression.trim().length() <= 0)) { + MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusOCLQuery_0, Messages.PapyrusOCLQuery_1); + return false; + } + + boolean result = true; + try { + + + @SuppressWarnings("unused") IDocument doc = queryEditorDocument; + + final BaseDocument editorDocument = queryEditorDocument; + Object value = null; + try { + + value = editorDocument.readOnly(new IUnitOfWork<Object, XtextResource>() { + + public Object exec(XtextResource state) throws Exception { + assert state != null; + @SuppressWarnings("unused") IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); + EvaluationRunnable runnable = new EvaluationRunnable((CSResource) state, expression); + runnable.run(new NullProgressMonitor()); + // progressService.busyCursorWhile(runnable); + return runnable.getValue(); + } + }); + } catch (Exception e) { + // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getMessage()); + } + if (value instanceof InvalidValueException) { + InvalidValueException exception = (InvalidValueException) value; + // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", exception.getMessage()); + Throwable cause = exception.getCause(); + if ((cause != null) && (cause != exception)) { + // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", cause.getMessage()); + } + } else if (value != null) { + CollectionValue collectionValue = ValueUtil.isCollectionValue(value); + if (collectionValue != null) { + for (Object elementValue : collectionValue.iterable()) { + if (elementValue instanceof EObject) { + ModelMatch match = new ModelElementMatch(elementValue, scopeEntry); + fResults.add(match); + } + // System.err.println("Found : " + ValuesUtil.stringValueOf(elementValue)); + } + } else { + if (value instanceof EObject) { + ModelMatch match = new ModelElementMatch(value, scopeEntry); + fResults.add(match); + } + // System.err.println("Found : " + ValuesUtil.stringValueOf(value)); + } + } else { + // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", ValuesUtil.stringValueOf(value)); + + } + + } catch (Exception e) { + result = false; + + if (e.getLocalizedMessage() == null) { + // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getClass().getName()); + } else { + // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getLocalizedMessage()); + } + } + + return result; + } + + private class EvaluationRunnable implements IRunnableWithProgress { + + private final CSResource resource; + + private final String expression; + + private Object value = null; + + public EvaluationRunnable(CSResource resource, String expression) { + this.resource = resource; + this.expression = expression; + } + + public Object getValue() { + return value; + } + + public void run(final IProgressMonitor monitor) { + monitor.beginTask(NLS.bind(ConsoleMessages.Progress_Title, expression), 10); + monitor.subTask(ConsoleMessages.Progress_Synchronising); + monitor.worked(1); + + + ExpressionInOCL expressionInOCL; + try { + PivotUtil.checkResourceErrors("", resource); //$NON-NLS-1$ + expressionInOCL = parserContext.getExpression(resource); + } catch (ParserException e) { + value = new InvalidValueException(e, ConsoleMessages.Result_ParsingFailure); + return; + } + if (expressionInOCL != null) { + // monitor.worked(2); + monitor.subTask(ConsoleMessages.Progress_Extent); + ModelManager modelManager2 = modelManager; + if (modelManager2 == null) { + // let the evaluation environment create one + modelManager2 = modelManager = environmentFactory.createModelManager(contextObject); + } + EvaluationEnvironment evaluationEnvironment = environmentFactory.createEvaluationEnvironment(expressionInOCL, modelManager2); + Object contextValue = environmentFactory.getIdResolver().boxedValueOf(contextObject); + evaluationEnvironment.add(ClassUtil.nonNullModel(expressionInOCL.getOwnedContext()), contextValue); + monitor.worked(2); + monitor.subTask(ConsoleMessages.Progress_Evaluating); + try { + // metamodelManager.setMonitor(monitor); + EvaluationVisitor evaluationVisitor = environmentFactory.createEvaluationVisitor(evaluationEnvironment); + evaluationVisitor.setMonitor(BasicMonitor.toMonitor(monitor)); + // evaluationVisitor.setLogger(new DomainLogger() { + // + // public void append(final @NonNull String message) { + // OCLConsolePage.this.getControl().getDisplay().asyncExec(new Runnable() { + // + // public void run() { + // OCLConsolePage.this.append(message, ColorManager.DEFAULT, false); + // } + // }); + // } + // }); + value = evaluationVisitor.visitExpressionInOCL(expressionInOCL); + } catch (InvalidValueException e) { + value = e; + } catch (Exception e) { + value = new InvalidValueException(e, ConsoleMessages.Result_EvaluationFailure); + } finally { + // metamodelManager.setMonitor(null); + } + } + monitor.worked(4); + } + } + + public IStatus run(IProgressMonitor monitor) throws OperationCanceledException { + results.removeAll(); + fResults.clear(); + + evaluate(queryEditorDocument.get().trim()); + + monitor.done(); + + return Status.OK_STATUS; + } + + /** + * Evaluate if the value matches the pattern + * + * @param value + * the value to evaluate + * @param attribute + * the attribute has the value + * @param pattern + * the pattern that is searched + * @param participant + * the element that contains the value + * @param scopeEntry + * the scopeEntry that contains the participant + */ + protected void evaluateAndAddToResult(String value, Object attribute, Pattern pattern, Object participant, ScopeEntry scopeEntry) { + + value = value != null ? value : ""; //$NON-NLS-1$ + + @SuppressWarnings("unused") Matcher m = pattern.matcher(value); + + // if(isRegularExpression) { + // if(m.matches()) { + // int start = m.start(); + // int end = m.end(); + // ModelMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute); + // + // fResults.add(match); + // } + // } else { + // while(m.find()) { + // int start = m.start(); + // int end = m.end(); + // AttributeMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute); + // fResults.add(match); + // } + // } + + + } + + /** + * Try to find elements that match in the participants + * + * @param participants + * @param scopeEntry + */ + protected void evaluate(Collection<EObject> participants, ScopeEntry scopeEntry) { + + // for(EObject participant : participants) { + // + // String query = searchQueryText; + // if(searchQueryText.equals("")) { //$NON-NLS-1$ + // query = ".*"; //$NON-NLS-1$ + // } + // + // Pattern pattern = PatternHelper.getInstance().createPattern(query, isCaseSensitive, isRegularExpression); + // + // if(pattern != null) { + // if(searchAllStringAttributes) { + // + // for(EAttribute attribute : participant.eClass().getEAllAttributes()) { + // Object value = participant.eGet(attribute); + // + // if(value instanceof String) { + // String stringValue = (String)value; + // evaluateAndAddToResult(stringValue, attribute, pattern, participant, scopeEntry); + // } + // } + // + // } else { + // if(participant instanceof NamedElement) { + // String umlElementName = ((NamedElement)participant).getName(); + // umlElementName = umlElementName != null ? umlElementName : ""; //$NON-NLS-1$ + // + // evaluateAndAddToResult(umlElementName, UMLPackage.eINSTANCE.getNamedElement_Name(), pattern, participant, scopeEntry); + // } + // } + // if(searchStereotypeAttributes) { + // if(participant instanceof Element) { + // EList<Stereotype> stereotypes = ((Element)participant).getAppliedStereotypes(); + // for(Stereotype stereotype : stereotypes) { + // for(Property stereotypeProperty : stereotype.getAllAttributes()) { + // if(!stereotypeProperty.getName().startsWith("base_")) { + // Object value = ((Element)participant).getValue(stereotype, stereotypeProperty.getName()); + // if(value != null) { + // + // if(value instanceof String) { + // String stringValue = (String)value; + // evaluateAndAddToResult(stringValue, stereotypeProperty, pattern, participant, scopeEntry); + // } + // } + // } + // } + // + // } + // } + // } + // + // } + // } + // + // //Now, find in diagram and others the elements we found + // ViewerSearchService viewerSearcherService = new ViewerSearchService(); + // try { + // viewerSearcherService.startService(); + // + // //Get sources elements that matched + // Set<Object> sources = new HashSet<Object>(); + // for(AbstractResultEntry match : fResults) { + // if(match instanceof AttributeMatch) { + // sources.add(((AttributeMatch)match).getTarget()); + // } else { + // sources.add(match.getSource()); + // } + // } + // + // //Get viewer of these sources + // Map<Object, Map<Object, Object>> viewersMappings = viewerSearcherService.getViewers(sources, scopeEntry.getModelSet()); + // + // //Add viewers to results + // for(Object containingModelSet : viewersMappings.keySet()) { + // for(Object view : viewersMappings.get(containingModelSet).keySet()) { + // Object semanticElement = viewersMappings.get(containingModelSet).get(view); + // ViewerMatch viewMatch = new ViewerMatch(view, scopeEntry, semanticElement); + // fResults.add(viewMatch); + // } + // } + // + // } catch (ServiceException e) { + // Activator.log.error(Messages.PapyrusQuery_5 + scopeEntry.getModelSet(), e); + // } + } + + public String getLabel() { + return Messages.PapyrusQuery_6; + } + + public boolean canRerun() { + return false; + } + + public boolean canRunInBackground() { + return true; + } + + public ISearchResult getSearchResult() { + for (AbstractResultEntry match : fResults) { + results.addMatch(match); + } + return results; + } + + /** + * Getter for the text query + * + * @return the the query text + */ + @Override + public String getSearchQueryText() { + if (queryEditorDocument.get().length() > 25) { + return queryEditorDocument.get().subSequence(0, 25) + "..."; //$NON-NLS-1$ + } else { + return queryEditorDocument.get(); + } + } +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java index 9ffc2b67f99..b90f024c653 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java @@ -24,7 +24,9 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubMonitor; import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.infra.core.resource.NotFoundException; @@ -81,7 +83,11 @@ public class PapyrusQuery extends AbstractPapyrusQuery { protected Set<AbstractResultEntry> fResults = null; - + /** + * Buffer contains matches to manually display. + * The buffer should be cleared after the display operation. + */ + //protected Set<AbstractResultEntry> buffer = null; public PapyrusQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, Collection<ScopeEntry> scopeEntries, Object[] participantsTypes, boolean searchAllStringAttributes) { this.searchQueryText = searchQueryText; @@ -93,30 +99,53 @@ public class PapyrusQuery extends AbstractPapyrusQuery { results = new PapyrusSearchResult(this); fResults = new HashSet<AbstractResultEntry>(); + //buffer = new HashSet<AbstractResultEntry>(); + } + + public PapyrusQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, Collection<ScopeEntry> scopeEntries, Object[] participantsTypes, boolean searchAllStringAttributes, boolean delay) { + this.searchQueryText = searchQueryText; + this.isCaseSensitive = isCaseSensitive; + this.isRegularExpression = isRegularExpression; + this.scopeEntries = scopeEntries; + this.participantsTypes = participantsTypes; + this.searchAllStringAttributes = searchAllStringAttributes; + this.delay = delay; + + results = new PapyrusSearchResult(this); + fResults = new HashSet<AbstractResultEntry>(); + //buffer = new HashSet<AbstractResultEntry>(); } public IStatus run(IProgressMonitor monitor) throws OperationCanceledException { + progressMonitor = SubMonitor.convert(monitor, scopeEntries.size() * 3); + progressMonitor.subTask("Searching"); + results.removeAll(); fResults.clear(); - + for (ScopeEntry scopeEntry : scopeEntries) { try { if (scopeEntry.getModelSet() != null) { UmlModel umlModel = (UmlModel) scopeEntry.getModelSet().getModelChecked(UmlModel.MODEL_ID); - + EObject root = umlModel.lookupRoot(); - + Collection<EObject> participants = ParticipantValidator.getInstance().getParticipants(root, participantsTypes); + progressMonitor.worked(1); + evaluate(participants, scopeEntry); + + progressMonitor.worked(1); } } catch (NotFoundException e) { Activator.log.error(Messages.PapyrusQuery_0 + scopeEntry.getModelSet(), e); } } - monitor.done(); + + progressMonitor.done(); return Status.OK_STATUS; } @@ -148,6 +177,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery { ModelMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute, stereotype); fResults.add(match); + //addToBuffer(match); } } else { while (m.find()) { @@ -155,6 +185,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery { int length = m.end() - m.start(); AttributeMatch match = new AttributeMatch(offset, length, participant, scopeEntry, attribute, stereotype); fResults.add(match); + //addToBuffer(match); } } @@ -164,6 +195,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery { // ModelMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute); // // fResults.add(match); + // addToBuffer(match); // } } @@ -246,6 +278,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery { Object semanticElement = viewersMappings.get(containingModelSet).get(view); ViewerMatch viewMatch = new ViewerMatch(view, scopeEntry, semanticElement); fResults.add(viewMatch); + //addToBuffer(viewMatch); } } @@ -258,7 +291,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery { public Set<AbstractResultEntry> getResults() { return fResults; } - + public String getLabel() { return Messages.PapyrusQuery_6; } @@ -272,11 +305,65 @@ public class PapyrusQuery extends AbstractPapyrusQuery { } public ISearchResult getSearchResult() { + int adds = 0; + + if (progressMonitor != null) { + progressMonitor.setWorkRemaining(fResults.size()); + progressMonitor.subTask("Displaying Results"); + } + for (AbstractResultEntry match : fResults) { results.addMatch(match); + + if (progressMonitor != null) { + progressMonitor.worked(1); + } + + + if (delay) { + /** E.g. Every 100 events fired (prompting 100 results display operation), + * sleep 100ms so the UI doesn't get stuck + */ + adds++; + if (adds >= NUMBER_ADDS_BEFORE_SLEEP) { + adds = 0; + try { + Thread.sleep(SLEEP_MILLISECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + if (progressMonitor != null) { + progressMonitor.done(); } + return results; } + + /*private void displaySearchResult() { + for (AbstractResultEntry match : buffer) { + results.addMatch(match); + } + + try { + Thread.sleep(SLEEP_MILLISECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + buffer.clear(); + } + } + + private void addToBuffer(AbstractResultEntry match) { + buffer.add(match); + + if (buffer.size() > BUFFER_SIZE) { + displaySearchResult(); + buffer.clear(); + } + }*/ /** * Getter for the text query diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/QueryInfo.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/QueryInfo.java index 1c36d41f2ae..6cfca99976d 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/QueryInfo.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/QueryInfo.java @@ -38,6 +38,8 @@ public class QueryInfo { private boolean searchForAnySter; private Collection<URI> scope; + + private boolean delay = false; /** * Creates a query info for simple query. @@ -65,6 +67,36 @@ public class QueryInfo { this.participantTypes = Collections.emptyList(); this.scope = scope; } + + /** + * Creates a query info for simple query. + * + * @param queryText + * the user-supplied search query text + * @param caseSensitive + * whether the {@code queryText} is to be applied in case-sensitive fashion + * @param regularExpression + * whether the {@code queryText} is to be taken as a regular expression + * @param searchAllStringAttributes + * whether to search all string attributes of UML metaclasses ({@code true}), or just named element {@linkplain NamedElement#getName() + * names} ({@code false}) + * @param scope + * the domain-specific search scope + * @param delay + * delayed results display + */ + public QueryInfo(String queryText, boolean caseSensitive, boolean regularExpression, boolean searchAllStringAttributes, Collection<URI> scope, boolean delay) { + super(); + + + this.queryText = queryText; + this.caseSensitive = caseSensitive; + this.regularExpression = regularExpression; + this.searchAllStringAttributes = searchAllStringAttributes; + this.participantTypes = Collections.emptyList(); + this.scope = scope; + this.delay = delay; + } /** * Creates a query info for advanced query. @@ -96,6 +128,40 @@ public class QueryInfo { this.searchForAllSter = searchForAllSter; this.searchForAnySter = searchForAnySter; } + + /** + * Creates a query info for advanced query. + * + * @param queryText + * the user-supplied search query text + * @param caseSensitive + * whether the {@code queryText} is to be applied in case-sensitive fashion + * @param regularExpression + * whether the {@code queryText} is to be taken as a regular expression + * @param participantTypes + * the participant types (identifying specific metaclasses and/or attributes) to include in the search + * @param searchForAllSter + * all and only selected stereotypes must be applied + * @param searchForAnySter + * at least one selected stereotype is applied or not + * @param scope + * the domain-specific search scope + * @param delay + * delayed results display + */ + public QueryInfo(String queryText, boolean caseSensitive, boolean regularExpression, Collection<? extends ParticipantTypeElement> participantTypes, Collection<URI> scope, boolean searchForAllSter, boolean searchForAnySter, boolean delay) { + super(); + + this.queryText = queryText; + this.caseSensitive = caseSensitive; + this.regularExpression = regularExpression; + this.searchAllStringAttributes = false; + this.participantTypes = participantTypes; + this.scope = scope; + this.searchForAllSter = searchForAllSter; + this.searchForAnySter = searchForAnySter; + this.delay = delay; + } /** * Partition copy constructor. @@ -111,6 +177,7 @@ public class QueryInfo { this.searchForAllSter = original.searchForAllSter; this.searchForAnySter = original.searchForAnySter; this.scope = scope; + this.delay = original.delay; } public String getQueryText() { @@ -144,6 +211,14 @@ public class QueryInfo { public boolean isSearchForAnySter() { return searchForAnySter; } + + public boolean isDelay() { + return delay; + } + + public void setDelay(boolean delay) { + this.delay = delay; + } /** diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/WorkspaceQueryProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/WorkspaceQueryProvider.java index 78f497730cc..f9b70a3c475 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/WorkspaceQueryProvider.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/WorkspaceQueryProvider.java @@ -51,12 +51,12 @@ public class WorkspaceQueryProvider implements IPapyrusQueryProvider { public AbstractPapyrusQuery createSimpleSearchQuery(QueryInfo queryInfo) { initMetaClasses(); Collection<ScopeEntry> scopeEntries = createScopeEntries(queryInfo.getScope()); - return new PapyrusQuery(queryInfo.getQueryText(), queryInfo.isCaseSensitive(), queryInfo.isRegularExpression(), scopeEntries, umlMetaClasses.toArray(), queryInfo.isSearchAllStringAttributes()); + return new PapyrusQuery(queryInfo.getQueryText(), queryInfo.isCaseSensitive(), queryInfo.isRegularExpression(), scopeEntries, umlMetaClasses.toArray(), queryInfo.isSearchAllStringAttributes(), queryInfo.isDelay()); } public AbstractPapyrusQuery createAdvancedSearchQuery(QueryInfo queryInfo) { Collection<ScopeEntry> scopeEntries = createScopeEntries(queryInfo.getScope()); - return new PapyrusAdvancedQuery(queryInfo.getQueryText(), queryInfo.isCaseSensitive(), queryInfo.isRegularExpression(), scopeEntries, queryInfo.getParticipantTypes().toArray(), queryInfo.isSearchForAllSter(), queryInfo.isSearchForAnySter()); + return new PapyrusAdvancedQuery(queryInfo.getQueryText(), queryInfo.isCaseSensitive(), queryInfo.isRegularExpression(), scopeEntries, queryInfo.getParticipantTypes().toArray(), queryInfo.isSearchForAllSter(), queryInfo.isSearchForAnySter(), queryInfo.isDelay()); } diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java index d652c7641eb..731d302be67 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java @@ -22,6 +22,8 @@ import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.papyrus.infra.core.resource.ModelUtils; +import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Stereotype; @@ -88,15 +90,20 @@ public class ParticipantValidator implements IParticipantValidator { while (it.hasNext()) { EObject modelElement = it.next(); if (modelElement instanceof Element) { - for (Stereotype appliedStereotype : ((Element) modelElement).getAppliedStereotypes()) { - // Check that metaclass of this element is a supported metaclass - for (Object stereotypeToGet : participantsTypesList) { - if (EcoreUtil.equals(appliedStereotype, (EObject) stereotypeToGet)) { + for (Object participantStereotype : participantsTypes) { + if (participantStereotype instanceof Stereotype) { + if (StereotypeUtil.isApplied((Element) modelElement, ((Stereotype) participantStereotype).getQualifiedName())) { results.add(modelElement); break; } } } + + /** + * EcoreUtil.equals is slow which has a big impact when searching in models of more than 100 elements. + * The temporary solution may raise a bug in the future. + */ + //if (EcoreUtil.equals(appliedStereotype, (EObject) participantStereotype)) { } } |