Skip to content
Snippets Groups Projects
Commit 215a358d authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Extended and implemented first filtering functions in kernel services.

refs 2567
parent a0ac5dbc
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ import static java.util.Collections.emptyList;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.emf.ecore.EObject;
......@@ -35,6 +36,7 @@ import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
import org.fortiss.tooling.kernel.introspection.IIntrospectionItem;
import org.fortiss.tooling.kernel.introspection.IIntrospectiveKernelService;
import org.fortiss.tooling.kernel.introspection.KernelIntrospectionSystemService;
import org.fortiss.tooling.kernel.service.ITutorialService;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuMultiSelectionContributor;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
......@@ -142,49 +144,95 @@ public class ContextMenuService implements IContextMenuService, IIntrospectiveKe
addContributions(menu, contextProvider);
IActionService.INSTANCE.addGlobalDefaultActionSectionToMenu(menu);
if(!ITutorialService.INSTANCE.isTutorialActive() ||
ITutorialService.INSTANCE.globalDefaultActionsVisible()) {
IActionService.INSTANCE.addGlobalDefaultActionSectionToMenu(menu);
}
}
}
/** Adds registered contributions to the given menu. */
private void addContributions(IMenuManager menu, ContextMenuContextProvider contextProvider) {
List<EObject> selection = contextProvider.getSelectedModelElementList();
if(selection == null) {
// do nothing
} else if(selection.size() == 1) {
EObject selectionElem = contextProvider.getSelectedModelElement();
for(IContextMenuContributor contributor : providerList) {
singleSelectionElementContributions(menu, contextProvider);
} else if(selection.size() > 1) {
addMultiSelectionContributions(menu, contextProvider, selection);
}
}
/** Populates the menu with contributions to a single model element selection. */
private void singleSelectionElementContributions(IMenuManager menu,
ContextMenuContextProvider contextProvider) {
EObject selectionElem = contextProvider.getSelectedModelElement();
for(IContextMenuContributor contributor : providerList) {
String menuSectionID = contributor.getMenuSectionID();
if(menuSectionID == null) {
menuSectionID = IWorkbenchActionConstants.MB_ADDITIONS;
}
// get contributions from contributor
List<IContributionItem> items =
contributor.getContributedItems(selectionElem, contextProvider);
if(items == null) {
continue;
}
// active tutorial may filter contributions
ITutorialService service = ITutorialService.INSTANCE;
if(service.isTutorialActive()) {
items =
items.stream()
.filter(i -> service.contextMenuContributionVisible(selectionElem,
i)).collect(Collectors.toList());
}
if(items == null) {
continue;
}
// populate menu
for(IContributionItem item : items) {
menu.appendToGroup(menuSectionID, item);
}
}
}
/** Populates the menu with contributions to multiple model element selection. */
private void addMultiSelectionContributions(IMenuManager menu,
ContextMenuContextProvider contextProvider, List<EObject> selection) {
for(IContextMenuContributor contributor : providerList) {
if(contributor instanceof IContextMenuMultiSelectionContributor) {
IContextMenuMultiSelectionContributor multicontributor =
(IContextMenuMultiSelectionContributor)contributor;
String menuSectionID = contributor.getMenuSectionID();
if(menuSectionID == null) {
menuSectionID = IWorkbenchActionConstants.MB_ADDITIONS;
}
List<IContributionItem> l =
contributor.getContributedItems(selectionElem, contextProvider);
if(l == null) {
// get contributions from contributor
List<IContributionItem> items =
multicontributor.getContributedItems(selection, contextProvider);
if(items == null) {
continue;
}
for(IContributionItem item : l) {
menu.appendToGroup(menuSectionID, item);
// active tutorial may filter contributions
ITutorialService service = ITutorialService.INSTANCE;
if(service.isTutorialActive()) {
items =
items.stream()
.filter(i -> service.contextMenuContributionVisible(selection,
i)).collect(Collectors.toList());
}
}
} else if(selection.size() > 1) {
for(IContextMenuContributor contributor : providerList) {
if(contributor instanceof IContextMenuMultiSelectionContributor) {
IContextMenuMultiSelectionContributor multicontributor =
(IContextMenuMultiSelectionContributor)contributor;
String menuSectionID = contributor.getMenuSectionID();
if(menuSectionID == null) {
menuSectionID = IWorkbenchActionConstants.MB_ADDITIONS;
}
List<IContributionItem> l =
multicontributor.getContributedItems(selection, contextProvider);
if(l == null) {
continue;
}
for(IContributionItem item : l) {
menu.appendToGroup(menuSectionID, item);
}
if(items == null) {
continue;
}
// populate menu
for(IContributionItem item : items) {
menu.appendToGroup(menuSectionID, item);
}
}
}
......
......@@ -17,6 +17,8 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.extension;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.data.Prototype;
......@@ -30,11 +32,24 @@ import org.fortiss.tooling.kernel.extension.data.Prototype;
* @ConQAT.Rating RED Hash:
*/
public interface ITutorialWhitelistProvider {
// FIXME: not used yet
/** Returns whether the given element should be displayed in the navigator tree. */
public boolean elementVisibleInNavigator(EObject element);
/** Returns whether the given prototype is active in this tutorial. */
/**
* Returns whether the given prototype is active in this tutorial. Note that active
* prototypes may still be filtered by other methods of this whitelist provider, e.g.,
* {@link #contextMenuContributionVisible(EObject, Object)}.
*/
public boolean prototypeActive(Prototype prototype);
/** Returns whether the global default actions are visible in the context menu. */
public boolean globalDefaultActionsVisible();
/** Returns whether the given context menu contribution is visible. */
public boolean contextMenuContributionVisible(EObject element, Object contribution);
/** Returns whether the given context menu contribution is visible. */
public boolean contextMenuContributionVisible(List<EObject> element, Object contribution);
// TODO: define other methods
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2016 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.extension.base;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.ITutorialWhitelistProvider;
import org.fortiss.tooling.kernel.extension.data.Prototype;
/**
* An {@link ITutorialWhitelistProvider} that blacklists everything.
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class TutorialBlacklistAllProvider implements ITutorialWhitelistProvider {
/** {@inheritDoc} */
@Override
public boolean elementVisibleInNavigator(EObject element) {
return false;
}
/** {@inheritDoc} */
@Override
public boolean prototypeActive(Prototype prototype) {
return false;
}
/** {@inheritDoc} */
@Override
public boolean globalDefaultActionsVisible() {
return false;
}
/** {@inheritDoc} */
@Override
public boolean contextMenuContributionVisible(EObject element, Object contribution) {
return false;
}
/** {@inheritDoc} */
@Override
public boolean contextMenuContributionVisible(List<EObject> element, Object contribution) {
return false;
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2016 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.extension.base;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.ITutorialWhitelistProvider;
import org.fortiss.tooling.kernel.extension.data.Prototype;
/**
* An {@link ITutorialWhitelistProvider} that whitelists everything.
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class TutorialWhitelistAllProvider implements ITutorialWhitelistProvider {
/** {@inheritDoc} */
@Override
public boolean elementVisibleInNavigator(EObject element) {
return true;
}
/** {@inheritDoc} */
@Override
public boolean prototypeActive(Prototype prototype) {
return true;
}
/** {@inheritDoc} */
@Override
public boolean globalDefaultActionsVisible() {
return true;
}
/** {@inheritDoc} */
@Override
public boolean contextMenuContributionVisible(EObject element, Object contribution) {
return true;
}
/** {@inheritDoc} */
@Override
public boolean contextMenuContributionVisible(List<EObject> element, Object contribution) {
return true;
}
}
......@@ -18,12 +18,12 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
package org.fortiss.tooling.kernel.internal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.conqat.lib.commons.collections.UnmodifiableMap;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.ITutorialProvider;
import org.fortiss.tooling.kernel.extension.ITutorialWhitelistProvider;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.extension.data.TutorialStep;
import org.fortiss.tooling.kernel.service.IPersistencyService;
......@@ -106,28 +106,39 @@ public final class TutorialService implements ITutorialService {
/** {@inheritDoc} */
@Override
public boolean elementVisibleInNavigator(EObject element) {
if(activeTutorial == null || activeStep == null) {
return false;
}
ITutorialWhitelistProvider global = activeTutorial.getGlobalWhitelistProvider();
if(global != null && global.elementVisibleInNavigator(element)) {
return true;
}
ITutorialWhitelistProvider local = activeStep.getWhitelistProvider();
return local != null && local.elementVisibleInNavigator(element);
return activeTutorial.getGlobalWhitelistProvider().elementVisibleInNavigator(element) ||
activeStep.getWhitelistProvider().elementVisibleInNavigator(element);
}
/** {@inheritDoc} */
@Override
public boolean prototypeActive(Prototype prototype) {
if(activeTutorial == null || activeStep == null) {
return false;
}
ITutorialWhitelistProvider global = activeTutorial.getGlobalWhitelistProvider();
if(global != null && global.prototypeActive(prototype)) {
return true;
}
ITutorialWhitelistProvider local = activeStep.getWhitelistProvider();
return local != null && local.prototypeActive(prototype);
return activeTutorial.getGlobalWhitelistProvider().prototypeActive(prototype) ||
activeStep.getWhitelistProvider().prototypeActive(prototype);
}
/** {@inheritDoc} */
@Override
public boolean globalDefaultActionsVisible() {
return activeTutorial.getGlobalWhitelistProvider().globalDefaultActionsVisible() ||
activeStep.getWhitelistProvider().globalDefaultActionsVisible();
}
/** {@inheritDoc} */
@Override
public boolean contextMenuContributionVisible(EObject element, Object contribution) {
return activeTutorial.getGlobalWhitelistProvider().contextMenuContributionVisible(element,
contribution) ||
activeStep.getWhitelistProvider().contextMenuContributionVisible(element,
contribution);
}
/** {@inheritDoc} */
@Override
public boolean contextMenuContributionVisible(List<EObject> element, Object contribution) {
return activeTutorial.getGlobalWhitelistProvider().contextMenuContributionVisible(element,
contribution) ||
activeStep.getWhitelistProvider().contextMenuContributionVisible(element,
contribution);
}
}
......@@ -31,7 +31,8 @@ import org.fortiss.tooling.kernel.internal.TutorialService;
* <P>
* This interface extends {@link ITutorialWhitelistProvider}, which delegates its method calls to
* the current {@link ITutorialProvider}'s global whitelist provider and the current
* {@link TutorialStep}'s local whitelist provider.
* {@link TutorialStep}'s local whitelist provider. Note that those methods <B>MUST NOT</B> be
* called unless {@link #isTutorialActive()} returns <code>true</code>.
*
* @author hoelzl
* @author $Author: hoelzl $
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment