Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GEF] Convert PropertyTable to GEF GraphicalViewer #17

Closed
wants to merge 9 commits into from
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
* 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 @@ -35,6 +35,7 @@
import org.eclipse.wb.internal.core.utils.ui.GridLayoutFactory;
import org.eclipse.wb.internal.core.utils.ui.dialogs.ResizableDialog;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaProject;
Expand Down Expand Up @@ -65,7 +66,6 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
* 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 @@ -15,8 +15,8 @@
import org.eclipse.wb.internal.core.model.property.table.PropertyTable;
import org.eclipse.wb.internal.core.utils.ast.AstEditor;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.swt.graphics.Point;

/**
* {@link PropertyEditor} that displays source of {@link Expression} from {@link GenericProperty}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 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 @@ -30,13 +30,13 @@
import org.eclipse.wb.internal.core.utils.state.EditorState;
import org.eclipse.wb.internal.core.utils.ui.UiUtils;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;

import org.apache.commons.lang3.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
* 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 @@ -37,6 +37,7 @@
import org.eclipse.wb.internal.core.utils.execution.RunnableEx;
import org.eclipse.wb.internal.core.utils.state.EditorState;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
Expand All @@ -48,7 +49,6 @@
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.SelectionDialog;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
* 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 @@ -92,7 +92,7 @@ protected boolean setEditorText(Property property, String text) throws Exception
* Opens editing dialog.
*/
private void openDialog(PropertyTable propertyTable, Property property) throws Exception {
StringPropertyDialog dialog = new StringPropertyDialog(propertyTable.getShell(), property);
StringPropertyDialog dialog = new StringPropertyDialog(propertyTable.getControl().getShell(), property);
if (dialog.open() == Window.OK) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.wb.internal.core.utils.execution.ExecutionUtils;
import org.eclipse.wb.internal.core.utils.execution.RunnableEx;

import org.eclipse.swt.graphics.Point;
import org.eclipse.draw2d.geometry.Point;

/**
* Implementation of {@link PropertyEditor} for {@link ListenerMethodProperty}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
* 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 @@ -92,7 +92,7 @@ private ImportantPropertiesDialog(Shell parentShell, JavaInfo javaInfo) {
private final ObjectEventListener m_refreshListener = new ObjectEventListener() {
@Override
public void refreshed() throws Exception {
m_propertyTable.redraw();
m_propertyTable.getControl().redraw();
}
};

Expand All @@ -102,7 +102,7 @@ protected Control createDialogArea(Composite parent) {
area.setLayout(new GridLayout());
//
m_propertyTable = new PropertyTable(area, SWT.BORDER);
GridDataFactory.create(m_propertyTable).grab().fill().hintC(55, 20);
GridDataFactory.create(m_propertyTable.getControl()).grab().fill().hintC(55, 20);
// install refresh listener
m_javaInfo.addBroadcastListener(m_refreshListener);
// show important properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2023 Google, Inc.
* Copyright (c) 2011, 2024 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 All @@ -11,10 +11,9 @@
package org.eclipse.wb.internal.draw2d;

import org.eclipse.wb.draw2d.Figure;
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;

import org.eclipse.draw2d.DeferredUpdateManager;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
Expand All @@ -23,8 +22,6 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

/**
* A Canvas that contains {@link Figure Figures}.
Expand All @@ -35,21 +32,15 @@
public class FigureCanvas extends org.eclipse.draw2d.FigureCanvas {
private RootFigure m_rootFigure;
private final Dimension m_rootPreferredSize = new Dimension();
// TODO ptziegler: Painting the figures on the canvas is the responsibility of
// the UpdateManager, not the FigureCanvas.
@Deprecated
private Image m_bufferedImage;
private boolean m_drawCached;
private CachedUpdateManager m_updateManager;

////////////////////////////////////////////////////////////////////////////
//
// Constructor
//
////////////////////////////////////////////////////////////////////////////
public FigureCanvas(Composite parent, int style) {
super(parent, style | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE, createLightweightSystem());
// add all listeners
hookControlEvents();
super(parent, style | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE);
// create root figure
createRootFigure();
}
Expand All @@ -66,38 +57,17 @@ private void createRootFigure() {
m_rootFigure.setForegroundColor(getForeground());
m_rootFigure.setFont(getFont());
setDefaultEventManager();
setDefaultUpdateManager();
setContents(m_rootFigure);
}

private static LightweightSystem createLightweightSystem() {
return new LightweightSystem() {
private FigureCanvas getFigureCanvas() {
return (FigureCanvas) ReflectionUtils.getFieldObject(this, "canvas");
}

@Override
protected void controlResized() {
getFigureCanvas().disposeBufferedImage();
super.controlResized();
}

@Override
public void paint(GC gc) {
org.eclipse.swt.graphics.Rectangle bounds = gc.getClipping();
getFigureCanvas().handlePaint(gc, bounds.x, bounds.y, bounds.width, bounds.height);
}
};
}

protected void setDefaultEventManager() {
m_rootFigure.getFigureCanvas().getLightweightSystem().setEventDispatcher(new EventManager(this));
}

private void disposeBufferedImage() {
if (m_bufferedImage != null) {
m_bufferedImage.dispose();
m_bufferedImage = null;
}
protected void setDefaultUpdateManager() {
m_updateManager = new CachedUpdateManager(this);
m_rootFigure.getFigureCanvas().getLightweightSystem().setUpdateManager(m_updateManager);
}

////////////////////////////////////////////////////////////////////////////
Expand All @@ -117,7 +87,7 @@ public RootFigure getRootFigure() {
* Sets draw cached mode.
*/
public void setDrawCached(boolean value) {
m_drawCached = value;
m_updateManager.m_drawCached = value;
}

////////////////////////////////////////////////////////////////////////////
Expand All @@ -136,52 +106,6 @@ public Point computeSize(int wHint, int hHint, boolean changed) {
// Handle events
//
////////////////////////////////////////////////////////////////////////////
private void hookControlEvents() {
addListener(SWT.Dispose, new Listener() {
@Override
public void handleEvent(Event event) {
disposeBufferedImage();
}
});
}

private void handlePaint(GC paintGC, int x, int y, int width, int height) {
// check draw cached mode
if (m_drawCached) {
if (m_bufferedImage == null) {
paintGC.fillRectangle(x, y, width, height);
} else {
paintGC.drawImage(m_bufferedImage, 0, 0);
}
return;
}
// check double buffered image
if (m_bufferedImage == null) {
Point size = getSize();
m_bufferedImage = new Image(null, size.x, size.y);
}
// prepare double buffered Graphics
GC bufferedGC = new GC(m_bufferedImage);
try {
bufferedGC.setClipping(x, y, width, height);
bufferedGC.setBackground(paintGC.getBackground());
bufferedGC.setForeground(paintGC.getForeground());
bufferedGC.setFont(paintGC.getFont());
bufferedGC.setLineStyle(paintGC.getLineStyle());
bufferedGC.setLineWidth(paintGC.getLineWidth());
bufferedGC.setXORMode(paintGC.getXORMode());
// draw content
Graphics graphics = new SWTGraphics(bufferedGC);
int dx = -getViewport().getHorizontalRangeModel().getValue();
int dy = -getViewport().getVerticalRangeModel().getValue();
graphics.translate(dx, dy);
m_rootFigure.paint(graphics);
} finally {
bufferedGC.dispose();
}
// flush painting
paintGC.drawImage(m_bufferedImage, 0, 0);
}

/**
* Check bounds and reconfigure scroll bar's if needed and repaint client area.
Expand All @@ -204,4 +128,62 @@ public void handleRefresh(int x, int y, int width, int height) {
redraw();
}
}

private static class CachedUpdateManager extends DeferredUpdateManager {
private FigureCanvas m_canvas;
private Image m_bufferedImage;
private boolean m_drawCached;

public CachedUpdateManager(FigureCanvas canvas) {
m_canvas = canvas;
}

@Override
protected void paint(GC paintGC) {
org.eclipse.swt.graphics.Rectangle bounds = paintGC.getClipping();
// check draw cached mode
if (m_drawCached) {
if (m_bufferedImage == null) {
paintGC.fillRectangle(bounds);
} else {
paintGC.drawImage(m_bufferedImage, 0, 0);
}
return;
}
// check double buffered image
if (m_bufferedImage == null) {
Point size = m_canvas.getSize();
m_bufferedImage = new Image(null, size.x, size.y);
}
// prepare double buffered Graphics
GC bufferedGC = new GC(m_bufferedImage);
try {
bufferedGC.setClipping(bounds);
bufferedGC.setBackground(paintGC.getBackground());
bufferedGC.setForeground(paintGC.getForeground());
bufferedGC.setFont(paintGC.getFont());
bufferedGC.setLineStyle(paintGC.getLineStyle());
bufferedGC.setLineWidth(paintGC.getLineWidth());
bufferedGC.setXORMode(paintGC.getXORMode());
// draw content
Graphics graphics = new SWTGraphics(bufferedGC);
int dx = -m_canvas.getViewport().getHorizontalRangeModel().getValue();
int dy = -m_canvas.getViewport().getVerticalRangeModel().getValue();
graphics.translate(dx, dy);
m_canvas.getRootFigure().paint(graphics);
} finally {
bufferedGC.dispose();
}
// flush painting
paintGC.drawImage(m_bufferedImage, 0, 0);
}

@Override
public void dispose() {
if (m_bufferedImage != null) {
m_bufferedImage.dispose();
m_bufferedImage = null;
}
}
}
}
Loading
Loading