From: <gjo...@us...> - 2007-06-21 14:12:52
|
Revision: 2433 http://abbot.svn.sourceforge.net/abbot/?rev=2433&view=rev Author: gjohnsto Date: 2007-06-21 07:12:53 -0700 (Thu, 21 Jun 2007) Log Message: ----------- abbot.swt.eclipse ----------------- Added class Popups and ShellTextHandler (automatic popup dialog handling support). Added class Preferences, the beginnings of preference manipulation convenience. Added method WorkbenchUtilities.waitEditorOpen(IFile). abbot.swt.gef ------------- Added method FigureCanvasTester.findViewer(FigureCanvas). Added method FigureTester.getRoot(IFigure). Made FigureTester.findViewer(IFigure) more robust. Added class PaletteTester to start providing more convenient palette usage. Added class ViewerTester (still rudimentary). Spiffed up FigureHierarchyPrinter, FigureFormatter & EditPartFormatter. Added classes EditPartHierarchyPrinter, WidgetEditPartHierarchyPrinter, WidgetFigureHierarchyPrinter. abbot.swt.hierarchy ------------------- Changed menu label from "SWT Hierarchy" to "Abbot". Added support for printing combined Widget/Figure hierarchies and Widget/EditPart hierarchies. Consolidated the action set extensions. Modified Paths: -------------- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/FigureCanvasTester.java abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/FigureTester.java abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/EditPartFormatter.java abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/FigureFormatter.java abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/FigureHierarchyPrinter.java Added Paths: ----------- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/PaletteTester.java abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/ViewerTester.java abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/EditPartHierarchyPrinter.java abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/WidgetEditPartHierarchyPrinter.java abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/WidgetFigureHierarchyPrinter.java Modified: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/FigureCanvasTester.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/FigureCanvasTester.java 2007-06-21 14:12:46 UTC (rev 2432) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/FigureCanvasTester.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -1,6 +1,8 @@ package abbot.swt.gef.tester; import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.EditPartViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; @@ -152,6 +154,13 @@ return new Point(((size.x - 1) / grid.x) + 1, ((size.y - 1) / grid.y) + 1); } + public EditPartViewer findViewer(FigureCanvas canvas) { + IFigure rootFigure = canvas.getContents(); + if (rootFigure != null) + return FigureTester.getFigureTester().findViewer(rootFigure); + return null; + } + /** * Forces a complete redraw and update/paint of the specified {@link FigureCanvas} (including * its children). Modified: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/FigureTester.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/FigureTester.java 2007-06-21 14:12:46 UTC (rev 2432) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/FigureTester.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -1,13 +1,17 @@ package abbot.swt.gef.tester; +import java.util.HashSet; +import java.util.Set; + import junit.framework.Assert; import org.eclipse.draw2d.FigureCanvas; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.Viewport; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.GraphicalViewer; -import org.eclipse.gef.ui.parts.GraphicalEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; @@ -17,8 +21,14 @@ import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Widget; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IViewReference; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; -import abbot.swt.eclipse.utils.WorkbenchUtilities.EditorMatcher; import abbot.swt.finder.WidgetFinder; import abbot.swt.finder.WidgetFinderImpl; import abbot.swt.finder.WidgetHierarchyImpl; @@ -40,6 +50,10 @@ */ public class FigureTester { + public static FigureTester getFigureTester() { + return new FigureTester(abbot.swt.tester.Robot.getDefault()); + } + /** * A {@link Robot} that does most of the heavy lifting for us. */ @@ -128,26 +142,45 @@ */ public FigureCanvas findCanvas(IFigure figure) { checkFigure(figure); - final Viewport viewport = getViewport(figure); - if (viewport != null) { - try { - WidgetFinder finder = new WidgetFinderImpl(new WidgetHierarchyImpl(getDisplay())); - return (FigureCanvas) finder.find(new WidgetClassMatcher(FigureCanvas.class) { - public boolean matches(Widget widget) { - return super.matches(widget) - && ((FigureCanvas) widget).getViewport() == viewport; - } - }); - } catch (NotFoundException e) { - // Empty block intended. Fall through to return null. - } catch (MultipleFoundException e) { - throw new RuntimeException(e); - } + final IFigure root = getRoot(figure); + try { + WidgetFinder finder = new WidgetFinderImpl(new WidgetHierarchyImpl(getDisplay())); + return (FigureCanvas) finder.find(new WidgetClassMatcher(FigureCanvas.class) { + public boolean matches(Widget widget) { + return super.matches(widget) && getRoot((FigureCanvas) widget) == root; + } + }); + } catch (NotFoundException e) { + // Empty block intended. Fall through to return null. + } catch (MultipleFoundException e) { + throw new RuntimeException(e); } return null; } /** + * + */ + private IFigure getRoot(FigureCanvas canvas) { + return canvas.getLightweightSystem().getRootFigure(); + } + + /** + * Gets a figure's root figure. + * + * @param figure + * an {@link IFigure} + * @return the root {@link IFigure} of the figure's tree + */ + public IFigure getRoot(IFigure figure) { + checkFigure(figure); + IFigure parent = figure.getParent(); + if (parent == null) + return figure; + return getRoot(parent); + } + + /** * Gets the {@link GraphicalEditPart} that references an {@link IFigure}. * * @param figure @@ -162,35 +195,93 @@ return null; } - private GraphicalViewer findViewer(IFigure figure) { - GraphicalEditor editor = findEditor(figure); - if (editor != null) - return GEFWorkbenchUtilities.getViewer(editor); - return null; - } + public GraphicalViewer findViewer(IFigure figure) { - private GraphicalEditor findEditor(IFigure figure) { - final Viewport viewport = getViewport(figure); - return (GraphicalEditor) GEFWorkbenchUtilities.findEditor(new EditorMatcher() { - public boolean matches(IEditorPart editor) { + final IFigure root = getRoot(figure); - // It's a match iff it's a GraphicalEditor and its viewer's root edit part's figure - // is the one we're looking for. - if (editor instanceof GraphicalEditor) { - GraphicalViewer viewer = (GraphicalViewer) editor - .getAdapter(GraphicalViewer.class); - if (viewer != null) { - GraphicalEditPart rootEditPart = (GraphicalEditPart) viewer - .getRootEditPart(); - if (rootEditPart.getFigure() == viewport) - return true; + // Viewers we've already checked. + Set<GraphicalViewer> viewers = new HashSet(); + + for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) { + for (IWorkbenchPage page : window.getPages()) { + + // Checking the Editors. + for (IEditorReference editorReference : page.getEditorReferences()) { + IEditorPart editor = editorReference.getEditor(false); + GraphicalViewer viewer = getViewer(editor); + if (viewer != null && viewers.add(viewer)) { + + // Checking the GraphicalViewer itself. + if (getRoot(viewer) == root) + return viewer; + + // Checking the GraphicalViewer's PaletteViewer. + viewer = GEFWorkbenchUtilities.getPaletteViewer(viewer); + if (viewer != null && viewers.add(viewer) && getRoot(viewer) == root) + return viewer; } } - return false; + + // Checking the Views. + for (IViewReference viewReference : page.getViewReferences()) { + IViewPart view = viewReference.getView(false); + GraphicalViewer viewer = getViewer(view); + if (viewer != null && viewers.add(viewer) && getRoot(viewer) == root) + return viewer; + } } - }, false); + } + + return null; } + private IFigure getRoot(GraphicalViewer viewer) { + GraphicalEditPart rootEditPart = (GraphicalEditPart) viewer.getRootEditPart(); + return getRoot(rootEditPart.getFigure()); + } + + private GraphicalViewer getViewer(IWorkbenchPart part) { + + // Look for GraphicalViewer directly. + GraphicalViewer viewer = (GraphicalViewer) part.getAdapter(GraphicalViewer.class); + if (viewer != null) + return viewer; + + // Look for GraphicalViewer indirectly through EditPart. + EditPart editPart = (EditPart) part.getAdapter(EditPart.class); + if (editPart != null) { + EditPartViewer editPartViewer = editPart.getViewer(); + if (editPartViewer instanceof GraphicalViewer) + return (GraphicalViewer) editPartViewer; + } + + // No love. + return null; + + } + + // private GraphicalEditor findEditor(IFigure figure) { + // final Viewport viewport = getViewport(figure); + // return (GraphicalEditor) GEFWorkbenchUtilities.findEditor(new EditorMatcher() { + // public boolean matches(IEditorPart editor) { + // + // // It's a match iff it's a GraphicalEditor and its viewer's root edit part's figure + // // is the one we're looking for. + // if (editor instanceof GraphicalEditor) { + // GraphicalViewer viewer = (GraphicalViewer) editor + // .getAdapter(GraphicalViewer.class); + // if (viewer != null) { + // GraphicalEditPart rootEditPart = (GraphicalEditPart) viewer + // .getRootEditPart(); + // if (rootEditPart.getFigure() == viewport) + // return true; + // } + // } + // return false; + // } + // }, false); + // } + // /** // * Get the {@link GraphicalEditPart} in an {@link EditPart} hierarchy that references a // * specified {@link IFigure}. Added: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/PaletteTester.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/PaletteTester.java (rev 0) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/PaletteTester.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -0,0 +1,148 @@ +package abbot.swt.gef.tester; + +import java.util.List; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.internal.ui.palette.editparts.DrawerEditPart; +import org.eclipse.gef.palette.PaletteDrawer; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.gef.ui.palette.PaletteViewer; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; + +import abbot.swt.script.Condition; +import abbot.swt.tester.ControlTester; + +public class PaletteTester { + + private boolean isVisible(PaletteViewer viewer) { + Control control = viewer.getControl(); + if (control != null) + return ControlTester.getControlTester().isVisible(control); + return false; + } + + private boolean isVisible(GraphicalEditPart editPart) { + PaletteEntry model = (PaletteEntry) editPart.getModel(); + return model.isVisible(); + } + + private boolean isExpanded(GraphicalEditPart drawerEditPart) { + return ((DrawerEditPart) drawerEditPart).isExpanded(); + } + + private GraphicalEditPart findCategory(PaletteViewer paletteViewer, String category) { + for (GraphicalEditPart editPart : (List<GraphicalEditPart>) paletteViewer.getContents() + .getChildren()) { + if (editPart.getModel() instanceof PaletteDrawer) { + String label = ((PaletteDrawer) editPart.getModel()).getLabel(); + if (category.equals(label)) + return editPart; + } + } + throw new RuntimeException(category + " not found"); + } + + private FigureTester getFigureTester(GraphicalEditPart editPart) { + return getFigureTester(editPart.getViewer()); + } + + private FigureTester getFigureTester(EditPartViewer viewer) { + Display display = viewer.getControl().getDisplay(); + return new FigureTester(display); + } + + private void actionExpand(GraphicalEditPart drawerEditPart) { + getFigureTester(drawerEditPart).actionClick(drawerEditPart.getFigure()); + } + + public GraphicalEditPart actionClickItem(PaletteViewer viewer, String category, String item) { + if (!isVisible(viewer)) + throw new IllegalStateException("palette is not visible"); + + GraphicalEditPart categoryEditPart = findCategory(viewer, category); + if (!isVisible(categoryEditPart)) + throw new IllegalStateException("category " + category + " is not visible"); + + if (!isExpanded(categoryEditPart)) + actionExpand(categoryEditPart); + + return selectItem(categoryEditPart, item); + + } + + private static final int HACK_OFFSET = 20; + + /** + * Finds out if an Palette Item is currently visible + * + * @param currCategory + * @param currPaletteItem + * @return 1, -1 or 0 depending on whether we need to click up, down or not at all. + */ + private int getScroll(GraphicalEditPart currCategory, GraphicalEditPart currPaletteItem) { + Rectangle categoryBounds = currCategory.getFigure().getBounds(); + Rectangle itemBounds = currPaletteItem.getFigure().getBounds(); + if (categoryBounds.y > (itemBounds.y + HACK_OFFSET)) + return 1; + if (categoryBounds.y + categoryBounds.height < itemBounds.y) + return -1; + return 0; + } + + private GraphicalEditPart selectItem(GraphicalEditPart drawerEditPart, String label) { + + for (GraphicalEditPart itemEditPart : (List<GraphicalEditPart>) drawerEditPart + .getChildren()) { + PaletteEntry entry = (PaletteEntry) itemEditPart.getModel(); + if (label.equals(entry.getLabel())) { + if (!itemEditPart.isSelectable()) + throw new IllegalStateException(label + " is not selectable"); + + final FigureTester tester = getFigureTester(drawerEditPart); + for (;;) { + + int scroll = getScroll(drawerEditPart, itemEditPart); + if (scroll == 0) + break; + + Rectangle categoryRect = drawerEditPart.getFigure().getBounds(); + Rectangle itemRect = itemEditPart.getFigure().getBounds(); + if (scroll == 1) { + // Scroll up. + tester.actionClick(drawerEditPart.getFigure(), categoryRect.x + + itemRect.width / 2, HACK_OFFSET + 5); + } else { + // Scroll down. + tester.actionClick(drawerEditPart.getFigure(), categoryRect.x + + itemRect.width / 2, categoryRect.height - itemRect.height / 2); + } + + waitScrollComplete(itemEditPart, itemRect); + } + + tester.actionClick(itemEditPart.getFigure()); + return itemEditPart; + } + } + + return null; + } + + private void waitScrollComplete(final GraphicalEditPart editPart, final Rectangle oldBounds) { + getFigureTester(editPart.getViewer()).getRobot().wait(new Condition() { + Rectangle prevBounds;; + + public boolean test() { + Rectangle bounds = editPart.getFigure().getBounds(); + if (!bounds.equals(oldBounds) && prevBounds != null && bounds.equals(prevBounds)) + return true; + prevBounds = bounds; + return false; + } + }, 5000L, 250L); + } + +} Added: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/ViewerTester.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/ViewerTester.java (rev 0) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/tester/ViewerTester.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -0,0 +1,23 @@ +package abbot.swt.gef.tester; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; + +/** + * A tester for GEF {@link EditPartViewer}s. + * + * @author Gary Johnston + */ +public class ViewerTester { + + private static ViewerTester Default = new ViewerTester(); + + public static ViewerTester getDefault() { + return Default; + } + + public EditPart getFocusEditPart(EditPartViewer viewer) { + return viewer.getFocusEditPart(); + } + +} Modified: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/EditPartFormatter.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/EditPartFormatter.java 2007-06-21 14:12:46 UTC (rev 2432) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/EditPartFormatter.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -1,6 +1,6 @@ package abbot.swt.gef.util; -import java.io.IOException; +import java.util.Formatter; import org.eclipse.draw2d.IFigure; import org.eclipse.gef.ConnectionEditPart; @@ -11,14 +11,22 @@ public class EditPartFormatter extends FormatterImpl<EditPart> { - public void format(Appendable appendable, EditPart editPart, int indent) throws IOException { + public EditPartFormatter(Appendable appendable) { + super(appendable); + } - appendable.append(editPart.toString()); // Includes class name and model. - appendState(appendable, editPart); + public void format(EditPart editPart, int indent) { + + indent(indent); + printf(editPart.toString()); // Includes class name and model. + printText(editPart); + printState(editPart); + println(); + printModel(editPart, indent + 1); if (editPart instanceof GraphicalEditPart) - appendGraphical(appendable, (GraphicalEditPart) editPart); + printGraphical((GraphicalEditPart) editPart, indent + 1); if (editPart instanceof ConnectionEditPart) - appendConnection(appendable, (ConnectionEditPart) editPart); + printConnection((ConnectionEditPart) editPart, indent + 1); // Useful? // if (editPart instanceof NodeEditPart) // appendNode(appendable, (NodeEditPart) editPart); @@ -28,65 +36,95 @@ // appendNode(appendable, (TreeEditPart) editPart); } - private void appendConnection(Appendable appendable, ConnectionEditPart editPart) - throws IOException { - appendEditPart(appendable, editPart.getSource(), "source"); - appendEditPart(appendable, editPart.getTarget(), "target"); + private void printConnection(ConnectionEditPart editPart, int indent) { + printEditPart(editPart.getSource(), "source", indent + 1); + printEditPart(editPart.getTarget(), "target", indent + 1); } - private void appendEditPart(Appendable appendable, EditPart editPart, String label) - throws IOException { - appendable.append(' '); - appendable.append(label); - appendable.append(':'); - if (editPart == null) { - appendable.append("*none*"); - } else { - format(appendable, editPart, 0); + private void printModel(EditPart editPart, int indent) { + indent(indent); + Object model = editPart.getModel(); + printf("model: %s\n", model); + } + + private void printEditPart(EditPart editPart, String label, int indent) { + indent(indent); + printf("%s: %s\n", label, editPart); + } + + private static class ListFormatter { + + private final String opener; + + private final String closer; + + private final String separator; + + private final Formatter formatter; + + private boolean first = true; + + public ListFormatter(String opener, String closer, String separator, Formatter formatter) { + this.opener = opener; + this.closer = closer; + this.separator = separator; + this.formatter = formatter; } + + public void printf(String format, Object... args) { + if (first) { + first = false; + formatter.format(opener); + } else { + formatter.format(separator); + } + formatter.format(format, args); + } + + public void close() { + formatter.format(closer); + } } - private void appendState(Appendable appendable, EditPart editPart) throws IOException { + private void printState(EditPart editPart) { - appendable.append(" ["); + ListFormatter list = new ListFormatter("[", "]", ",", formatter); if (editPart.isActive()) - appendable.append(" active"); + list.printf("active"); if (editPart.hasFocus()) - appendable.append(" focus"); + list.printf("focus"); if (editPart.isSelectable()) - appendable.append(" selectable"); + list.printf("selectable"); int selected = editPart.getSelected(); switch (selected) { case EditPart.SELECTED_NONE: break; case EditPart.SELECTED: - appendable.append("selected"); + list.printf("selected"); break; case EditPart.SELECTED_PRIMARY: - appendable.append("selected-primary"); + list.printf("selected-primary"); break; default: - appendable.append(String.format("selected:%d?", selected)); + list.printf(String.format("selected:%d?", selected)); break; } - appendable.append(']'); + list.close(); } - private void appendGraphical(Appendable appendable, GraphicalEditPart editPart) - throws IOException { - appendable.append(" ("); + private void printGraphical(GraphicalEditPart editPart, int indent) { IFigure figure = editPart.getFigure(); if (figure == null) { - appendable.append("*no figure*"); + indent(indent); + printf("*no figure*\n"); } else { - new FigureFormatter().format(appendable, editPart.getFigure(), 0); + new FigureFormatter(appendable).format(editPart.getFigure(), indent); } - appendable.append(')'); } } Added: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/EditPartHierarchyPrinter.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/EditPartHierarchyPrinter.java (rev 0) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/EditPartHierarchyPrinter.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -0,0 +1,13 @@ +package abbot.swt.gef.util; + +import org.eclipse.gef.EditPart; + +import abbot.swt.finder.generic.HierarchyPrinter; +import abbot.swt.gef.finder.EditPartHierarchy; + +public class EditPartHierarchyPrinter extends HierarchyPrinter<EditPart> { + + public EditPartHierarchyPrinter(EditPartHierarchy hierarchy, Appendable appendable) { + super(hierarchy, new EditPartFormatter(appendable)); + } +} Modified: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/FigureFormatter.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/FigureFormatter.java 2007-06-21 14:12:46 UTC (rev 2432) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/FigureFormatter.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -1,37 +1,41 @@ package abbot.swt.gef.util; -import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.swt.graphics.Color; import abbot.swt.finder.generic.FormatterImpl; public class FigureFormatter extends FormatterImpl<IFigure> { - public void format(Appendable appendable, IFigure figure, int indent) throws IOException { - appendable.append('>'); - appendable.append(getClassName(figure)); - appendStyle(appendable, figure); - appendLocation(appendable, figure); + public FigureFormatter(Appendable appendable) { + super(appendable); } + public void format(IFigure figure, int indent) { + indent(indent); + printf(getClassName(figure)); + printText(figure); + printStyle(figure); + printLocation(figure); + println(); + } + private String getClassName(IFigure figure) { String className = figure.getClass().getName(); String[] prefixes = { "org.eclipse.draw2d.", "org.eclipse.gef." }; for (int i = 0; i < prefixes.length; i++) { String prefix = prefixes[i]; if (className.startsWith(prefix)) - return "*." + className.substring(prefix.length()); + return className.substring(prefix.length()); } return className; } - private void appendStyle(Appendable appendable, IFigure figure) throws IOException { + private void printStyle(IFigure figure) { List styles = new ArrayList(); if (figure.isVisible()) @@ -40,10 +44,10 @@ styles.add("enabled"); if (figure.isShowing()) styles.add("showing"); - styles.add(getColor("fg", figure.getForegroundColor())); - styles.add(getColor("bg", figure.getBackgroundColor())); + // styles.add(getColor("fg", figure.getForegroundColor())); + // styles.add(getColor("bg", figure.getBackgroundColor())); - appendable.append(" ["); + printf(" ["); boolean first = true; for (Iterator iterator = styles.iterator(); iterator.hasNext();) { @@ -51,23 +55,23 @@ if (first) { first = false; } else { - appendable.append(','); + print(','); } - appendable.append(style.toString()); + printf(style.toString()); } - appendable.append(']'); + print(']'); } - private void appendLocation(Appendable appendable, IFigure figure) throws IOException { + protected void printLocation(IFigure figure) { Rectangle bounds = figure.getBounds(); org.eclipse.swt.graphics.Rectangle rectangle = new org.eclipse.swt.graphics.Rectangle( bounds.x, bounds.y, bounds.width, bounds.height); - appendLocation(appendable, rectangle); + super.printLocation(rectangle); } - private String getColor(String tag, Color color) { - return String.format("%s(%02x,%02x,%02x)", tag, color.getRed(), color.getGreen(), color - .getBlue()); - } + // private String getColor(String tag, Color color) { + // return String.format("%s(%02x,%02x,%02x)", tag, color.getRed(), color.getGreen(), color + // .getBlue()); + // } } Modified: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/FigureHierarchyPrinter.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/FigureHierarchyPrinter.java 2007-06-21 14:12:46 UTC (rev 2432) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/FigureHierarchyPrinter.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -7,8 +7,7 @@ public class FigureHierarchyPrinter extends HierarchyPrinter<IFigure> { - public FigureHierarchyPrinter(Appendable appendable, FigureHierarchy hierarchy) { - super(appendable, hierarchy, new FigureFormatter()); + public FigureHierarchyPrinter(FigureHierarchy hierarchy, Appendable appendable) { + super(hierarchy, new FigureFormatter(appendable)); } - } Added: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/WidgetEditPartHierarchyPrinter.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/WidgetEditPartHierarchyPrinter.java (rev 0) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/WidgetEditPartHierarchyPrinter.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -0,0 +1,72 @@ +package abbot.swt.gef.util; + +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.LightweightSystem; +import org.eclipse.draw2d.Viewport; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.RootEditPart; +import org.eclipse.swt.widgets.Widget; + +import abbot.swt.finder.WidgetHierarchy; +import abbot.swt.gef.finder.EditPartHierarchy; +import abbot.swt.gef.finder.EditPartHierarchyImpl; +import abbot.swt.gef.tester.FigureTester; +import abbot.swt.utilities.WidgetFormatter; +import abbot.swt.utilities.WidgetHierarchyPrinter; + +public class WidgetEditPartHierarchyPrinter extends WidgetHierarchyPrinter { + + public WidgetEditPartHierarchyPrinter(WidgetHierarchy hierarchy, Appendable appendable) { + super(hierarchy, new WidgetEditPartFormatter(appendable)); + } + + private static class WidgetEditPartFormatter extends WidgetFormatter { + + public WidgetEditPartFormatter(Appendable appendable) { + super(appendable); + } + + public void format(Widget widget, int indent) { + + // Let the super do its thing. + super.format(widget, indent); + + // If it's a FigureCanvas, dive into the EditPart hierarchy. + if (widget instanceof FigureCanvas) { + formatFigureCanvas((FigureCanvas) widget, indent + 1); + } + } + + private void formatFigureCanvas(final FigureCanvas canvas, final int indent) { + + // Viewport + Viewport viewport = canvas.getViewport(); + indent(indent); + printf("viewport: %s\n", viewport); + + // Lightweight system + LightweightSystem system = canvas.getLightweightSystem(); + indent(indent); + printf("lightweight system: %s (root: %s)\n", system, system.getRootFigure()); + + IFigure root = canvas.getContents(); + EditPartViewer viewer = FigureTester.getFigureTester().findViewer(root); + indent(indent); + printf("viewer: %s\n", viewer); + if (viewer != null) { + RootEditPart rootEditPart = viewer.getRootEditPart(); + EditPartHierarchy hierarchy = new EditPartHierarchyImpl(rootEditPart); + EditPartHierarchyPrinter printer = new EditPartHierarchyPrinter(hierarchy, appendable); + printer.print(indent); + } + + // Contents +// FigureHierarchy hierarchy = new FigureHierarchyImpl(root); +// FigureHierarchyPrinter printer = new FigureHierarchyPrinter(hierarchy, appendable); +// printer.print(indent); + } + + } + +} Added: abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/WidgetFigureHierarchyPrinter.java =================================================================== --- abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/WidgetFigureHierarchyPrinter.java (rev 0) +++ abbot.swt/trunk/abbot.swt.gef/src/abbot/swt/gef/util/WidgetFigureHierarchyPrinter.java 2007-06-21 14:12:53 UTC (rev 2433) @@ -0,0 +1,59 @@ +package abbot.swt.gef.util; + +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.LightweightSystem; +import org.eclipse.draw2d.Viewport; +import org.eclipse.swt.widgets.Widget; + +import abbot.swt.finder.WidgetHierarchy; +import abbot.swt.gef.finder.FigureHierarchy; +import abbot.swt.gef.finder.FigureHierarchyImpl; +import abbot.swt.utilities.WidgetFormatter; +import abbot.swt.utilities.WidgetHierarchyPrinter; + +public class WidgetFigureHierarchyPrinter extends WidgetHierarchyPrinter { + + public WidgetFigureHierarchyPrinter(WidgetHierarchy hierarchy, Appendable appendable) { + super(hierarchy, new WidgetFigureFormatter(appendable)); + } + + private static class WidgetFigureFormatter extends WidgetFormatter { + + public WidgetFigureFormatter(Appendable appendable) { + super(appendable); + } + + public void format(Widget widget, int indent) { + + // Let the super do its thing. + super.format(widget, indent); + + // If it's a FigureCanvas, dive into the IFigure hierarchy. + if (widget instanceof FigureCanvas) { + formatFigureCanvas((FigureCanvas) widget, indent + 1); + } + } + + private void formatFigureCanvas(final FigureCanvas canvas, final int indent) { + + // Viewport + Viewport viewport = canvas.getViewport(); + indent(indent); + printf("viewport: %s\n", viewport); + + // Lightweight system + LightweightSystem system = canvas.getLightweightSystem(); + indent(indent); + printf("lightweight system: %s (root: %s)\n", system, system.getRootFigure()); + + // Contents + IFigure root = canvas.getContents(); + FigureHierarchy hierarchy = new FigureHierarchyImpl(root); + FigureHierarchyPrinter printer = new FigureHierarchyPrinter(hierarchy, appendable); + printer.print(indent); + } + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |