Skip to content

Commit

Permalink
Initial PoC for pure GEF-based palette viewer
Browse files Browse the repository at this point in the history
This implements the WindowBuilder palette using the native GEF
implementation. While it implementation is functional, it is still
missing functionality like theming and drag & drop, which is why the new
palette has to be expiliclty enabled using the "wbp.gef.palette" system
property.
  • Loading branch information
ptziegler committed Jan 19, 2025
1 parent e79c5b8 commit c400020
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2025 Patrick Ziegler 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:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.core.editor.palette;

import org.eclipse.gef.EditDomain;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.Tool;
import org.eclipse.gef.ui.palette.PaletteViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;

/**
* Custom edit domain used for the {@link PaletteViewer} that keeps track of
* whether the CTRL key is pressed while creating a tool. If so, the tool
* remains active after being used, allowing the user to add multiple elements
* without having to re-select the entry every time.
*/
public class DesignerEditDomain extends EditDomain {

private boolean reload;

@Override
public void mouseUp(MouseEvent mouseEvent, EditPartViewer viewer) {
Tool tool = getActiveTool();
if (tool != null) {
try {
reload = (mouseEvent.stateMask & SWT.CTRL) != 0;
tool.mouseUp(mouseEvent, viewer);
} finally {
reload = false;
}
}
}

/**
* Returns {@code true}, when called from within the
* {@link #mouseUp(MouseEvent, EditPartViewer)} method while the CTRL key is
* pressed.
*/
public boolean isReload() {
return reload;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import org.eclipse.wb.core.model.JavaInfo;
import org.eclipse.wb.core.model.broadcast.ObjectEventListener;
import org.eclipse.wb.gef.core.IEditPartViewer;
import org.eclipse.wb.gef.core.tools.Tool;
import org.eclipse.wb.gef.graphical.tools.SelectionTool;
import org.eclipse.wb.internal.core.EnvironmentUtils;
import org.eclipse.wb.internal.core.editor.DesignPage;
import org.eclipse.wb.internal.core.editor.palette.command.CategoryMoveCommand;
import org.eclipse.wb.internal.core.editor.palette.command.CategoryRemoveCommand;
Expand Down Expand Up @@ -59,6 +61,9 @@
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.gef.ui.palette.PaletteContextMenuProvider;
import org.eclipse.gef.ui.palette.PaletteViewer;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -89,8 +94,11 @@ public class DesignerPalette {
private final String ENTRYINFO_CATEGORY = "org.eclipse.wb.swing.layouts";
private final boolean m_isMainPalette;
private final PluginPalettePreferences m_preferences;
private final PaletteComposite m_paletteComposite;
private final PaletteComposite m_legacyPaletteComposite;
private final DesignerPaletteOperations m_operations;
private final PaletteViewer m_paletteViewer;
private final FigureCanvas m_paletteComposite;
private final DesignerEditDomain m_paletteDomain;
private IEditPartViewer m_editPartViewer;
private JavaInfo m_rootJavaInfo;
private PaletteManager m_manager;
Expand All @@ -105,7 +113,22 @@ public DesignerPalette(Composite parent, int style, boolean isMainPalette) {
m_isMainPalette = isMainPalette;
m_operations = new DesignerPaletteOperations();
m_preferences = new PluginPalettePreferences();
m_paletteComposite = new PaletteComposite(parent, SWT.NONE);
if (EnvironmentUtils.isGefPalette()) {
m_legacyPaletteComposite = null;
m_paletteDomain = new DesignerEditDomain();
m_paletteViewer = new PaletteViewer();
m_paletteViewer.enableVerticalScrollbar(true);
m_paletteViewer.setEditDomain(m_paletteDomain);
m_paletteViewer.setPaletteViewerPreferences(m_preferences);
m_paletteViewer.setContextMenu(new PaletteContextMenuProvider(m_paletteViewer));
m_paletteComposite = (FigureCanvas) m_paletteViewer.createControl(parent);
m_paletteComposite.setScrollbarsMode(SWT.NONE);
} else {
m_legacyPaletteComposite = new PaletteComposite(parent, SWT.NONE);
m_paletteDomain = null;
m_paletteViewer = null;
m_paletteComposite = null;
}
}

////////////////////////////////////////////////////////////////////////////
Expand All @@ -114,7 +137,7 @@ public DesignerPalette(Composite parent, int style, boolean isMainPalette) {
//
////////////////////////////////////////////////////////////////////////////
public Control getControl() {
return m_paletteComposite;
return m_legacyPaletteComposite != null ? m_legacyPaletteComposite : m_paletteComposite;
}

/**
Expand All @@ -125,6 +148,9 @@ public void setInput(IEditPartViewer editPartViewer,
String toolkitId) {
m_editPartViewer = editPartViewer;
m_rootJavaInfo = rootJavaInfo;
if (m_legacyPaletteComposite == null) {
editPartViewer.getEditDomain().setPaletteViewer(m_paletteViewer);
}
//
if (m_rootJavaInfo != null) {
// cancel cache pre-loading jobs possibly scheduled and/or running
Expand All @@ -143,15 +169,21 @@ public void setInput(IEditPartViewer editPartViewer,
// configure preferences
{
m_preferences.setPrefix(toolkitId);
m_paletteComposite.setPreferences(m_preferences);
if (m_legacyPaletteComposite != null) {
m_legacyPaletteComposite.setPreferences(m_preferences);
}
}
// set site
IPaletteSite.Helper.setSite(m_rootJavaInfo, m_paletteSite);
// refresh palette on JavaInfo hierarchy refresh
rootJavaInfo.addBroadcastListener(new ObjectEventListener() {
@Override
public void refreshed() throws Exception {
if (m_paletteComposite.isDisposed()) {
if (m_legacyPaletteComposite != null && m_legacyPaletteComposite.isDisposed()) {
rootJavaInfo.removeBroadcastListener(this);
return;
}
if (m_paletteComposite != null && m_paletteComposite.isDisposed()) {
rootJavaInfo.removeBroadcastListener(this);
return;
}
Expand Down Expand Up @@ -279,6 +311,14 @@ public boolean isEnabled() {
public boolean activate(boolean reload) {
return entryInfo.createTool(reload) != null;
}

@Override
public Tool createTool() {
if (m_paletteDomain == null) {
return entryInfo.createTool(false);
}
return entryInfo.createTool(m_paletteDomain.isReload());
}
};
m_goodEntryInfos.add(entryInfo);
m_entryInfoToVisual.put(entryInfo, entry);
Expand Down Expand Up @@ -419,7 +459,11 @@ public void moveEntry(IEntry _entry, ICategory _targetCategory, IEntry _nextEntr
}
}
}
m_paletteComposite.setPalette(palette);
if (m_legacyPaletteComposite != null) {
m_legacyPaletteComposite.setPalette(palette);
} else {
m_paletteViewer.setPaletteRoot(palette);
}
configure_EditDomain_DefaultTool();
}

Expand Down Expand Up @@ -447,7 +491,11 @@ private void configure_EditDomain_DefaultTool() {
@Override
public void loadDefaultTool() {
if (m_defaultEntry != null) {
m_paletteComposite.selectEntry(m_defaultEntry, false);
if (m_legacyPaletteComposite != null) {
m_legacyPaletteComposite.selectEntry(m_defaultEntry, false);
} else {
m_paletteViewer.setActiveTool(m_defaultEntry);
}
} else {
editDomain.setActiveTool(new SelectionTool());
}
Expand All @@ -461,7 +509,9 @@ public void loadDefaultTool() {
* Refreshes visual palette.
*/
private void refreshVisualPalette() {
m_paletteComposite.refreshPalette();
if (m_legacyPaletteComposite != null) {
m_legacyPaletteComposite.refreshPalette();
}
}

////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -508,15 +558,19 @@ public void editPreferences() {
PalettePreferencesDialog dialog = new PalettePreferencesDialog(getShell(), m_preferences);
if (dialog.open() == Window.OK) {
dialog.commit();
m_paletteComposite.setPreferences(m_preferences);
if (m_legacyPaletteComposite != null) {
m_legacyPaletteComposite.setPreferences(m_preferences);
}
}
}

public void setIconsType(int iconsType) {
m_paletteComposite.setLayoutType(iconsType);
m_preferences.setLayoutSetting(iconsType);
m_paletteComposite.setPreferences(m_preferences);
m_paletteComposite.refreshComposite();
if (m_legacyPaletteComposite != null) {
m_legacyPaletteComposite.setLayoutType(iconsType);
m_legacyPaletteComposite.setPreferences(m_preferences);
m_legacyPaletteComposite.refreshComposite();
}
}

public EntryInfo getEntry(Object target) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Patrick Ziegler and others.
* Copyright (c) 2024, 2025 Patrick Ziegler 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
Expand All @@ -19,7 +19,7 @@
@SuppressWarnings("removal")
public abstract class DesignerEntry extends ToolEntry implements IEntry {
public DesignerEntry(String label, String shortDescription, ImageDescriptor iconSmall) {
super(label, shortDescription, iconSmall, null);
super(label, shortDescription, iconSmall, iconSmall);
}

/**
Expand All @@ -36,9 +36,15 @@ public DesignerEntry(String label, String shortDescription, ImageDescriptor icon
*
* @return <code>true</code> if {@link DesignerEntry} was successfully
* activated.
* @deprecated Call {@link #createTool()} instead and check for null-ness. The
* reload flag needs to be set in the edit domain. This method will
* be removed after the 2027-03 release.
*/
@Override
public abstract boolean activate(boolean reload);
@Deprecated(since = "1.19.0", forRemoval = true)
public boolean activate(boolean reload) {
return false;
}

/**
* @noreference This method is not intended to be referenced by clients.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2024 Google, Inc. and others.
* Copyright (c) 2011, 2025 Google, Inc. 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
Expand Down Expand Up @@ -210,4 +210,15 @@ public static boolean isTestingTime() {
public static void setTestingTime(boolean value) {
System.setProperty(WBP_TESTING_TIME, value ? "true" : "false");
}

////////////////////////////////////////////////////////////////////////////
//
// Development
//
////////////////////////////////////////////////////////////////////////////
private static final String WBP_GEF_PALETTE = "wbp.gef.palette";

public static boolean isGefPalette() {
return Boolean.getBoolean(WBP_GEF_PALETTE);
}
}
10 changes: 4 additions & 6 deletions org.eclipse.wb.doc.user/html-src/whatsnew/index.asciidoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
= What's New - v1.18.0
= What's New - v1.19.0

* Fixed IndexOutOfBoundsException when removing widgets while using JDK8
* Dropped support for JSR296 (Swing Application Framework)
* Removal of old amd64 binaries for Linux
* Experimental GEF palette which can be enabled using the _wbp.gef.palette_ system property.
For a full list of all changes, check the link:https://github.com/eclipse-windowbuilder/windowbuilder/milestone/10[1.18.0] milestone.
For a full list of all changes, check the link:https://github.com/eclipse-windowbuilder/windowbuilder/milestone/11[1.19.0] milestone.

What's new - link:v117.html[*v1.17.0*]
What's new - link:v118.html[*v1.18.0*]
9 changes: 9 additions & 0 deletions org.eclipse.wb.doc.user/html-src/whatsnew/v118.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
= What's New - v1.18.0

* Fixed IndexOutOfBoundsException when removing widgets while using JDK8
* Dropped support for JSR296 (Swing Application Framework)
* Removal of old amd64 binaries for Linux
For a full list of all changes, check the link:https://github.com/eclipse-windowbuilder/windowbuilder/milestone/10[1.18.0] milestone.

What's new - link:v117.html[*v1.17.0*]

0 comments on commit c400020

Please sign in to comment.