public code v1

This commit is contained in:
2026-05-22 11:14:29 +02:00
parent 427197ec5a
commit b8141736eb
28859 changed files with 575079 additions and 0 deletions
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1 @@
/bin
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.e4.ui.workbench.perspectiveswitcher</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
line.separator=\n
@@ -0,0 +1,106 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=error
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=error
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,28 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.e4.ui.workbench.perspectiveswitcher;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.e4.ui.workbench.perspectiveswitcher.E4PerspectiveSwitcherActivator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.e4.core.commands,
org.eclipse.e4.core.services,
org.eclipse.e4.ui.model.workbench,
org.eclipse.e4.ui.workbench,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.di,
org.eclipse.e4.ui.services,
org.eclipse.e4.core.di.extensions,
org.eclipse.jface,
javax.annotation
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javax.inject,
org.eclipse.emf.common.util,
org.osgi.service.event
Export-Package: org.eclipse.e4.ui.workbench.perspectiveswitcher.commands,
org.eclipse.e4.ui.workbench.perspectiveswitcher.handlers,
org.eclipse.e4.ui.workbench.perspectiveswitcher.tools
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Automatic-Module-Name: org.eclipse.e4.ui.workbench.perspectiveswitcher
@@ -0,0 +1,28 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>About</title>
</head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>November 20, 2008</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
</body>
</html>
@@ -0,0 +1,8 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties,\
icons/,\
about.html,\
plugin.xml
Binary file not shown.

After

Width:  |  Height:  |  Size: 574 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 670 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

@@ -0,0 +1,12 @@
###############################################################################
# Copyright (c) 2012 Joseph Carroll 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:
# Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
###############################################################################
pluginName = Eclipse Workbench Perspective Switcher
providerName = Eclipse
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="id1"
point="org.eclipse.e4.workbench.model">
<processor
beforefragment="true"
class="org.eclipse.e4.ui.workbench.perspectiveswitcher.E4PerspectiveSwitcherProcessor">
</processor>
</extension>
</plugin>
@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright (c) 2012 - 2014 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - ongoing maintenance
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher;
import org.eclipse.e4.ui.internal.workbench.URIHelper;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
/**
* The activator class controls the plug-in life cycle
*/
@SuppressWarnings("restriction")
public class E4PerspectiveSwitcherActivator implements BundleActivator {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.e4.ui.workbench.perspectiveswitcher"; //$NON-NLS-1$
public static final String RESOURCE_SCHEMA = "bundleclass://"; //$NON-NLS-1$
public static final String RESOURCE_SEPARATOR = "/"; //$NON-NLS-1$
// The shared instance
private static E4PerspectiveSwitcherActivator plugin;
/**
* The constructor
*/
public E4PerspectiveSwitcherActivator() {
}
@Override
public void start(BundleContext context) throws Exception {
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static E4PerspectiveSwitcherActivator getDefault() {
return plugin;
}
/**
* Returns the platform URI of the bundle
*
* @return the platform URI
*/
public String getPlatformURI() {
return URIHelper.constructPlatformURI(FrameworkUtil.getBundle(E4PerspectiveSwitcherActivator.class));
}
/**
* Returns the platform resource URI for the provided class
*
* @param clazz
* the class to get the resource URI for
* @return the platform resource URI
*/
public String getResourceURI(Class<?> clazz) {
return RESOURCE_SCHEMA + PLUGIN_ID + RESOURCE_SEPARATOR
+ clazz.getCanonicalName();
}
}
@@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2012 - 2014 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - ongoing maintenance
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.commands.MCategory;
import org.eclipse.e4.ui.model.application.commands.MCommand;
import org.eclipse.e4.ui.model.application.commands.MCommandParameter;
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
import org.eclipse.e4.ui.model.application.commands.MHandler;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.commands.E4WorkbenchCommandConstants;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.commands.E4WorkbenchParameterConstants;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.handlers.E4WorkbenchHandlerConstants;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.handlers.ShowPerspectiveHandler;
public class E4PerspectiveSwitcherProcessor {
@Inject private MApplication application;
MCommandsFactory commandsFactory = MCommandsFactory.INSTANCE;
String contributorURI = E4PerspectiveSwitcherActivator.getDefault().getPlatformURI();
@Execute
void init() {
// Perspectives Category definition
MCategory perspectivesCategory = commandsFactory.createCategory();
perspectivesCategory.setContributorURI(contributorURI);
perspectivesCategory.setDescription(E4WorkbenchCommandConstants.CATEGORY_PERSPECTIVES$_DESCRIPTION);
perspectivesCategory.setElementId(E4WorkbenchCommandConstants.CATEGORY_PERSPECTIVES);
perspectivesCategory.setName(E4WorkbenchCommandConstants.CATEGORY_PERSPECTIVES$_NAME);
application.getCategories().add(perspectivesCategory);
{ // Show Perspective command & handler with properties
MCommand showPerspectiveCommand = commandsFactory.createCommand();
showPerspectiveCommand.setContributorURI(contributorURI);
showPerspectiveCommand.setElementId(E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE);
showPerspectiveCommand.setCategory(perspectivesCategory);
showPerspectiveCommand.setCommandName(E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE$_NAME);
showPerspectiveCommand.setDescription(E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE$_DESCRIPTION);
application.getCommands().add(showPerspectiveCommand);
MCommandParameter parameterPerspectiveId = commandsFactory.createCommandParameter();
parameterPerspectiveId.setContributorURI(contributorURI);
parameterPerspectiveId.setElementId(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_ID);
parameterPerspectiveId.setName(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_ID$_NAME);
parameterPerspectiveId.setOptional(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_ID$_OPTION);
showPerspectiveCommand.getParameters().add(parameterPerspectiveId);
MCommandParameter parameterWindow = commandsFactory.createCommandParameter();
parameterWindow.setContributorURI(contributorURI);
parameterWindow.setElementId(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_WINDOW);
parameterWindow.setName(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_WINDOW$_NAME);
parameterWindow.setOptional(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_WINDOW$_OPTION);
showPerspectiveCommand.getParameters().add(parameterWindow);
MCommandParameter parameterNewWindow = commandsFactory.createCommandParameter();
parameterNewWindow.setContributorURI(contributorURI);
parameterNewWindow.setElementId(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_NEW_WINDOW);
parameterNewWindow.setName(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_NEW_WINDOW$_NAME);
parameterNewWindow.setOptional(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_NEW_WINDOW$_OPTION);
showPerspectiveCommand.getParameters().add(parameterNewWindow);
MHandler showTextHandler = commandsFactory.createHandler();
showTextHandler.setContributorURI(contributorURI);
showTextHandler.setElementId(E4WorkbenchHandlerConstants.PERSPECTIVES_SHOW_PERSPECTIVE);
showTextHandler.setCommand(showPerspectiveCommand);
showTextHandler.setContributionURI(E4PerspectiveSwitcherActivator.getDefault().getResourceURI(ShowPerspectiveHandler.class));
application.getHandlers().add(showTextHandler);
}
}
}
@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher;
public class E4WorkbenchMessages {
public static final String OpenSelectPerspectiveWindow = "Open Perspective...";
}
@@ -0,0 +1,123 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.commands;
public interface E4WorkbenchCommandConstants {
/**
* Id for category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives"</code>).
*/
public static final String CATEGORY_PERSPECTIVES = "org.eclipse.e4.ui.perspectives"; //$NON-NLS-1$
/**
* Name for category "Perspectives"
* (value is <code>"Perspectives Category"</code>).
*/
public static final String CATEGORY_PERSPECTIVES$_NAME = "Perspectives"; //$NON-NLS-1$
/**
* Description for category "Perspectives"
* (value is <code>"Manipulation of workbench perspectives"</code>).
*/
public static final String CATEGORY_PERSPECTIVES$_DESCRIPTION = "Manipulation of workbench perspectives"; //$NON-NLS-1$
/**
* Id for command "Show Perspective" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.showPerspective"</code>).
*/
public static final String PERSPECTIVES_SHOW_PERSPECTIVE = "org.eclipse.e4.ui.perspectives.showPerspective"; //$NON-NLS-1$
/**
* Name for command "Show Perspective" in category "Perspectives"
* (value is <code>"Show Perspective"</code>).
*/
public static final String PERSPECTIVES_SHOW_PERSPECTIVE$_NAME = "Show Perspective"; //$NON-NLS-1$
/**
* Description for command "Show Perspective" in category "Perspectives"
* (value is <code>"Opens a new perspective"</code>).
*/
public static final String PERSPECTIVES_SHOW_PERSPECTIVE$_DESCRIPTION = "Opens a new perspective"; //$NON-NLS-1$
/**
* Id for command "Save As" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.saveAs"</code>).
*/
public static final String PERSPECTIVES_SAVE_AS = "org.eclipse.e4.ui.perspectives.saveAs"; //$NON-NLS-1$
/**
* Name for command "Save As" in category "Perspectives"
* (value is <code>"Save &As..."</code>).
*/
public static final String PERSPECTIVES_SAVE_AS$_NAME = "Save &As..."; //$NON-NLS-1$
/**
* Description for command "Save As" in category "Perspectives"
* (value is <code>"Prompts the user to save the active perspective under a specified name"</code>).
*/
public static final String PERSPECTIVES_SAVE_AS$_DESCRIPTION = "Prompts the user to save the active perspective under a specified name"; //$NON-NLS-1$
/**
* Id for command "Reset" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.reset"</code>).
*/
public static final String PERSPECTIVES_RESET = "org.eclipse.e4.ui.perspectives.reset"; //$NON-NLS-1$
/**
* Name for command "Reset" in category "Perspectives"
* (value is <code>"&Reset"</code>).
*/
public static final String PERSPECTIVES_RESET$_NAME = "&Reset"; //$NON-NLS-1$
/**
* Description for command "Reset" in category "Perspectives"
* (value is <code>"Resets the perspective to its default state"</code>).
*/
public static final String PERSPECTIVES_RESET$_DESCRIPTION = "Resets the perspective to its default state"; //$NON-NLS-1$
/**
* Id for command "Close" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.close"</code>).
*/
public static final String PERSPECTIVES_CLOSE = "org.eclipse.e4.ui.perspectives.close"; //$NON-NLS-1$
/**
* Name for command "Close" in category "Perspectives"
* (value is <code>"&Close"</code>).
*/
public static final String PERSPECTIVES_CLOSE$_NAME = "&Close"; //$NON-NLS-1$
/**
* Description for command "Close" in category "Perspectives"
* (value is <code>"Closes the perspective"</code>).
*/
public static final String PERSPECTIVES_CLOSE$_DESCRIPTION = "Closes the perspective"; //$NON-NLS-1$
/**
* Id for command "Show Text" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.showText"</code>).
*/
public static final String PERSPECTIVES_SHOW_TEXT = "org.eclipse.e4.ui.perspectives.showText"; //$NON-NLS-1$
/**
* Name for command "Show Text" in category "Perspectives"
* (value is <code>"Show &Text"</code>).
*/
public static final String PERSPECTIVES_SHOW_TEXT$_NAME = "Show &Text"; //$NON-NLS-1$
/**
* Description for command "Show Text" in category "Perspectives"
* (value is <code>"Displays the perspective name next to its icon"</code>).
*/
public static final String PERSPECTIVES_SHOW_TEXT$_DESCRIPTION = "Displays the perspective name next to its icon"; //$NON-NLS-1$
}
@@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.commands;
public class E4WorkbenchParameterConstants {
/**
* Id for command parameter "Perspective ID"
* (value is <code>"org.eclipse.e4.ui.perspectives.parameters.perspectiveId"</code>).
*/
public static final String COMMAND_PERSPECTIVE_ID = "org.eclipse.e4.ui.perspectives.parameters.perspectiveId"; //$NON-NLS-1$
/**
* Name for command parameter "Perspective ID"
* (value is <code>"Perspective ID"</code>).
*/
public static final String COMMAND_PERSPECTIVE_ID$_NAME = "Perspective ID";
/**
* Whether the command parameter "Perspective ID" is optional
* (value is <code>true</code>).
*/
public static final boolean COMMAND_PERSPECTIVE_ID$_OPTION = true;
/**
* Id for command parameter "Window"
* (value is <code>"org.eclipse.e4.ui.perspectives.parameters.window"</code>).
*/
public static final String COMMAND_PERSPECTIVE_WINDOW = "org.eclipse.e4.ui.perspectives.parameters.window"; //$NON-NLS-1$
/**
* Name for command parameter "Window"
* (value is <code>"The Current Window"</code>).
*/
public static final String COMMAND_PERSPECTIVE_WINDOW$_NAME = "The Current Window";
/**
* Whether the command parameter "Window" is optional
* (value is <code>true</code>).
*/
public static final boolean COMMAND_PERSPECTIVE_WINDOW$_OPTION = true;
/**
* Id for command parameter "New Window"
* (value is <code>"org.eclipse.e4.ui.perspectives.parameters.newWindow"</code>).
*/
public static final String COMMAND_PERSPECTIVE_NEW_WINDOW = "org.eclipse.e4.ui.perspectives.parameters.newWindow"; //$NON-NLS-1$
/**
* Name for command parameter "New Window"
* (value is <code>"Open in New Window"</code>).
*/
public static final String COMMAND_PERSPECTIVE_NEW_WINDOW$_NAME = "Open in New Window";
/**
* Whether the command parameter "New Window" is optional
* (value is <code>true</code>).
*/
public static final boolean COMMAND_PERSPECTIVE_NEW_WINDOW$_OPTION = true;
}
@@ -0,0 +1,11 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.commands;
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.handlers;
public class E4WorkbenchHandlerConstants {
/**
* Id for handler "Show Perspective" for command "Show Perspective" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.handlers.showPerspective"</code>).
*/
public static final String PERSPECTIVES_SHOW_PERSPECTIVE = "org.eclipse.e4.ui.perspectives.handlers.showPerspective"; //$NON-NLS-1$
/**
* Id for handler "Save As" for command "Save As" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.handlers.saveAs"</code>).
*/
public static final String PERSPECTIVES_SAVE_AS = "org.eclipse.e4.ui.perspectives.handlers.saveAs"; //$NON-NLS-1$
/**
* Id for handler "Reset" for command "Reset" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.handlers.reset"</code>).
*/
public static final String PERSPECTIVES_RESET = "org.eclipse.e4.ui.perspectives.handlers.reset"; //$NON-NLS-1$
/**
* Id for handler "Close" for command "Close" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.handlers.close"</code>).
*/
public static final String PERSPECTIVES_CLOSE = "org.eclipse.e4.ui.perspectives.handlers.close"; //$NON-NLS-1$
/**
* Id for handler "Show Text" for command "Show Text" in category "Perspectives"
* (value is <code>"org.eclipse.e4.ui.perspectives.handlers.showText"</code>).
*/
public static final String PERSPECTIVES_SHOW_TEXT = "org.eclipse.e4.ui.perspectives.handlers.showText"; //$NON-NLS-1$
}
@@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.handlers;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.inject.Named;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.commands.E4WorkbenchParameterConstants;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.internal.dialogs.SelectPerspectiveDialog;
public final class ShowPerspectiveHandler {
@Execute
public void execute(IEclipseContext context,
@Optional @Named(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_ID) String perspectiveID,
@Optional @Named(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_NEW_WINDOW) String newWindow)
throws InvocationTargetException, InterruptedException {
if (perspectiveID == null || perspectiveID.equals(""))
openSelectionDialog(context);
else if (Boolean.parseBoolean(newWindow))
openNewWindowPerspective(context, perspectiveID);
else
openPerspective(context, perspectiveID);
}
/**
* Opens the specified perspective in a new window.
*
* @param perspectiveId
* The perspective to open; must not be <code>null</code>
* @throws ExecutionException
* If the perspective could not be opened.
*/
private void openNewWindowPerspective(IEclipseContext context, String perspectiveID) {
MApplication application = context.get(MApplication.class);
EPartService partService = context.get(EPartService.class);
EModelService modelService = context.get(EModelService.class);
List<MPerspective> perspectives = modelService.findElements(application, perspectiveID, MPerspective.class, null);
partService.switchPerspective(perspectives.get(0));
}
/**
* Opens a view selection dialog, allowing the user to chose a view.
*
* @throws ExecutionException
* If the perspective could not be opened.
*/
private final void openSelectionDialog(IEclipseContext context) {
SelectPerspectiveDialog dialog = ContextInjectionFactory.make(SelectPerspectiveDialog.class, context);
dialog.open();
}
/**
* Opens the perspective with the given identifier.
*
* @param perspectiveId
* The perspective to open; must not be <code>null</code>
* @throws ExecutionException
* If the perspective could not be opened.
*/
private final void openPerspective(IEclipseContext context, String perspectiveID) {
MApplication application = context.get(MApplication.class);
EPartService partService = context.get(EPartService.class);
EModelService modelService = context.get(EModelService.class);
List<MPerspective> perspectives = modelService.findElements(application, perspectiveID, MPerspective.class, null);
partService.switchPerspective(perspectives.get(0));
}
}
@@ -0,0 +1,11 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.handlers;
@@ -0,0 +1,157 @@
/*******************************************************************************
* Copyright (c) 2010 IBM Corporation 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:
* IBM Corporation - initial API and implementation
* Joseph Carroll <jdsalingerjr@gmail.com> - Updated for Eclipse4
*******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.internal.dialogs;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.IFontProvider;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.jface.viewers.ViewerColumn;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
/**
* @since 3.5
*
*/
public abstract class DelegatingLabelProviderWithTooltip extends ColumnLabelProvider {
/**
*
*/
private final ILabelDecorator decorator;
ILabelProvider wrappedLabelProvider;
/**
*
* @param wrappedLabelProvider
* @param decorator
*/
DelegatingLabelProviderWithTooltip(ILabelProvider wrappedLabelProvider, ILabelDecorator decorator) {
this.wrappedLabelProvider = wrappedLabelProvider;
this.decorator = decorator;
wrappedLabelProvider.addListener(new ILabelProviderListener() {
@Override
public void labelProviderChanged(LabelProviderChangedEvent event) {
fireLabelProviderChanged(event);
}
});
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.CellLabelProvider#initialize(org.eclipse.jface.viewers.ColumnViewer, org.eclipse.jface.viewers.ViewerColumn)
*/
@Override
protected void initialize(ColumnViewer viewer, ViewerColumn column) {
super.initialize(viewer, column);
if (decorator != null) {
ColumnViewerToolTipSupport.enableFor(viewer);
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.BaseLabelProvider#fireLabelProviderChanged(org.eclipse.jface.viewers.LabelProviderChangedEvent)
*/
@Override
protected void fireLabelProviderChanged(LabelProviderChangedEvent event) {
super.fireLabelProviderChanged(event);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
return wrappedLabelProvider.getText(element);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
*/
@Override
public Image getImage(Object element) {
return wrappedLabelProvider.getImage(element);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getFont(java.lang.Object)
*/
@Override
public Font getFont(Object element) {
if (wrappedLabelProvider instanceof IFontProvider) {
return ((IFontProvider) wrappedLabelProvider).getFont(element);
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getForeground(java.lang.Object)
*/
@Override
public Color getForeground(Object element) {
if (wrappedLabelProvider instanceof IColorProvider) {
return ((IColorProvider) wrappedLabelProvider).getForeground(element);
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getBackground(java.lang.Object)
*/
@Override
public Color getBackground(Object element) {
if (wrappedLabelProvider instanceof IColorProvider) {
return ((IColorProvider) wrappedLabelProvider).getBackground(element);
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
*/
@Override
public String getToolTipText(Object element) {
if (decorator == null) {
return null;
}
String text = getText(element);
element = unwrapElement(element);
return decorator.decorateText(text, element);
}
/**
* Returns the element that will be used to determine the bundle id. In most
* cases, this method can just return the provided element. Sometimes, it
* might be necessary to return a nested object, or an
* IConfigurationElement.
*
* @param element
* @return the element, or a client object wrapped by element, or an
* IConfigurationElement
*/
protected abstract Object unwrapElement(Object element);
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.BaseLabelProvider#dispose()
*/
@Override
public void dispose() {
wrappedLabelProvider.dispose();
super.dispose();
}
}
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll.
* 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.internal.dialogs;
public class E4WorkbenchDialogConstants {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
@@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.internal.dialogs;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer;
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.basic.MWindowElement;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
@Creatable
public class PerspectiveContentProvider implements IStructuredContentProvider {
@Override
public void dispose() {
//no-op
}
@Override
public Object[] getElements(Object element) {
List<MPerspective> perspectives = new ArrayList<>(5);
if (element instanceof MWindow) {
addElementsFrom((MWindow) element, perspectives);
}
return perspectives.toArray();
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
//no-op
}
private void addElementsFrom(MWindow window, List<MPerspective> perspectives) {
List<MWindowElement> windowElements = window.getChildren();
for (MWindowElement _elm : windowElements) {
if (_elm instanceof MPerspectiveStack) {
perspectives.addAll(((MPerspectiveStack) _elm).getChildren());
} else if (_elm instanceof MPartSashContainer) {
addChildPerspectives((MPartSashContainer) _elm, perspectives);
}
}
}
private void addChildPerspectives(MPartSashContainer partContainer, List<MPerspective> perspectives) {
List<MPartSashContainerElement> containerElements = partContainer.getChildren();
for (MPartSashContainerElement _elm : containerElements) {
if (_elm instanceof MPartSashContainer) {
addChildPerspectives((MPartSashContainer) _elm, perspectives);
}
if (_elm instanceof MPerspectiveStack) {
perspectives.addAll(((MPerspectiveStack) _elm).getChildren());
}
}
}
}
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.internal.dialogs;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
@Creatable
public class PerspectiveLabelDecorator implements ILabelDecorator {
@Override
public void addListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public boolean isLabelProperty(Object element, String property) {
// TODO Auto-generated method stub
return false;
}
@Override
public void removeListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
@Override
public Image decorateImage(Image image, Object element) {
// TODO Auto-generated method stub
return null;
}
@Override
public String decorateText(String text, Object element) {
// TODO Auto-generated method stub
return null;
}
}
@@ -0,0 +1,121 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.internal.dialogs;
import java.util.HashMap;
import javax.inject.Inject;
import org.eclipse.core.runtime.Assert;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.core.services.translation.TranslationService;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.workbench.IResourceUtilities;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.E4PerspectiveSwitcherActivator;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.tools.E4Util;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
@SuppressWarnings("restriction")
@Creatable
public class PerspectiveLabelProvider extends LabelProvider implements ITableLabelProvider {
@Inject
private Logger logger;
@Inject
private IResourceUtilities<ImageDescriptor> resourceUtilities;
@Inject
private TranslationService translationService;
/**
* List of all Image objects this label provider is responsible for.
*/
private HashMap<ImageDescriptor, Image> imageCache = new HashMap<>(5);
/**
* Indicates whether the default perspective is visually marked.
*/
private boolean markActive = true;
@Override
public final Image getImage(Object element) {
Assert.isTrue(element instanceof MPerspective);
Image icon = null;
MPerspective perspective = (MPerspective) element;
String _uri = perspective.getIconURI();
ImageDescriptor descriptor = null;
try {
URI iconURI = URI.createURI(_uri);
descriptor = resourceUtilities.imageDescriptorFromURI(iconURI);
} catch (RuntimeException ex) {
logger.error("PerspectiveLabelProvider: uri=" + _uri);
}
if (descriptor != null) {
icon = imageCache.get(descriptor);
if (icon == null) {
icon = descriptor.createImage();
imageCache.put(descriptor, icon);
}
}
return icon;
}
@Override
public final void dispose() {
for (Image image : imageCache.values()) {
image.dispose();
}
imageCache.clear();
}
@Override
public final String getText(Object element) {
String label = translationService.translate("unknown",
"platform:/plugin/" + E4PerspectiveSwitcherActivator.PLUGIN_ID); //$NON-NLS-1$
if (element instanceof MPerspective) {
MPerspective perspective = (MPerspective) element;
String _lbl = perspective.getLocalizedLabel();
if (_lbl != null && !_lbl.equals("")) {
label = _lbl;
}
if (markActive && E4Util.isSelectedElement(perspective)) {
label = label + "\t(" + translationService.translate("active",
"platform:/plugin/" + E4PerspectiveSwitcherActivator.PLUGIN_ID) + ")"; //$NON-NLS-1$
}
}
return label;
}
@Override
public final Image getColumnImage(Object element, int columnIndex) {
return getImage(element);
}
@Override
public final String getColumnText(Object element, int columnIndex) {
return getText(element);
}
}
@@ -0,0 +1,244 @@
/*******************************************************************************
* Copyright (c) 2012 - 2016 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - ongoing maintenance
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.internal.dialogs;
import java.util.HashMap;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.e4.core.commands.ECommandService;
import org.eclipse.e4.core.commands.EHandlerService;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.commands.E4WorkbenchCommandConstants;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.commands.E4WorkbenchParameterConstants;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
/**
* A dialog for perspective creation
*/
@SuppressWarnings("restriction")
@Creatable
public class SelectPerspectiveDialog extends Dialog implements
ISelectionChangedListener {
@Inject
private IEclipseContext context;
@Inject
private ECommandService commandService;
@Inject
private EHandlerService handlerService;
@Inject
private MWindow window;
final private static int LIST_HEIGHT = 300;
final private static int LIST_WIDTH = 300;
private TableViewer viewer;
private Button okButton;
Object selection;
/**
* PerspectiveDialog constructor comment.
*
* @param parentShell the parent shell
*/
@Inject
public SelectPerspectiveDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
super(shell);
setShellStyle(getShellStyle() | SWT.SHEET);
}
@Override
protected void cancelPressed() {
selection = null;
super.cancelPressed();
}
@Override
protected void configureShell(Shell shell) {
shell.setText("Open Perspective");
setBlockOnOpen(false);
super.configureShell(shell);
}
/**
* Creates and returns the contents of the upper part of this dialog (above
* the button bar).
*
* @param parent the parent composite to contain the dialog area
* @return the dialog area control
*/
@Override
protected Control createDialogArea(Composite parent) {
// Run super.
Composite composite = (Composite) super.createDialogArea(parent);
composite.setFont(parent.getFont());
createViewer(composite);
layoutTopControl(viewer.getControl());
// Return results.
return composite;
}
/**
* Create a new viewer in the parent.
*
* @param parent the parent <code>Composite</code>.
*/
private void createViewer(Composite parent) {
// Add perspective list.
viewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
viewer.getTable().setFont(parent.getFont());
viewer.setLabelProvider(new DelegatingLabelProviderWithTooltip(
ContextInjectionFactory.make(PerspectiveLabelProvider.class, context),
ContextInjectionFactory.make(PerspectiveLabelDecorator.class, context)) {
@Override
protected Object unwrapElement(Object element) {
// We do not need to unwrap the element
return element;
}
});
viewer.setContentProvider(
ContextInjectionFactory.make(PerspectiveContentProvider.class, context));
// list.addFilter(activityViewerFilter);
viewer.setComparator(new ViewerComparator());
viewer.setInput(window);
viewer.addSelectionChangedListener(this);
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
handleDoubleClickEvent();
}
});
}
/**
* Handle a double click event on the list
*/
protected void handleDoubleClickEvent() {
okPressed();
}
/**
* Layout the top control.
*
* @param control the control.
*/
private void layoutTopControl(Control control) {
GridData spec = new GridData(GridData.FILL_BOTH);
spec.widthHint = LIST_WIDTH;
spec.heightHint = LIST_HEIGHT;
control.setLayoutData(spec);
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
true);
okButton.setEnabled(false);
createButton(parent, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, false);
}
// @Override
// protected void createButtonsForButtonBar(Composite parent) {
// okButton = createButton(parent, IDialogConstants.OK_ID,
// IDialogConstants.OK_LABEL,
// true);
// okButton.setEnabled(false);
// createButton(parent, IDialogConstants.CANCEL_ID,
// IDialogConstants.CANCEL_LABEL, false);
// }
/**
* Notifies that the selection has changed.
*
* @param event event object describing the change
*/
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateSelection(event);
updateButtons();
}
/**
* Update the button enablement state.
*/
protected void updateButtons() {
okButton.setEnabled(selection != null);
}
/**
* Update the selection object.
*/
protected void updateSelection(SelectionChangedEvent event) {
selection = null;
IStructuredSelection _sel = (IStructuredSelection) event.getSelection();
if (!_sel.isEmpty()) {
Object obj = _sel.getFirstElement();
if (obj instanceof MPerspective) {
selection = obj;
}
}
}
@Override
protected void okPressed() {
HashMap<String, Object> parameters = new HashMap<>(2);
parameters.put(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_ID,
((MPerspective) selection).getElementId());
parameters.put(E4WorkbenchParameterConstants.COMMAND_PERSPECTIVE_NEW_WINDOW,
"false");
ParameterizedCommand command = commandService
.createCommand(E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE, parameters);
handlerService.executeHandler(command);
super.okPressed();
}
@Override
protected boolean isResizable() {
return true;
}
}
@@ -0,0 +1,11 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.internal.dialogs;
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2012 - 2013 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - ongoing maintenance
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.tools;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
public class E4PerspectiveSwitcherPreferences {
public static final String ROOT_PREFERENCES_NODE = "org.eclipse.e4.ui.workbench.perspectiveswitcher"; //$NON-NLS-1$
public static final String LAST_ACTIVE_CONTEXT_NODE = "org.eclipse.e4.ui.workbench.perspectiveswitcher.lastActive"; //$NON-NLS-1$
public static final String SHOW_TEXT = "perspective_switcher_show_text"; //$NON-NLS-1$
public static final String LAST_ACTIVE = "last_active_perspective"; //$NON-NLS-1$
public static void initialize() {
IEclipsePreferences defaultNode = DefaultScope.INSTANCE.getNode(ROOT_PREFERENCES_NODE);
defaultNode.putBoolean(SHOW_TEXT, true);
IEclipsePreferences lastActiveNode = DefaultScope.INSTANCE.getNode(LAST_ACTIVE_CONTEXT_NODE);
lastActiveNode.put(LAST_ACTIVE, ""); //$NON-NLS-1$
}
}
@@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.tools;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
public class E4Util {
@SuppressWarnings("unchecked")
public static <T extends MUIElement> List<T> getMatchingChildren(MElementContainer<?> container, Class<T> type) {
List<T> matchingChildren = new ArrayList<>();
for (Object child : container.getChildren()) {
if (type.isInstance(child))
matchingChildren.add((T) child);
}
return matchingChildren;
}
/**
* Recursively sets the active selection to the element until it reaches the
* containing window.
*
* @param element the new selected element
*/
public static void setWindowSelectedElement(MUIElement element) {
MElementContainer<MUIElement> parent = element.getParent();
parent.setSelectedElement(element);
if (!((MUIElement) parent instanceof MWindow))
setWindowSelectedElement(parent);
}
/**
* Recursively checks if the active selection of the parent is the <tt>element</tt>,
* until the containing window element is reached. Returns true if the selected
* element is the parameter in the window and false otherwise.
*
* @param element the model element to check
* @return true if the model element is the selected element
* false otherwise
*/
public static boolean isSelectedElement(MUIElement element) {
MElementContainer<MUIElement> parent = element.getParent();
if (parent.getSelectedElement() == element) {
if (!((MUIElement) parent instanceof MWindow))
return isSelectedElement(parent);
else
return true;
}
return false;
}
}
@@ -0,0 +1,200 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.tools;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
@Creatable
public class EPerspectiveSwitcher {
@Inject
EModelService modelService;
@Inject
IEventBroker eventBroker;
@Inject
MWindow window;
IPerspectiveSwitcherControl control;
private EventHandler labelHandler = new EventHandler() {
@Override
public void handleEvent(Event event) {
if (window == null)
return;
MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(changedElement instanceof MPerspective))
return;
MPerspective perspective = (MPerspective) changedElement;
if (!perspective.isToBeRendered())
return;
MWindow perspectiveWindow = perspective.getContext().get(MWindow.class);
if (window != perspectiveWindow)
return;
String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
Object newValue = event.getProperty(UIEvents.EventTags.NEW_VALUE);
control.updateAttributeFor(perspective, attName, newValue);
}
};
private EventHandler toBeRenderedHandler = new EventHandler() {
@Override
public void handleEvent(Event event) {
if (window == null)
return;
MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(changedElement instanceof MPerspective))
return;
MPerspective perspective = (MPerspective) changedElement;
if (!perspective.getParent().isToBeRendered())
return;
MWindow perspectiveWindow = perspective.getContext().get(MWindow.class);
if (window != perspectiveWindow)
return;
if (perspective.isToBeRendered())
control.addPerspectiveShortcut(perspective);
else
control.removePerspectiveShortcut(perspective);
}
};
private EventHandler selectionHandler = new EventHandler() {
@Override
public void handleEvent(Event event) {
if (window == null)
return;
MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(changedElement instanceof MPerspectiveStack))
return;
MPerspectiveStack perspectiveStack = (MPerspectiveStack) changedElement;
if (!perspectiveStack.isToBeRendered())
return;
MWindow stackWindow = modelService.getContainingContext(perspectiveStack)
.get(MWindow.class);
if (window != stackWindow)
return;
MPerspective selectedElement = perspectiveStack.getSelectedElement();
control.setSelectedElement(selectedElement);
}
};
private EventHandler childrenHandler = new EventHandler() {
@Override
public void handleEvent(Event event) {
if (window == null)
return;
MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(changedElement instanceof MPerspectiveStack))
return;
MPerspectiveStack perspectiveStack = (MPerspectiveStack) changedElement;
if (!perspectiveStack.isToBeRendered())
return;
MWindow stackWindow = modelService.getContainingContext(perspectiveStack)
.get(MWindow.class);
if (window != stackWindow)
return;
if (UIEvents.isADD(event)) {
for (Object o : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) {
MPerspective added = (MPerspective) o;
// Adding invisible elements is a NO-OP
if (!added.isToBeRendered())
continue;
control.addPerspectiveShortcut(added);
}
} else if (UIEvents.isREMOVE(event)) {
for (Object o : UIEvents.asIterable(event, UIEvents.EventTags.OLD_VALUE)) {
MPerspective removed = (MPerspective) o;
// Removing invisible elements is a NO-OP
if (!removed.isToBeRendered())
continue;
control.removePerspectiveShortcut(removed);
}
}
}
};
void init() {
// Handles the UI element changes (label, tooltip, icon)
eventBroker.subscribe(UIEvents.UILabel.TOPIC_ALL, labelHandler);
// Handles the model's list of renderable elements
eventBroker.subscribe(UIEvents.UIElement.TOPIC_TOBERENDERED, toBeRenderedHandler);
// Handles the changes in the selected element
eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT, selectionHandler);
// Handles when whole perspective stacks are added and removed
eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_CHILDREN, childrenHandler);
}
@PreDestroy
void cleanUp() {
eventBroker.unsubscribe(labelHandler);
eventBroker.unsubscribe(toBeRenderedHandler);
eventBroker.unsubscribe(selectionHandler);
eventBroker.unsubscribe(childrenHandler);
}
/**
* Sets the UI control associated with the perspective switcher. The perspective switcher
* subscribes to topics only once a non-null ui control is passed and unsubscribes from all
* topics if a null value is received.
*
* @param uiControl the visual representation of the perspective switcher
*/
public void setControlProvider(IPerspectiveSwitcherControl uiControl) {
if (uiControl == null) {
control = null;
cleanUp();
} else {
if (control == null)
init();
control = uiControl;
}
}
}
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.tools;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
public interface IPerspectiveSwitcherControl {
/**
* Adds a shortcut for the referenced perspective to the visual perspective container.
*
* @param perspective the perspective to add
*/
void addPerspectiveShortcut(MPerspective perspective);
/**
* Removes the shortcut for the referenced perspective from the visual perspective container.
*
* @param perspective the perspective to remove
*/
void removePerspectiveShortcut(MPerspective perspective);
/**
* Updates the active selection in the visual perspective container.
*
* @param perspective the active perspective
*/
void setSelectedElement(MPerspective perspective);
/**
* Updates the given attribute for the perspective in the visual perspective container.
* Not all containers will support the same attributes.
*
* @param perspective the perspective to update
* @param attributeName the attribute of the perspective to update
* @param newValue the updated value
*/
void updateAttributeFor(MPerspective perspective, String attributeName, Object newValue);
}
@@ -0,0 +1,610 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.tools;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.e4.core.commands.ECommandService;
import org.eclipse.e4.core.commands.EHandlerService;
import org.eclipse.e4.core.di.extensions.Preference;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
import org.eclipse.e4.ui.workbench.IResourceUtilities;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.perspectiveswitcher.commands.E4WorkbenchCommandConstants;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.accessibility.AccessibleListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MenuDetectEvent;
import org.eclipse.swt.events.MenuDetectListener;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
@SuppressWarnings("restriction")
public class PerspectiveSwitcherSwtTrim implements IPerspectiveSwitcherControl {
@Inject
private Logger logger;
@Inject
private ECommandService commandService;
@Inject
private EHandlerService handlerService;
@Inject
private IResourceUtilities<?> resourceUtilities;
@Inject
private MWindow window;
@Inject
EPerspectiveSwitcher perspectiveSwitcher;
// TODO: set instance property for the previously active perspective
// keep the order for all open perspectives
//
Composite composite;
ToolBar toolBar;
//
@Inject
@Preference(value = E4PerspectiveSwitcherPreferences.SHOW_TEXT, nodePath = E4PerspectiveSwitcherPreferences.ROOT_PREFERENCES_NODE)
private boolean showShortcutText;
static String _null = ""; //$NON-NLS-1$
//
static RGB defaultContainerCurveColor = new RGB(0, 0, 0);
Image openPerspectiveImage;
Color internalCrvColor;
// CSS Styles
Color containerCurveColor;
@PreDestroy
void cleanUp() {
if (perspectiveSwitcher != null)
perspectiveSwitcher.setControlProvider(null);
perspectiveSwitcher = null;
disposeToolBarImages();
dispose();
}
@PostConstruct
void createControl(Composite parent, MToolControl control) {
perspectiveSwitcher.setControlProvider(this);
composite = new Composite(parent, SWT.None);
RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
rowLayout.marginLeft = rowLayout.marginRight = 8;
rowLayout.marginTop = 6;
rowLayout.marginBottom = 4;
composite.setLayout(rowLayout);
composite.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
paintContainer(event);
}
});
composite.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent event) {
dispose();
}
});
toolBar = new ToolBar(composite, SWT.FLAT | SWT.WRAP | SWT.RIGHT);
toolBar.addMenuDetectListener(new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent event) {
ToolBar tb = (ToolBar) event.widget;
Point p = new Point(event.x, event.y);
p = toolBar.getDisplay().map(null, toolBar, p);
ToolItem item = tb.getItem(p);
if (item != null && item.getData() != null)
openMenuFor(item, (MPerspective) item.getData());
else if (item == null)
logger.debug("No item found");
else
logger.debug("Perspective not associated with item");
}
});
toolBar.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent event) {
disposeToolBarImages();
}
});
// TODO: Implement accessibility features & I10n
toolBar.getAccessible().addAccessibleListener(new AccessibleListener() {
@Override
public void getName(AccessibleEvent e) {
}
@Override
public void getKeyboardShortcut(AccessibleEvent e) {
}
@Override
public void getHelp(AccessibleEvent e) {
}
@Override
public void getDescription(AccessibleEvent e) {
}
});
// FIXME AFRYCA modification
// ToolItem perspectiveDialog = new ToolItem(toolBar, SWT.PUSH);
// perspectiveDialog.setImage(getOpenPerspectiveImage());
// perspectiveDialog
// .setToolTipText(E4WorkbenchMessages.OpenSelectPerspectiveWindow);
// perspectiveDialog.addSelectionListener(new SelectionAdapter() {
//
// @Override
// public void widgetSelected(SelectionEvent event) {
// openPerspectiveDialog();
// }
// });
//
// // The separator
// new ToolItem(toolBar, SWT.SEPARATOR);
// The perspectives currently open
List<MPerspectiveStack> appPerspectiveStacks = E4Util
.getMatchingChildren(window, MPerspectiveStack.class);
if (appPerspectiveStacks.size() > 0) {
for (MPerspectiveStack stack : appPerspectiveStacks)
for (MPerspective perspective : stack.getChildren()) {
if (perspective.isToBeRendered())
addPerspectiveShortcut(perspective);
}
}
}
void paintContainer(PaintEvent event) {
GC gc = event.gc;
gc.setAdvanced(true);
if (gc.getAdvanced())
gc.setAntialias(SWT.ON);
Point size = composite.getSize();
int h = size.y;
int[] simpleCurve = new int[] { 0, h - 1, 1, h - 1, 2, h - 2, 2, 1, 3,
0 };
gc.setForeground(getContainerCurveColor(event));
gc.drawPolyline(simpleCurve);
Rectangle bounds = ((Control) event.widget).getBounds();
bounds.x = bounds.y = 0;
Region r = new Region();
r.add(bounds);
int[] simpleCurveClose = new int[simpleCurve.length + 4];
System.arraycopy(simpleCurve, 0, simpleCurveClose, 0,
simpleCurve.length);
int index = simpleCurve.length;
simpleCurveClose[index++] = bounds.width;
simpleCurveClose[index++] = 0;
simpleCurveClose[index++] = bounds.width;
simpleCurveClose[index++] = bounds.height;
r.subtract(simpleCurveClose);
Region clipping = new Region();
gc.getClipping(clipping);
r.intersect(clipping);
gc.setClipping(r);
clipping.dispose();
r.dispose();
}
void openMenuFor(ToolItem item, MPerspective perspective) {
final Menu menu = new Menu(toolBar);
menu.setData(perspective);
if (E4Util.isSelectedElement(perspective)) {
addSaveAsMenuItem(menu);
addResetMenuItem(menu);
}
if (perspective.isVisible()) {
addCloseMenuItem(menu);
}
new MenuItem(menu, SWT.SEPARATOR);
addShowTextMenuItem(menu);
Rectangle bounds = item.getBounds();
Point point = toolBar.toDisplay(bounds.x, bounds.y + bounds.height);
menu.setLocation(point);
menu.setVisible(true);
menu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent e) {
// do nothing
}
@Override
public void menuHidden(MenuEvent e) {
toolBar.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
menu.dispose();
}
});
}
});
}
@SuppressWarnings("unchecked")
void openPerspectiveDialog() {
ParameterizedCommand command = commandService.createCommand(
E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE,
Collections.EMPTY_MAP);
handlerService.executeHandler(command);
}
@Override
public void addPerspectiveShortcut(MPerspective perspective) {
ToolItem shortcut = new ToolItem(toolBar, SWT.RADIO);
shortcut.setData(perspective);
ImageDescriptor descriptor = getIconFor(perspective.getIconURI());
if (descriptor != null) {
Image icon = descriptor.createImage();
shortcut.setImage(icon);
}
if (descriptor == null || showShortcutText) {
String label = perspective.getLocalizedLabel();
shortcut.setText(label != null ? label : _null);
shortcut.setToolTipText(perspective.getLocalizedTooltip());
} else {
shortcut.setText(_null);
shortcut.setToolTipText(perspective.getLocalizedLabel());
}
shortcut.setSelection(E4Util.isSelectedElement(perspective));
shortcut.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
MPerspective perspective = (MPerspective) event.widget
.getData();
E4Util.setWindowSelectedElement(perspective);
}
});
// update the layout ???
}
@Override
public void removePerspectiveShortcut(MPerspective perspective) {
ToolItem item = getToolItemFor(perspective);
if (item == null || item.isDisposed())
return;
Image icon = item.getImage();
if (icon != null) {
item.setImage(null);
icon.dispose();
icon = null;
}
item.dispose();
// update the layout
}
/*
* (non-Javadoc)
*
* @see org.eclipse.e4.ui.workbench.perspectiveswitcher.tools.
* IPerspectiveSwitcherControl
* #setSelectedElement(org.eclipse.e4.ui.model.application
* .ui.advanced.MPerspective)
*/
@Override
public void setSelectedElement(MPerspective perspective) {
for (ToolItem item : toolBar.getItems())
item.setSelection(item.getData() == perspective);
}
@Override
public void updateAttributeFor(MPerspective perspective, String attName,
Object newValue) {
ToolItem item = getToolItemFor(perspective);
if (showShortcutText && UIEvents.UILabel.LABEL.equals(attName)) {
String newName = (String) newValue;
item.setText(newName != null ? newName : _null);
} else if (UIEvents.UILabel.TOOLTIP.equals(attName)) {
String newTip = (String) newValue;
item.setToolTipText(newTip);
} else if (UIEvents.UILabel.ICONURI.equals(attName)) {
ImageDescriptor descriptor = getIconFor((String) newValue);
Image newIcon = null;
Image oldIcon = item.getImage();
if (descriptor != null)
newIcon = descriptor.createImage();
item.setImage(newIcon);
if (oldIcon != null) {
oldIcon.dispose();
oldIcon = null;
}
if (!showShortcutText) {
String label = null;
if (item.getData() instanceof MPerspective)
label = ((MPerspective) item.getData()).getLocalizedLabel();
else
label = item.getText();
item.setText(item.getImage() == null ? label : _null);
}
}
}
@Inject
void setShowText(
@Preference(value = E4PerspectiveSwitcherPreferences.SHOW_TEXT, nodePath = E4PerspectiveSwitcherPreferences.ROOT_PREFERENCES_NODE) boolean showShortcutText) {
this.showShortcutText = showShortcutText;
if (toolBar == null || toolBar.isDisposed())
return;
for (ToolItem item : toolBar.getItems()) {
if (!(item.getData() instanceof MPerspective))
continue;
MPerspective perspective = (MPerspective) item.getData();
if (item.getImage() == null || this.showShortcutText) {
String label = perspective.getLocalizedLabel();
item.setText(label != null ? label : _null);
item.setToolTipText(perspective.getLocalizedTooltip());
} else {
item.setText(_null);
item.setToolTipText(perspective.getLocalizedLabel());
}
}
// update the layout
}
ToolItem getToolItemFor(MPerspective perspective) {
if (toolBar == null || toolBar.isDisposed())
return null;
ToolItem toolItem = null;
// Items 0 & 1 in the toolbar are never perspectives
for (int i = 2; i < toolBar.getItems().length && toolItem == null; i++) {
if (toolBar.getItem(i).getData() == perspective)
toolItem = toolBar.getItem(i);
}
return toolItem;
}
ImageDescriptor getIconFor(String iconURI) {
ImageDescriptor descriptor = null;
try {
URI uri = URI.createURI(iconURI);
descriptor = (ImageDescriptor) resourceUtilities
.imageDescriptorFromURI(uri);
} catch (RuntimeException ex) {
logger.debug(ex, "icon uri=" + iconURI);
}
return descriptor;
}
/**
* Returns the open perspective image TODO: Evaluate whether this needs to
* ported into an Eclipse4 friendly version.
*
* @return the image
*/
Image getOpenPerspectiveImage() {
if (openPerspectiveImage == null || openPerspectiveImage.isDisposed()) {
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
URL url = FileLocator.find(bundle, new Path(
"icons/full/eview16/new_persp.gif"), null);
ImageDescriptor imageDescr = ImageDescriptor.createFromURL(url);
return imageDescr.createImage();
// ImageDescriptor desc =
// WorkbenchImages.getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_NEW_PAGE);
// openPerspectiveImage = desc.createImage();
}
// return openPerspectiveImage;
// TODO fill image
return null;
}
Color getContainerCurveColor(PaintEvent event) {
Color curveColor = containerCurveColor;
if (curveColor == null)
curveColor = internalCrvColor != null ? internalCrvColor
: new Color(event.display, defaultContainerCurveColor);
return curveColor;
}
private void dispose() {
if (internalCrvColor != null) {
internalCrvColor.dispose();
internalCrvColor = null;
}
}
private void disposeToolBarImages() {
if (toolBar == null || toolBar.isDisposed())
return;
for (ToolItem item : toolBar.getItems()) {
Image icon = item.getImage();
if (icon != null) {
item.setImage(null);
icon.dispose();
icon = null;
}
}
}
// ///////////////////////////////////////////////////////////////
// Menu Items
// ///////////////////////////////////////////////////////////////
private void addSaveAsMenuItem(Menu menu) {
final MenuItem menuItem = new MenuItem(menu, SWT.Activate);
menuItem.setText(E4WorkbenchCommandConstants.PERSPECTIVES_SAVE_AS$_NAME);
// TODO: Integrate into help system
menuItem.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("unchecked")
@Override
public void widgetSelected(SelectionEvent event) {
ParameterizedCommand command = commandService.createCommand(
E4WorkbenchCommandConstants.PERSPECTIVES_SAVE_AS,
Collections.EMPTY_MAP);
handlerService.executeHandler(command);
}
});
}
private void addResetMenuItem(Menu menu) {
final MenuItem menuItem = new MenuItem(menu, SWT.Activate);
menuItem.setText(E4WorkbenchCommandConstants.PERSPECTIVES_RESET$_NAME);
// TODO: Integrate into help system
menuItem.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("unchecked")
@Override
public void widgetSelected(SelectionEvent event) {
ParameterizedCommand command = commandService.createCommand(
E4WorkbenchCommandConstants.PERSPECTIVES_RESET,
Collections.EMPTY_MAP);
handlerService.executeHandler(command);
}
});
}
private void addCloseMenuItem(Menu menu) {
final MenuItem menuItem = new MenuItem(menu, SWT.Activate);
menuItem.setText(E4WorkbenchCommandConstants.PERSPECTIVES_CLOSE$_NAME);
// TODO: Integrate into help system
menuItem.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("unchecked")
@Override
public void widgetSelected(SelectionEvent event) {
ParameterizedCommand command = commandService.createCommand(
E4WorkbenchCommandConstants.PERSPECTIVES_CLOSE,
Collections.EMPTY_MAP);
handlerService.executeHandler(command);
}
});
}
private void addShowTextMenuItem(Menu menu) {
final MenuItem menuItem = new MenuItem(menu, SWT.Activate | SWT.CHECK);
menuItem.setText(E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_TEXT$_NAME);
menuItem.setSelection(showShortcutText);
// TODO: Integrate into help system
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
Map<String, Object> parameters = new HashMap<>(3);
ParameterizedCommand command = commandService.createCommand(
E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_TEXT,
parameters);
handlerService.executeHandler(command);
}
});
}
}
@@ -0,0 +1,11 @@
/*******************************************************************************
* Copyright (c) 2012 Joseph Carroll 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:
* Joseph Carroll <jdsalingerjr@gmail.com> - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.workbench.perspectiveswitcher.tools;
@@ -0,0 +1,24 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.e4.ui.workbench.perspectiveswitcher;sin
gleton:=true
Bundle-Version: 1.0.0.202101221157
Bundle-Activator: org.eclipse.e4.ui.workbench.perspectiveswitcher.E4Pers
pectiveSwitcherActivator
Require-Bundle: org.eclipse.core.runtime,org.eclipse.e4.core.commands,or
g.eclipse.e4.core.services,org.eclipse.e4.ui.model.workbench,org.eclips
e.e4.ui.workbench,org.eclipse.e4.core.contexts,org.eclipse.e4.core.di,o
rg.eclipse.e4.ui.services,org.eclipse.e4.core.di.extensions,org.eclipse
.jface
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javax.annotation,javax.inject,org.eclipse.emf.common.uti
l,org.osgi.service.event
Export-Package: org.eclipse.e4.ui.workbench.perspectiveswitcher.commands
,org.eclipse.e4.ui.workbench.perspectiveswitcher.handlers,org.eclipse.e
4.ui.workbench.perspectiveswitcher.tools
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Automatic-Module-Name: org.eclipse.e4.ui.workbench.perspectiveswitcher
@@ -0,0 +1,4 @@
#Fri Jan 22 13:02:37 CET 2021
artifact.main=C\:\\Users\\\u00C1lvaro\\Workspaces\\afryca_2020\\afryca\\plugins\\org.eclipse.e4.ui.workbench.perspectiveswitcher\\target\\org.eclipse.e4.ui.workbench.perspectiveswitcher-1.0.0-SNAPSHOT.jar
artifact.attached.p2artifacts=C\:\\Users\\\u00C1lvaro\\Workspaces\\afryca_2020\\afryca\\plugins\\org.eclipse.e4.ui.workbench.perspectiveswitcher\\target\\p2artifacts.xml
artifact.attached.p2metadata=C\:\\Users\\\u00C1lvaro\\Workspaces\\afryca_2020\\afryca\\plugins\\org.eclipse.e4.ui.workbench.perspectiveswitcher\\target\\p2content.xml
@@ -0,0 +1,3 @@
artifactId=org.eclipse.e4.ui.workbench.perspectiveswitcher
groupId=afryca.group
version=1.0.0-SNAPSHOT
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<?artifactRepository version='1.1.0'?>
<artifacts size='1'>
<artifact classifier='osgi.bundle' id='org.eclipse.e4.ui.workbench.perspectiveswitcher' version='1.0.0.202101221157'>
<properties size='5'>
<property name='artifact.size' value='58140'/>
<property name='download.size' value='58140'/>
<property name='maven-groupId' value='afryca.group'/>
<property name='maven-artifactId' value='org.eclipse.e4.ui.workbench.perspectiveswitcher'/>
<property name='maven-version' value='1.0.0-SNAPSHOT'/>
</properties>
</artifact>
</artifacts>
@@ -0,0 +1,58 @@
<?xml version='1.0' encoding='UTF-8'?>
<units size='1'>
<unit id='org.eclipse.e4.ui.workbench.perspectiveswitcher' version='1.0.0.202101221157' generation='2'>
<update id='org.eclipse.e4.ui.workbench.perspectiveswitcher' range='[0.0.0,1.0.0.202101221157)' severity='0'/>
<properties size='5'>
<property name='org.eclipse.equinox.p2.name' value='%pluginName'/>
<property name='org.eclipse.equinox.p2.provider' value='%providerName'/>
<property name='maven-groupId' value='afryca.group'/>
<property name='maven-artifactId' value='org.eclipse.e4.ui.workbench.perspectiveswitcher'/>
<property name='maven-version' value='1.0.0-SNAPSHOT'/>
</properties>
<provides size='7'>
<provided namespace='org.eclipse.equinox.p2.iu' name='org.eclipse.e4.ui.workbench.perspectiveswitcher' version='1.0.0.202101221157'/>
<provided namespace='osgi.bundle' name='org.eclipse.e4.ui.workbench.perspectiveswitcher' version='1.0.0.202101221157'/>
<provided namespace='java.package' name='org.eclipse.e4.ui.workbench.perspectiveswitcher.commands' version='0.0.0'/>
<provided namespace='java.package' name='org.eclipse.e4.ui.workbench.perspectiveswitcher.handlers' version='0.0.0'/>
<provided namespace='java.package' name='org.eclipse.e4.ui.workbench.perspectiveswitcher.tools' version='0.0.0'/>
<provided namespace='osgi.identity' name='org.eclipse.e4.ui.workbench.perspectiveswitcher' version='1.0.0.202101221157'>
<properties size='1'>
<property name='type' value='osgi.bundle'/>
</properties>
</provided>
<provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/>
</provides>
<requires size='15'>
<required namespace='osgi.bundle' name='org.eclipse.core.runtime' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.core.commands' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.core.services' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.ui.model.workbench' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.ui.workbench' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.core.contexts' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.core.di' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.ui.services' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.core.di.extensions' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.jface' range='0.0.0'/>
<required namespace='java.package' name='javax.annotation' range='0.0.0'/>
<required namespace='java.package' name='javax.inject' range='0.0.0'/>
<required namespace='java.package' name='org.eclipse.emf.common.util' range='0.0.0'/>
<required namespace='java.package' name='org.osgi.service.event' range='0.0.0'/>
<requiredProperties namespace='osgi.ee' match='(&amp;(osgi.ee=JavaSE)(version=1.8))'>
<description>
org.eclipse.e4.ui.workbench.perspectiveswitcher
</description>
</requiredProperties>
</requires>
<artifacts size='1'>
<artifact classifier='osgi.bundle' id='org.eclipse.e4.ui.workbench.perspectiveswitcher' version='1.0.0.202101221157'/>
</artifacts>
<touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/>
<touchpointData size='1'>
<instructions size='1'>
<instruction key='manifest'>
Bundle-SymbolicName: org.eclipse.e4.ui.workbench.perspectiveswitcher;singleton:=true&#xA;Bundle-Version: 1.0.0.202101221157&#xA;
</instruction>
</instructions>
</touchpointData>
</unit>
</units>