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

Moved UI whitelisting parts to tutorial UI service.

refs 2567
parent aee069e3
No related branches found
No related tags found
No related merge requests found
Showing
with 240 additions and 117 deletions
......@@ -17,6 +17,8 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.extension;
import org.fortiss.tooling.kernel.extension.data.TutorialStep;
/**
* Interface UI parts of tutorial providers.
*
......@@ -26,5 +28,14 @@ package org.fortiss.tooling.kernel.ui.extension;
* @ConQAT.Rating RED Hash:
*/
public interface ITutorialUIProvider {
/**
* Returns the global whitelist provider. This method MUST never return <code>null</code>.
*/
public ITutorialUIWhitelistProvider getGlobalUIWhitelistProvider();
/**
* Returns the local whitelist provider for the given step. This method MUST never return
* <code>null</code>.
*/
public ITutorialUIWhitelistProvider getLocalUIWhitelistProvider(TutorialStep step);
}
......@@ -17,6 +17,10 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.extension;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
/**
* Tutorial whitelist provider interface for the UI kernel services.
*
......@@ -26,5 +30,17 @@ package org.fortiss.tooling.kernel.ui.extension;
* @ConQAT.Rating RED Hash:
*/
public interface ITutorialUIWhitelistProvider {
// FIXME: not used yet
/** Returns whether the given element should be displayed in the navigator tree. */
public boolean elementVisibleInNavigator(EObject element);
/** 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.ui.extension.base;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.ui.extension.ITutorialUIWhitelistProvider;
/**
* An {@link ITutorialUIWhitelistProvider} that blacklists everything.
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class TutorialUIBlacklistAllProvider implements ITutorialUIWhitelistProvider {
/** {@inheritDoc} */
@Override
public boolean elementVisibleInNavigator(EObject element) {
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.ui.extension.base;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.ui.extension.ITutorialUIWhitelistProvider;
/**
* An {@link ITutorialUIWhitelistProvider} that whitelists everything.
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class TutorialUIWhitelistAllProvider implements ITutorialUIWhitelistProvider {
/** {@inheritDoc} */
@Override
public boolean elementVisibleInNavigator(EObject element) {
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;
}
}
......@@ -43,6 +43,7 @@ import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
import org.fortiss.tooling.kernel.ui.internal.introspection.items.ContextMenuServiceIntrospectionDetailsItem;
import org.fortiss.tooling.kernel.ui.service.IActionService;
import org.fortiss.tooling.kernel.ui.service.IContextMenuService;
import org.fortiss.tooling.kernel.ui.service.ITutorialUIService;
import org.fortiss.tooling.kernel.utils.ExtensionPointUtils;
import org.fortiss.tooling.kernel.utils.LoggingUtils;
import org.osgi.framework.Bundle;
......@@ -145,7 +146,7 @@ public class ContextMenuService implements IContextMenuService, IIntrospectiveKe
addContributions(menu, contextProvider);
if(!ITutorialService.INSTANCE.isTutorialActive() ||
ITutorialService.INSTANCE.globalDefaultActionsVisible()) {
ITutorialUIService.INSTANCE.globalDefaultActionsVisible()) {
IActionService.INSTANCE.addGlobalDefaultActionSectionToMenu(menu);
}
}
......@@ -181,8 +182,8 @@ public class ContextMenuService implements IContextMenuService, IIntrospectiveKe
}
// active tutorial may filter contributions
ITutorialService service = ITutorialService.INSTANCE;
if(service.isTutorialActive()) {
if(ITutorialService.INSTANCE.isTutorialActive()) {
ITutorialUIService service = ITutorialUIService.INSTANCE;
items =
items.stream()
.filter(i -> service.contextMenuContributionVisible(selectionElem,
......@@ -219,8 +220,8 @@ public class ContextMenuService implements IContextMenuService, IIntrospectiveKe
}
// active tutorial may filter contributions
ITutorialService service = ITutorialService.INSTANCE;
if(service.isTutorialActive()) {
if(ITutorialService.INSTANCE.isTutorialActive()) {
ITutorialUIService service = ITutorialUIService.INSTANCE;
items =
items.stream()
.filter(i -> service.contextMenuContributionVisible(selection,
......
......@@ -17,7 +17,17 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.ITutorialProvider;
import org.fortiss.tooling.kernel.extension.data.TutorialStep;
import org.fortiss.tooling.kernel.service.ITutorialService;
import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator;
import org.fortiss.tooling.kernel.ui.extension.ITutorialUIProvider;
import org.fortiss.tooling.kernel.ui.service.ITutorialUIService;
......@@ -31,10 +41,85 @@ import org.fortiss.tooling.kernel.ui.service.ITutorialUIService;
*/
public final class TutorialUIService implements ITutorialUIService {
/** The map from tutorial providers to their UI counter-part. */
private final Map<Class<? extends ITutorialProvider>, Class<? extends ITutorialUIProvider>> providerMap =
new HashMap<Class<? extends ITutorialProvider>, Class<? extends ITutorialUIProvider>>();
/** The map of tutorial UI provider instances. */
private final Map<Class<? extends ITutorialUIProvider>, ITutorialUIProvider> instanceMap =
new HashMap<Class<? extends ITutorialUIProvider>, ITutorialUIProvider>();
/** {@inheritDoc} */
@Override
public void registerTutorialProvider(Class<? extends ITutorialProvider> nonUIprovider,
Class<? extends ITutorialUIProvider> uiProvider) {
// TODO Auto-generated method stub
if(!providerMap.containsKey(nonUIprovider)) {
try {
providerMap.put(nonUIprovider, uiProvider);
instanceMap.put(uiProvider, uiProvider.newInstance());
} catch(Exception e) {
error(ToolingKernelUIActivator.getDefault(),
"Failed to instantiate tutorial UI provider " + uiProvider.getName() + "!",
e);
}
} else {
StringBuilder sb = new StringBuilder();
sb.append("TutorialProvider ").append(nonUIprovider.getName());
sb.append(" already mapped to ").append(uiProvider.getName());
sb.append("!");
error(ToolingKernelUIActivator.getDefault(), sb.toString());
}
}
/** Returns the current tutorial UI provider. */
private ITutorialUIProvider getCurrentUIProvider() {
Class<? extends ITutorialProvider> nonUIClass =
ITutorialService.INSTANCE.getActiveTutorial().getClass();
return instanceMap.get(providerMap.get(nonUIClass));
}
/** {@inheritDoc} */
@Override
public boolean elementVisibleInNavigator(EObject element) {
ITutorialUIProvider p = getCurrentUIProvider();
if(p.getGlobalUIWhitelistProvider().elementVisibleInNavigator(element)) {
return true;
}
TutorialStep step = ITutorialService.INSTANCE.getActiveTutorialStep();
return p.getLocalUIWhitelistProvider(step).elementVisibleInNavigator(element);
}
/** {@inheritDoc} */
@Override
public boolean globalDefaultActionsVisible() {
ITutorialUIProvider p = getCurrentUIProvider();
if(p.getGlobalUIWhitelistProvider().globalDefaultActionsVisible()) {
return true;
}
TutorialStep step = ITutorialService.INSTANCE.getActiveTutorialStep();
return p.getLocalUIWhitelistProvider(step).globalDefaultActionsVisible();
}
/** {@inheritDoc} */
@Override
public boolean contextMenuContributionVisible(EObject element, Object contribution) {
ITutorialUIProvider p = getCurrentUIProvider();
if(p.getGlobalUIWhitelistProvider().contextMenuContributionVisible(element, contribution)) {
return true;
}
TutorialStep step = ITutorialService.INSTANCE.getActiveTutorialStep();
return p.getLocalUIWhitelistProvider(step).contextMenuContributionVisible(element,
contribution);
}
/** {@inheritDoc} */
@Override
public boolean contextMenuContributionVisible(List<EObject> element, Object contribution) {
ITutorialUIProvider p = getCurrentUIProvider();
if(p.getGlobalUIWhitelistProvider().contextMenuContributionVisible(element, contribution)) {
return true;
}
TutorialStep step = ITutorialService.INSTANCE.getActiveTutorialStep();
return p.getLocalUIWhitelistProvider(step).contextMenuContributionVisible(element,
contribution);
}
}
......@@ -17,8 +17,6 @@ $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;
......@@ -32,9 +30,6 @@ 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. Note that active
......@@ -42,14 +37,4 @@ public interface ITutorialWhitelistProvider {
* {@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
}
......@@ -17,9 +17,6 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
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;
......@@ -32,34 +29,9 @@ import org.fortiss.tooling.kernel.extension.data.Prototype;
* @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;
}
}
......@@ -17,9 +17,6 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
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;
......@@ -32,34 +29,9 @@ import org.fortiss.tooling.kernel.extension.data.Prototype;
* @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;
}
}
......@@ -20,7 +20,6 @@ package org.fortiss.tooling.kernel.internal;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.conqat.lib.commons.collections.UnmodifiableMap;
......@@ -109,45 +108,6 @@ public final class TutorialService implements ITutorialService {
activeTutorial = null;
}
/** {@inheritDoc} */
@Override
public boolean elementVisibleInNavigator(EObject element) {
return activeTutorial.getGlobalWhitelistProvider().elementVisibleInNavigator(element) ||
activeStep.getWhitelistProvider().elementVisibleInNavigator(element);
}
/** {@inheritDoc} */
@Override
public boolean prototypeActive(Prototype 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);
}
/** {@inheritDoc} */
@Override
public void addTutorialServiceListener(ITutorialServiceListener l) {
......@@ -161,4 +121,11 @@ public final class TutorialService implements ITutorialService {
public void removeTutorialServiceListener(ITutorialServiceListener l) {
listeners.remove(l);
}
/** {@inheritDoc} */
@Override
public boolean prototypeActive(Prototype prototype) {
return activeTutorial.getGlobalWhitelistProvider().prototypeActive(prototype) ||
activeStep.getWhitelistProvider().prototypeActive(prototype);
}
}
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