From 5da1b6b2c8d1ab0859ffc7d4065667cb4ba29b9c Mon Sep 17 00:00:00 2001 From: Alois Zoitl Date: Fri, 29 Mar 2024 22:31:37 +0100 Subject: [PATCH] Final Clean-up of shapes example. Mostly externalize strings --- .../META-INF/MANIFEST.MF | 2 +- .../eclipse/gef/examples/shapes/Messages.java | 28 ++++++++++ .../examples/shapes/ShapesCreationWizard.java | 16 +++--- .../gef/examples/shapes/ShapesEditor.java | 9 ++-- .../shapes/ShapesEditorPaletteFactory.java | 30 +++++------ .../shapes/ShapesExampleMessages.java | 54 +++++++++++++++++++ .../gef/examples/shapes/messages.properties | 27 ++++++++++ .../gef/examples/shapes/model/Connection.java | 6 +-- .../shapes/model/EllipticalShape.java | 8 ++- .../shapes/model/RectangularShape.java | 8 ++- .../gef/examples/shapes/model/Shape.java | 11 ++-- .../examples/shapes/model/ShapesDiagram.java | 4 +- .../commands/ConnectionCreateCommand.java | 3 +- .../commands/ConnectionDeleteCommand.java | 3 +- .../commands/ConnectionReconnectCommand.java | 12 +++-- .../model/commands/ShapeCreateCommand.java | 3 +- .../model/commands/ShapeDeleteCommand.java | 3 +- .../commands/ShapeSetConstraintCommand.java | 3 +- .../shapes/parts/DiagramEditPart.java | 9 ++-- .../shapes/parts/DiagramTreeEditPart.java | 3 +- .../examples/shapes/parts/ShapeEditPart.java | 14 ++--- .../shapes/parts/ShapesEditPartFactory.java | 4 +- 22 files changed, 194 insertions(+), 66 deletions(-) create mode 100644 org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/Messages.java create mode 100644 org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesExampleMessages.java create mode 100644 org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/messages.properties diff --git a/org.eclipse.gef.examples.shapes/META-INF/MANIFEST.MF b/org.eclipse.gef.examples.shapes/META-INF/MANIFEST.MF index 280b52d7f..a62ed2f10 100644 --- a/org.eclipse.gef.examples.shapes/META-INF/MANIFEST.MF +++ b/org.eclipse.gef.examples.shapes/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Plugin.name Bundle-SymbolicName: org.eclipse.gef.examples.shapes; singleton:=true -Bundle-Version: 3.14.300.qualifier +Bundle-Version: 3.15.0.qualifier Bundle-Activator: org.eclipse.gef.examples.shapes.ShapesPlugin Bundle-Vendor: %Plugin.providerName Bundle-Localization: plugin diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/Messages.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/Messages.java new file mode 100644 index 000000000..fb5407479 --- /dev/null +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/Messages.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2024 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.gef.examples.shapes; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$ + public static String ShapeSetConstraintCommand_MoveResize; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesCreationWizard.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesCreationWizard.java index 79b87531c..e23405f09 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesCreationWizard.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesCreationWizard.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.ObjectOutputStream; +import java.text.MessageFormat; import org.eclipse.swt.widgets.Composite; @@ -80,7 +81,7 @@ public boolean performFinish() { * This WizardPage can create an empty .shapes file for the ShapesEditor. */ private class CreationPage extends WizardNewFileCreationPage { - private static final String DEFAULT_EXTENSION = ".shapes"; + private static final String DEFAULT_EXTENSION = ".shapes"; //$NON-NLS-1$ private final IWorkbench workbench; /** @@ -91,10 +92,12 @@ private class CreationPage extends WizardNewFileCreationPage { * @see ShapesCreationWizard#init(IWorkbench, IStructuredSelection) */ CreationPage(IWorkbench workbench, IStructuredSelection selection) { - super("shapeCreationPage1", selection); + super("shapeCreationPage1", selection); //$NON-NLS-1$ this.workbench = workbench; - setTitle("Create a new " + DEFAULT_EXTENSION + " file"); - setDescription("Create a new " + DEFAULT_EXTENSION + " file"); + setTitle( + MessageFormat.format(ShapesExampleMessages.ShapesCreationWizard_CreateANewFile, DEFAULT_EXTENSION)); + setDescription( + MessageFormat.format(ShapesExampleMessages.ShapesCreationWizard_CreateANewFile, DEFAULT_EXTENSION)); } /* @@ -106,7 +109,7 @@ private class CreationPage extends WizardNewFileCreationPage { @Override public void createControl(Composite parent) { super.createControl(parent); - setFileName("shapesExample" + fileCount + DEFAULT_EXTENSION); + setFileName("shapesExample" + fileCount + DEFAULT_EXTENSION); //$NON-NLS-1$ setPageComplete(validatePage()); } @@ -167,7 +170,8 @@ private boolean validateFilename() { if (getFileName() != null && getFileName().endsWith(DEFAULT_EXTENSION)) { return true; } - setErrorMessage("The 'file' name must end with " + DEFAULT_EXTENSION); + setErrorMessage(MessageFormat.format(ShapesExampleMessages.ShapesCreationWizard_FileNameMustEndWith, + DEFAULT_EXTENSION)); return false; } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesEditor.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesEditor.java index e30c0f1dc..23a85442a 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesEditor.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesEditor.java @@ -246,6 +246,7 @@ public void execute(final IProgressMonitor monitor) { } catch (InterruptedException ie) { // should not happen, since the monitor dialog is not cancelable ie.printStackTrace(); + Thread.currentThread().interrupt(); } catch (InvocationTargetException ite) { ite.printStackTrace(); } @@ -279,7 +280,7 @@ protected PaletteRoot getPaletteRoot() { } private void handleLoadException(Exception e) { - System.err.println("** Load failed. Using default model. **"); + System.err.println("** Load failed. Using default model. **"); //$NON-NLS-1$ e.printStackTrace(); diagram = new ShapesDiagram(); } @@ -321,11 +322,7 @@ protected void setInput(IEditorInput input) { try (ObjectInputStream in = new ObjectInputStream(file.getContents())) { diagram = (ShapesDiagram) in.readObject(); setPartName(file.getName()); - } catch (IOException e) { - handleLoadException(e); - } catch (CoreException e) { - handleLoadException(e); - } catch (ClassNotFoundException e) { + } catch (IOException | CoreException | ClassNotFoundException e) { handleLoadException(e); } } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesEditorPaletteFactory.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesEditorPaletteFactory.java index bd2db4095..66c2f75b8 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesEditorPaletteFactory.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesEditorPaletteFactory.java @@ -40,18 +40,18 @@ final class ShapesEditorPaletteFactory { /** Create the "Shapes" drawer. */ private static PaletteContainer createShapesDrawer() { - PaletteDrawer componentsDrawer = new PaletteDrawer("Shapes"); + PaletteDrawer componentsDrawer = new PaletteDrawer(ShapesExampleMessages.ShapesEditorPaletteFactory_Shapes); - CombinedTemplateCreationEntry component = new CombinedTemplateCreationEntry("Ellipse", - "Create an elliptical shape", EllipticalShape.class, new SimpleFactory<>(EllipticalShape.class), - ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/ellipse16.gif"), - ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/ellipse24.gif")); + CombinedTemplateCreationEntry component = new CombinedTemplateCreationEntry(ShapesExampleMessages.ShapesEditorPaletteFactory_Ellipse, + ShapesExampleMessages.ShapesEditorPaletteFactory_CreateEllipticalShape, EllipticalShape.class, new SimpleFactory<>(EllipticalShape.class), + ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/ellipse16.gif"), //$NON-NLS-1$ + ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/ellipse24.gif")); //$NON-NLS-1$ componentsDrawer.add(component); - component = new CombinedTemplateCreationEntry("Rectangle", "Create a rectangular shape", RectangularShape.class, + component = new CombinedTemplateCreationEntry(ShapesExampleMessages.ShapesEditorPaletteFactory_Rectangle, ShapesExampleMessages.ShapesEditorPaletteFactory_CreateRectangularShape, RectangularShape.class, new SimpleFactory<>(RectangularShape.class), - ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/rectangle16.gif"), - ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/rectangle24.gif")); + ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/rectangle16.gif"), //$NON-NLS-1$ + ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/rectangle24.gif")); //$NON-NLS-1$ componentsDrawer.add(component); return componentsDrawer; @@ -72,7 +72,7 @@ static PaletteRoot createPalette() { /** Create the "Tools" group. */ private static PaletteContainer createToolsGroup(PaletteRoot palette) { - PaletteToolbar toolbar = new PaletteToolbar("Tools"); + PaletteToolbar toolbar = new PaletteToolbar(ShapesExampleMessages.ShapesEditorPaletteFactory_Tools); // Add a selection tool to the group ToolEntry tool = new PanningSelectionToolEntry(); @@ -83,7 +83,7 @@ private static PaletteContainer createToolsGroup(PaletteRoot palette) { toolbar.add(new MarqueeToolEntry()); // Add (solid-line) connection tool - tool = new ConnectionCreationToolEntry("Solid connection", "Create a solid-line connection", + tool = new ConnectionCreationToolEntry(ShapesExampleMessages.ShapesEditorPaletteFactory_SolidConnection, ShapesExampleMessages.ShapesEditorPaletteFactory_CreateSolidLineConnection, new CreationFactory() { @Override public Object getNewObject() { @@ -96,12 +96,12 @@ public Object getNewObject() { public Object getObjectType() { return Connection.SOLID_CONNECTION; } - }, ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_s16.gif"), - ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_s24.gif")); + }, ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_s16.gif"), //$NON-NLS-1$ + ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_s24.gif")); //$NON-NLS-1$ toolbar.add(tool); // Add (dashed-line) connection tool - tool = new ConnectionCreationToolEntry("Dashed connection", "Create a dashed-line connection", + tool = new ConnectionCreationToolEntry(ShapesExampleMessages.ShapesEditorPaletteFactory_DashedConnection, ShapesExampleMessages.ShapesEditorPaletteFactory_CreateDashedLineConnection, new CreationFactory() { @Override public Object getNewObject() { @@ -114,8 +114,8 @@ public Object getNewObject() { public Object getObjectType() { return Connection.DASHED_CONNECTION; } - }, ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_d16.gif"), - ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_d24.gif")); + }, ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_d16.gif"), //$NON-NLS-1$ + ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_d24.gif")); //$NON-NLS-1$ toolbar.add(tool); return toolbar; diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesExampleMessages.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesExampleMessages.java new file mode 100644 index 000000000..cda0e51f3 --- /dev/null +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/ShapesExampleMessages.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University Linz. + * + * 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: + * Alois Zoitl - initial API and implementation + *******************************************************************************/ + +package org.eclipse.gef.examples.shapes; + +import org.eclipse.osgi.util.NLS; + +@SuppressWarnings("squid:S3008") // tell sonar the java naming convention does not make sense for this class +public class ShapesExampleMessages extends NLS { + private static final String BUNDLE_NAME = ShapesExampleMessages.class.getPackageName() + ".messages"; //$NON-NLS-1$ + public static String ConnectionCreateCommand_ConnectionCreation; + public static String ConnectionDeleteCommand_ConnectionDeletion; + public static String ConnectionReconnectCommand_MoveConnectionEndPoint; + public static String ConnectionReconnectCommand_MoveConnectionStartPoint; + public static String EllipticalShape_Ellipse; + public static String RectangularShape_Rectangle; + public static String Shape_Height; + public static String Shape_NotANumber; + public static String Shape_ValueMustBeGreaterOrEqualZero; + public static String Shape_Width; + public static String Shape_X; + public static String Shape_Y; + public static String ShapeCreateCommand_ShapeCreation; + public static String ShapeDeleteCommand_ShapeDeletion; + public static String ShapesCreationWizard_CreateANewFile; + public static String ShapesCreationWizard_FileNameMustEndWith; + public static String ShapesEditorPaletteFactory_CreateDashedLineConnection; + public static String ShapesEditorPaletteFactory_CreateEllipticalShape; + public static String ShapesEditorPaletteFactory_CreateRectangularShape; + public static String ShapesEditorPaletteFactory_CreateSolidLineConnection; + public static String ShapesEditorPaletteFactory_DashedConnection; + public static String ShapesEditorPaletteFactory_Ellipse; + public static String ShapesEditorPaletteFactory_Rectangle; + public static String ShapesEditorPaletteFactory_Shapes; + public static String ShapesEditorPaletteFactory_SolidConnection; + public static String ShapesEditorPaletteFactory_Tools; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, ShapesExampleMessages.class); + } + + private ShapesExampleMessages() { + } +} diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/messages.properties b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/messages.properties new file mode 100644 index 000000000..eb0eb9908 --- /dev/null +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/messages.properties @@ -0,0 +1,27 @@ +ConnectionCreateCommand_ConnectionCreation=connection creation +ConnectionDeleteCommand_ConnectionDeletion=connection deletion +ConnectionReconnectCommand_MoveConnectionEndPoint=move connection endpoint +ConnectionReconnectCommand_MoveConnectionStartPoint=move connection startpoint +EllipticalShape_Ellipse=Ellipse {0} +RectangularShape_Rectangle=Rectangle {0} +Shape_Height=Height +Shape_NotANumber=Not a number +Shape_ValueMustBeGreaterOrEqualZero=Value must be >= 0 +Shape_Width=Width +Shape_X=X +Shape_Y=Y +ShapeCreateCommand_ShapeCreation=shape creation +ShapeDeleteCommand_ShapeDeletion=shape deletion +ShapesCreationWizard_CreateANewFile=Create a new {0} file +ShapesCreationWizard_FileNameMustEndWith=The ''file'' name must end with {0} +ShapesEditorPaletteFactory_CreateDashedLineConnection=Create a dashed-line connection +ShapesEditorPaletteFactory_CreateEllipticalShape=Create an elliptical shape +ShapesEditorPaletteFactory_CreateRectangularShape=Create a rectangular shape +ShapesEditorPaletteFactory_CreateSolidLineConnection=Create a solid-line connection +ShapesEditorPaletteFactory_DashedConnection=Dashed connection +ShapesEditorPaletteFactory_Ellipse=Ellipse +ShapesEditorPaletteFactory_Rectangle=Rectangle +ShapesEditorPaletteFactory_Shapes=Shapes +ShapesEditorPaletteFactory_SolidConnection=Solid connection +ShapesEditorPaletteFactory_Tools=Tools +ShapeSetConstraintCommand_MoveResize=move / resize diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/Connection.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/Connection.java index 7f18bc78b..3dc099884 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/Connection.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/Connection.java @@ -38,10 +38,10 @@ public class Connection extends ModelElement { */ public static final Integer DASHED_CONNECTION = Integer.valueOf(Graphics.LINE_DASH); /** Property ID to use when the line style of this connection is modified. */ - public static final String LINESTYLE_PROP = "LineStyle"; + public static final String LINESTYLE_PROP = "LineStyle"; //$NON-NLS-1$ private static final IPropertyDescriptor[] descriptors = new IPropertyDescriptor[1]; - private static final String SOLID_STR = "Solid"; - private static final String DASHED_STR = "Dashed"; + private static final String SOLID_STR = "Solid"; //$NON-NLS-1$ + private static final String DASHED_STR = "Dashed"; //$NON-NLS-1$ private static final long serialVersionUID = 1; /** True, if the connection is attached to its endpoints. */ diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/EllipticalShape.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/EllipticalShape.java index 4dc629530..92cae89d9 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/EllipticalShape.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/EllipticalShape.java @@ -12,8 +12,12 @@ *******************************************************************************/ package org.eclipse.gef.examples.shapes.model; +import java.text.MessageFormat; + import org.eclipse.swt.graphics.Image; +import org.eclipse.gef.examples.shapes.ShapesExampleMessages; + /** * An elliptical shape. * @@ -22,7 +26,7 @@ public class EllipticalShape extends Shape { /** A 16x16 pictogram of an elliptical shape. */ - private static final Image ELLIPSE_ICON = createImage("icons/ellipse16.gif"); + private static final Image ELLIPSE_ICON = createImage("icons/ellipse16.gif"); //$NON-NLS-1$ private static final long serialVersionUID = 1; @@ -33,6 +37,6 @@ public Image getIcon() { @Override public String toString() { - return "Ellipse " + hashCode(); + return MessageFormat.format(ShapesExampleMessages.EllipticalShape_Ellipse, hashCode()); } } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/RectangularShape.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/RectangularShape.java index ac291d6ff..d53a5aaaa 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/RectangularShape.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/RectangularShape.java @@ -12,8 +12,12 @@ *******************************************************************************/ package org.eclipse.gef.examples.shapes.model; +import java.text.MessageFormat; + import org.eclipse.swt.graphics.Image; +import org.eclipse.gef.examples.shapes.ShapesExampleMessages; + /** * A rectangular shape. * @@ -21,7 +25,7 @@ */ public class RectangularShape extends Shape { /** A 16x16 pictogram of a rectangular shape. */ - private static final Image RECTANGLE_ICON = createImage("icons/rectangle16.gif"); + private static final Image RECTANGLE_ICON = createImage("icons/rectangle16.gif"); //$NON-NLS-1$ private static final long serialVersionUID = 1; @@ -32,6 +36,6 @@ public Image getIcon() { @Override public String toString() { - return "Rectangle " + hashCode(); + return MessageFormat.format(ShapesExampleMessages.RectangularShape_Rectangle, hashCode()); } } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/Shape.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/Shape.java index 05d455f8a..fac902585 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/Shape.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/Shape.java @@ -26,6 +26,7 @@ import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.examples.shapes.ShapesExampleMessages; import org.eclipse.gef.examples.shapes.ShapesPlugin; /** @@ -89,9 +90,9 @@ public abstract class Shape extends ModelElement { * @see #setPropertyValue(Object, Object) */ static { - descriptors = new IPropertyDescriptor[] { new TextPropertyDescriptor(XPOS_PROP, "X"), // id and description pair - new TextPropertyDescriptor(YPOS_PROP, "Y"), new TextPropertyDescriptor(WIDTH_PROP, "Width"), - new TextPropertyDescriptor(HEIGHT_PROP, "Height"), }; + descriptors = new IPropertyDescriptor[] { new TextPropertyDescriptor(XPOS_PROP, ShapesExampleMessages.Shape_X), // id and description pair + new TextPropertyDescriptor(YPOS_PROP, ShapesExampleMessages.Shape_Y), new TextPropertyDescriptor(WIDTH_PROP, ShapesExampleMessages.Shape_Width), + new TextPropertyDescriptor(HEIGHT_PROP, ShapesExampleMessages.Shape_Height), }; // use a custom cell editor validator for all four array entries for (IPropertyDescriptor descriptor : descriptors) { ((PropertyDescriptor) descriptor).setValidator(value -> { @@ -99,9 +100,9 @@ public abstract class Shape extends ModelElement { try { intValue = Integer.parseInt((String) value); } catch (NumberFormatException exc) { - return "Not a number"; + return ShapesExampleMessages.Shape_NotANumber; } - return (intValue >= 0) ? null : "Value must be >= 0"; + return (intValue >= 0) ? null : ShapesExampleMessages.Shape_ValueMustBeGreaterOrEqualZero; }); } } // static diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/ShapesDiagram.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/ShapesDiagram.java index cbae80b40..511c0a0c9 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/ShapesDiagram.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/ShapesDiagram.java @@ -24,9 +24,9 @@ public class ShapesDiagram extends ModelElement { /** Property ID to use when a child is added to this diagram. */ - public static final String CHILD_ADDED_PROP = "ShapesDiagram.ChildAdded"; + public static final String CHILD_ADDED_PROP = "ShapesDiagram.ChildAdded"; //$NON-NLS-1$ /** Property ID to use when a child is removed from this diagram. */ - public static final String CHILD_REMOVED_PROP = "ShapesDiagram.ChildRemoved"; + public static final String CHILD_REMOVED_PROP = "ShapesDiagram.ChildRemoved"; //$NON-NLS-1$ private static final long serialVersionUID = 1; private final List shapes = new ArrayList<>(); diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionCreateCommand.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionCreateCommand.java index 31741c6ec..61d9e1b2c 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionCreateCommand.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionCreateCommand.java @@ -14,6 +14,7 @@ import org.eclipse.gef.commands.Command; +import org.eclipse.gef.examples.shapes.ShapesExampleMessages; import org.eclipse.gef.examples.shapes.model.Connection; import org.eclipse.gef.examples.shapes.model.Shape; @@ -62,7 +63,7 @@ public ConnectionCreateCommand(Shape source, int lineStyle) { if (source == null) { throw new IllegalArgumentException(); } - setLabel("connection creation"); + setLabel(ShapesExampleMessages.ConnectionCreateCommand_ConnectionCreation); this.source = source; this.lineStyle = lineStyle; } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionDeleteCommand.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionDeleteCommand.java index 384fc3359..c63393f21 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionDeleteCommand.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionDeleteCommand.java @@ -14,6 +14,7 @@ import org.eclipse.gef.commands.Command; +import org.eclipse.gef.examples.shapes.ShapesExampleMessages; import org.eclipse.gef.examples.shapes.model.Connection; /** @@ -37,7 +38,7 @@ public ConnectionDeleteCommand(Connection conn) { if (conn == null) { throw new IllegalArgumentException(); } - setLabel("connection deletion"); + setLabel(ShapesExampleMessages.ConnectionDeleteCommand_ConnectionDeletion); this.connection = conn; } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionReconnectCommand.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionReconnectCommand.java index 4ed65b970..2b6a4877c 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionReconnectCommand.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ConnectionReconnectCommand.java @@ -14,6 +14,7 @@ import org.eclipse.gef.commands.Command; +import org.eclipse.gef.examples.shapes.ShapesExampleMessages; import org.eclipse.gef.examples.shapes.model.Connection; import org.eclipse.gef.examples.shapes.model.Shape; @@ -48,7 +49,7 @@ public class ConnectionReconnectCommand extends Command { /** The connection instance to reconnect. */ - private Connection connection; + private final Connection connection; /** The new source endpoint. */ private Shape newSource; /** The new target endpoint. */ @@ -83,7 +84,8 @@ public ConnectionReconnectCommand(Connection conn) { public boolean canExecute() { if (newSource != null) { return checkSourceReconnection(); - } else if (newTarget != null) { + } + if (newTarget != null) { return checkTargetReconnection(); } return false; @@ -128,7 +130,7 @@ public void execute() { } else if (newTarget != null) { connection.reconnect(oldSource, newTarget); } else { - throw new IllegalStateException("Should not happen"); + throw new IllegalStateException("Should not happen"); //$NON-NLS-1$ } } @@ -150,7 +152,7 @@ public void setNewSource(Shape connectionSource) { if (connectionSource == null) { throw new IllegalArgumentException(); } - setLabel("move connection startpoint"); + setLabel(ShapesExampleMessages.ConnectionReconnectCommand_MoveConnectionStartPoint); newSource = connectionSource; newTarget = null; } @@ -173,7 +175,7 @@ public void setNewTarget(Shape connectionTarget) { if (connectionTarget == null) { throw new IllegalArgumentException(); } - setLabel("move connection endpoint"); + setLabel(ShapesExampleMessages.ConnectionReconnectCommand_MoveConnectionEndPoint); newSource = null; newTarget = connectionTarget; } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeCreateCommand.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeCreateCommand.java index dd8197fb3..005407bd7 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeCreateCommand.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeCreateCommand.java @@ -17,6 +17,7 @@ import org.eclipse.gef.commands.Command; +import org.eclipse.gef.examples.shapes.ShapesExampleMessages; import org.eclipse.gef.examples.shapes.model.Shape; import org.eclipse.gef.examples.shapes.model.ShapesDiagram; @@ -49,7 +50,7 @@ public ShapeCreateCommand(Shape newShape, ShapesDiagram parent, Rectangle bounds this.newShape = newShape; this.parent = parent; this.bounds = bounds; - setLabel("shape creation"); + setLabel(ShapesExampleMessages.ShapeCreateCommand_ShapeCreation); } /** diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeDeleteCommand.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeDeleteCommand.java index 2b4552f1a..9fea2d68d 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeDeleteCommand.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeDeleteCommand.java @@ -16,6 +16,7 @@ import org.eclipse.gef.commands.Command; +import org.eclipse.gef.examples.shapes.ShapesExampleMessages; import org.eclipse.gef.examples.shapes.model.Connection; import org.eclipse.gef.examples.shapes.model.Shape; import org.eclipse.gef.examples.shapes.model.ShapesDiagram; @@ -50,7 +51,7 @@ public ShapeDeleteCommand(ShapesDiagram parent, Shape child) { if (parent == null || child == null) { throw new IllegalArgumentException(); } - setLabel("shape deletion"); + setLabel(ShapesExampleMessages.ShapeDeleteCommand_ShapeDeletion); this.parent = parent; this.child = child; } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeSetConstraintCommand.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeSetConstraintCommand.java index 0f37697f3..460e16776 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeSetConstraintCommand.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/model/commands/ShapeSetConstraintCommand.java @@ -18,6 +18,7 @@ import org.eclipse.gef.commands.Command; import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gef.examples.shapes.Messages; import org.eclipse.gef.examples.shapes.model.Shape; /** @@ -51,7 +52,7 @@ public ShapeSetConstraintCommand(Shape shape, ChangeBoundsRequest req, Rectangle this.shape = shape; this.request = req; this.newBounds = newBounds.getCopy(); - setLabel("move / resize"); + setLabel(Messages.ShapeSetConstraintCommand_MoveResize); } /* diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/DiagramEditPart.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/DiagramEditPart.java index 40c8a0403..3f4746fcb 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/DiagramEditPart.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/DiagramEditPart.java @@ -116,8 +116,9 @@ public void deactivate() { } } - private ShapesDiagram getCastedModel() { - return (ShapesDiagram) getModel(); + @Override + public ShapesDiagram getModel() { + return (ShapesDiagram) super.getModel(); } /* @@ -126,8 +127,8 @@ private ShapesDiagram getCastedModel() { * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren() */ @Override - protected List getModelChildren() { - return getCastedModel().getChildren(); // return a list of shapes + protected List getModelChildren() { + return getModel().getChildren(); // return a list of shapes } /* diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/DiagramTreeEditPart.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/DiagramTreeEditPart.java index 2558d69cd..9976f1465 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/DiagramTreeEditPart.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/DiagramTreeEditPart.java @@ -23,6 +23,7 @@ import org.eclipse.gef.editpolicies.RootComponentEditPolicy; import org.eclipse.gef.examples.shapes.model.ModelElement; +import org.eclipse.gef.examples.shapes.model.Shape; import org.eclipse.gef.examples.shapes.model.ShapesDiagram; /** @@ -105,7 +106,7 @@ private EditPart getEditPartForChild(Object child) { * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren() */ @Override - protected List getModelChildren() { + protected List getModelChildren() { return getModel().getChildren(); // a list of shapes } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/ShapeEditPart.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/ShapeEditPart.java index dea6d9230..82e5dbdf6 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/ShapeEditPart.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/ShapeEditPart.java @@ -162,12 +162,12 @@ protected IFigure createFigure() { private IFigure createFigureForModel() { if (getModel() instanceof EllipticalShape) { return new Ellipse(); - } else if (getModel() instanceof RectangularShape) { + } + if (getModel() instanceof RectangularShape) { return new RectangleFigure(); - } else { - // if Shapes gets extended the conditions above must be updated - throw new IllegalArgumentException(); } + // if Shapes gets extended the conditions above must be updated + throw new IllegalArgumentException(); } /** @@ -195,7 +195,7 @@ protected ConnectionAnchor getConnectionAnchor() { anchor = new ChopboxAnchor(getFigure()); } else { // if Shapes gets extended the conditions above must be updated - throw new IllegalArgumentException("unexpected model"); + throw new IllegalArgumentException("unexpected model"); //$NON-NLS-1$ } } return anchor; @@ -209,7 +209,7 @@ protected ConnectionAnchor getConnectionAnchor() { * () */ @Override - protected List getModelSourceConnections() { + protected List getModelSourceConnections() { return getModel().getSourceConnections(); } @@ -221,7 +221,7 @@ protected List getModelSourceConnections() { * () */ @Override - protected List getModelTargetConnections() { + protected List getModelTargetConnections() { return getModel().getTargetConnections(); } diff --git a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/ShapesEditPartFactory.java b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/ShapesEditPartFactory.java index 9765b25af..12609b7a9 100644 --- a/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/ShapesEditPartFactory.java +++ b/org.eclipse.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/parts/ShapesEditPartFactory.java @@ -56,8 +56,8 @@ private static EditPart getPartForElement(Object modelElement) { if (modelElement instanceof Connection) { return new ConnectionEditPart(); } - throw new RuntimeException("Can't create part for model element: " - + ((modelElement != null) ? modelElement.getClass().getName() : "null")); + throw new RuntimeException("Can't create part for model element: " //$NON-NLS-1$ + + ((modelElement != null) ? modelElement.getClass().getName() : "null")); //$NON-NLS-1$ } } \ No newline at end of file