-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make palette selection and hover colors customizable
This defines a new ColorPalette interface that can be set in the PaletteViewer. The colors provided by this interface are then used in the palette figure for e.g. the tool entries. Clients can extend the DefaultColorPalette to define their own colors and therefore change the look of the palette.
- Loading branch information
Showing
21 changed files
with
404 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="ASCII"?> | ||
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmlns:ui="http://www.eclipse.org/ui/2010/UIModel/application/ui" xmi:id="_NgZIIJVIEe-9Ku3Ok7Aflw"> | ||
<imports xsi:type="menu:Menu" xmi:id="_XpVcIJVKEe-9Ku3Ok7Aflw" elementId="org.eclipse.ui.main.menu"/> | ||
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_OIiGMJVIEe-9Ku3Ok7Aflw" featurename="handlers" parentElementId="xpath:/"> | ||
<elements xsi:type="commands:Handler" xmi:id="_SvOkgJVIEe-9Ku3Ok7Aflw" elementId="org.eclipse.gef.examples.shapes.handler.paletteHandler" contributionURI="bundleclass://org.eclipse.gef.examples.shapes/org.eclipse.gef.examples.shapes.handler.ColorPaletteHandler" command="_WIwFEJVIEe-9Ku3Ok7Aflw"/> | ||
</fragments> | ||
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_Ug_dEJVIEe-9Ku3Ok7Aflw" featurename="commands" parentElementId="xpath:/"> | ||
<elements xsi:type="commands:Command" xmi:id="_WIwFEJVIEe-9Ku3Ok7Aflw" elementId="org.eclipse.gef.examples.shapes.command.paletteCommand" commandName="Use Custom Color Palette"/> | ||
</fragments> | ||
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_DGMksJVJEe-9Ku3Ok7Aflw" featurename="menuContributions" parentElementId="xpath:/"> | ||
<elements xsi:type="menu:MenuContribution" xmi:id="_FRJZUJVJEe-9Ku3Ok7Aflw" elementId="org.eclipse.gef.examples.shapes.menucontribution.paletteMenu" positionInParent="after=edit" parentId="org.eclipse.ui.main.menu"> | ||
<children xsi:type="menu:Menu" xmi:id="_VaBhYJVJEe-9Ku3Ok7Aflw" elementId="org.eclipse.gef.examples.shapes.menu.palette" label="%menu.label.1"> | ||
<visibleWhen xsi:type="ui:ImperativeExpression" xmi:id="_5lzhoJVKEe-9Ku3Ok7Aflw" contributionURI="bundleclass://org.eclipse.gef.examples.shapes/org.eclipse.gef.examples.shapes.handler.ColorPaletteExpression"/> | ||
<children xsi:type="menu:HandledMenuItem" xmi:id="_knZOAJVKEe-9Ku3Ok7Aflw" elementId="org.eclipse.gef.examples.shapes.handledmenuitem.usecustompalette" label="%handledmenuitem.label.1" enabled="false" type="Check" command="_WIwFEJVIEe-9Ku3Ok7Aflw"/> | ||
</children> | ||
</elements> | ||
</fragments> | ||
</fragment:ModelFragments> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...f.examples.shapes/src/org/eclipse/gef/examples/shapes/handler/ColorPaletteExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.gef.examples.shapes.handler; | ||
|
||
import org.eclipse.e4.core.contexts.Active; | ||
import org.eclipse.e4.core.di.annotations.Evaluate; | ||
import org.eclipse.e4.core.di.annotations.Optional; | ||
import org.eclipse.e4.ui.model.application.ui.basic.MPart; | ||
import org.eclipse.ui.IEditorPart; | ||
|
||
import org.eclipse.gef.examples.shapes.ShapesEditor; | ||
|
||
/** | ||
* This imperative expression is invoked by the {@code fragment.e4xmi} to check | ||
* whether the {@code Palette} menu item is visible. | ||
*/ | ||
public class ColorPaletteExpression { | ||
@Evaluate | ||
@SuppressWarnings("static-method") | ||
public boolean test(@Optional @Active MPart activePart) { | ||
if (activePart != null) { | ||
return activePart.getContext().get(IEditorPart.class) instanceof ShapesEditor; | ||
} | ||
return false; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
....gef.examples.shapes/src/org/eclipse/gef/examples/shapes/handler/ColorPaletteHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.gef.examples.shapes.handler; | ||
|
||
import org.eclipse.e4.core.contexts.Active; | ||
import org.eclipse.e4.core.di.annotations.CanExecute; | ||
import org.eclipse.e4.core.di.annotations.Execute; | ||
import org.eclipse.e4.ui.model.application.ui.basic.MPart; | ||
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; | ||
import org.eclipse.ui.IEditorPart; | ||
|
||
import org.eclipse.gef.GraphicalViewer; | ||
import org.eclipse.gef.ui.palette.PaletteViewer; | ||
|
||
import org.eclipse.gef.examples.shapes.ShapesEditor; | ||
import org.eclipse.gef.examples.shapes.palette.ShapesColorPalette; | ||
|
||
/** | ||
* This handler manages the {@code Use Custom Palette} menu item which switches | ||
* between the default and the custom palette theme. | ||
*/ | ||
public class ColorPaletteHandler { | ||
@Execute | ||
@SuppressWarnings("static-method") | ||
public void execute(@Active MPart activePart, MMenuItem menuItem) { | ||
IEditorPart editorPart = activePart.getContext().get(IEditorPart.class); | ||
GraphicalViewer graphicalViewer = editorPart.getAdapter(GraphicalViewer.class); | ||
PaletteViewer paletteViewer = graphicalViewer.getEditDomain().getPaletteViewer(); | ||
if (menuItem.isSelected()) { | ||
paletteViewer.setColorPalette(new ShapesColorPalette()); | ||
} else { | ||
paletteViewer.setColorPalette(null); | ||
} | ||
paletteViewer.getControl().redraw(); | ||
} | ||
|
||
@CanExecute | ||
@SuppressWarnings("static-method") | ||
public boolean canExecute(@Active MPart activePart) { | ||
return activePart.getContext().get(IEditorPart.class) instanceof ShapesEditor; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...e.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/palette/ShapesColorPalette.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.gef.examples.shapes.palette; | ||
|
||
import org.eclipse.swt.graphics.Color; | ||
|
||
import org.eclipse.draw2d.ColorConstants; | ||
|
||
import org.eclipse.gef.ui.palette.DefaultColorPalette; | ||
|
||
/** | ||
* Defines arbitrary colors that distinguish themselves from the default | ||
* palette. | ||
*/ | ||
public class ShapesColorPalette extends DefaultColorPalette { | ||
@Override | ||
public Color getSelectedColor() { | ||
return ColorConstants.darkGreen; | ||
} | ||
|
||
@Override | ||
public Color getHoverColor() { | ||
return ColorConstants.cyan; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
org.eclipse.gef.tests/src/org/eclipse/gef/test/swtbot/utils/SWTBotGefPalette.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.gef.test.swtbot.utils; | ||
|
||
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; | ||
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefViewer; | ||
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; | ||
|
||
import org.eclipse.gef.ui.palette.ColorPalette; | ||
import org.eclipse.gef.ui.palette.PaletteViewer; | ||
|
||
/** | ||
* Convenience class to create an SWTBot instance over the palette viewer. | ||
*/ | ||
public class SWTBotGefPalette extends SWTBotGefViewer { | ||
|
||
public SWTBotGefPalette(SWTBotGefViewer gefViewer) throws WidgetNotFoundException { | ||
super(getPaletteViewer(gefViewer)); | ||
} | ||
|
||
private static PaletteViewer getPaletteViewer(SWTBotGefViewer gefViewer) { | ||
SWTBotGefEditPart gefEditPart = gefViewer.rootEditPart(); | ||
return gefEditPart.part().getViewer().getEditDomain().getPaletteViewer(); | ||
} | ||
|
||
public PaletteViewer getPaletteViewer() { | ||
return (PaletteViewer) graphicalViewer; | ||
} | ||
|
||
public ColorPalette getColorPalette() { | ||
return getPaletteViewer().getColorPalette(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.