From 83c0e5d1e4c89012ea6209abe9d813bd0e5a6df0 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Tue, 24 Dec 2024 12:09:34 +0100 Subject: [PATCH] Externalize Zest JFace examples --- .../org/eclipse/zest/examples/Messages.java | 32 +++++++++++++ .../jface/CustomFigureJFaceSnippet.java | 17 +++---- .../examples/jface/GraphJFaceSnippet1.java | 20 ++++---- .../examples/jface/GraphJFaceSnippet2.java | 31 +++++++------ .../examples/jface/GraphJFaceSnippet3.java | 7 +-- .../examples/jface/GraphJFaceSnippet4.java | 35 +++++++------- .../examples/jface/GraphJFaceSnippet5.java | 34 +++++++------- .../examples/jface/GraphJFaceSnippet6.java | 35 ++++++-------- .../examples/jface/GraphJFaceSnippet7.java | 46 ++++++++----------- .../examples/jface/GraphJFaceSnippet8.java | 16 ++++--- .../examples/jface/GraphJFaceSnippet9.java | 11 +++-- .../jface/ManhattanLayoutJFaceSnippet.java | 43 ++++++++--------- .../eclipse/zest/examples/messages.properties | 32 +++++++++++++ .../zest/tests/examples/GraphJFaceTests.java | 10 ++-- 14 files changed, 218 insertions(+), 151 deletions(-) diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/Messages.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/Messages.java index 98336a2f4..e16123986 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/Messages.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/Messages.java @@ -21,14 +21,45 @@ public class Messages extends NLS { public static String Paper; public static String Rock; public static String Scissors; + public static String Rock2Paper; + public static String Paper2Scissors; + public static String Scissors2Paper; + public static String Scissors2Rock; public static String Information; public static String Warning; public static String Error; public static String Root; + public static String One; + public static String Two; + public static String Three; + public static String First; + public static String Second; + public static String Third; + public static String Fourth; // public static String AnimationSnippet_Animate; public static String AnimationSnippet_Title; + public static String CustomFigureJFaceSnippet_Title; public static String CustomLayout_Title; + public static String GraphJFaceSnippet1_Title; + public static String GraphJFaceSnippet1_Reload; + public static String GraphJFaceSnippet2_Title; + public static String GraphJFaceSnippet3_Title; + public static String GraphJFaceSnippet4_Title; + public static String GraphJFaceSnippet5_Title; + public static String GraphJFaceSnippet5_Refresh; + public static String GraphJFaceSnippet6_Title; + public static String GraphJFaceSnippet6_Push; + public static String GraphJFaceSnippet7_Title; + public static String GraphJFaceSnippet7_Push; + public static String GraphJFaceSnippet7_Class; + public static String GraphJFaceSnippet7_Field_Columns; + public static String GraphJFaceSnippet7_Field_Rows; + public static String GraphJFaceSnippet7_Method_GetColumns; + public static String GraphJFaceSnippet7_Method_GetRows; + public static String GraphJFaceSnippet8_Title; + public static String GraphJFaceSnippet9_Title; + public static String GraphJFaceSnippet9_Reload; public static String GraphSnippet1_Title; public static String GraphSnippet10_Title; public static String GraphSnippet10_ChangeCurve; @@ -78,6 +109,7 @@ public class Messages extends NLS { public static String LayoutExample_Node2; public static String ManhattanLayoutGraphSnippet_Title; public static String ManhattanLayoutGraphSnippet_ChangeRouter; + public static String ManhattanLayoutJFaceSnippet_Title; public static String NestedGraphSnippet_Title; public static String NestedGraphSnippet_Container1; public static String NestedGraphSnippet_Container2; diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/CustomFigureJFaceSnippet.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/CustomFigureJFaceSnippet.java index ab0dfb42d..3e1c39205 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/CustomFigureJFaceSnippet.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/CustomFigureJFaceSnippet.java @@ -28,6 +28,7 @@ import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; import org.eclipse.zest.core.widgets.ILabeledFigure; import org.eclipse.zest.core.widgets.IStyleableFigure; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; import org.eclipse.draw2d.Graphics; @@ -113,21 +114,21 @@ static class MyContentProvider implements IGraphEntityContentProvider { @Override public Object[] getConnectedTo(Object entity) { - if (entity.equals("One")) { - return new Object[] { "Two" }; + if (entity.equals(Messages.One)) { + return new Object[] { Messages.Two }; } - if (entity.equals("Two")) { - return new Object[] { "Three" }; + if (entity.equals(Messages.Two)) { + return new Object[] { Messages.Three }; } - if (entity.equals("Three")) { - return new Object[] { "One" }; + if (entity.equals(Messages.Three)) { + return new Object[] { Messages.One }; } return null; } @Override public Object[] getElements(Object inputElement) { - return new String[] { "One", "Two", "Three" }; + return new String[] { Messages.One, Messages.Two, Messages.Three }; } @Override @@ -177,7 +178,7 @@ public IFigure getFigure(Object element) { public static void main(String[] args) { Display d = new Display(); Shell shell = new Shell(d); - shell.setText("CustomFigureJFaceSnippet"); + shell.setText(Messages.CustomFigureJFaceSnippet_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); viewer = new GraphViewer(shell, SWT.NONE); diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet1.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet1.java index e68b46650..faa1eb418 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet1.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet1.java @@ -26,6 +26,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.zest.core.viewers.GraphViewer; import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; /** @@ -47,21 +48,21 @@ static class MyContentProvider implements IGraphEntityContentProvider { @Override public Object[] getConnectedTo(Object entity) { - if (entity.equals("First")) { - return new Object[] { "Second" }; + if (entity.equals(Messages.First)) { + return new Object[] { Messages.Second }; } - if (entity.equals("Second")) { - return new Object[] { "Third" }; + if (entity.equals(Messages.Second)) { + return new Object[] { Messages.Third }; } - if (entity.equals("Third")) { - return new Object[] { "First" }; + if (entity.equals(Messages.Third)) { + return new Object[] { Messages.First }; } return null; } @Override public Object[] getElements(Object inputElement) { - return new String[] { "First", "Second", "Third" }; + return new String[] { Messages.First, Messages.Second, Messages.Third }; } public double getWeight(Object entity1, Object entity2) { @@ -110,8 +111,9 @@ public static void main(String[] args) { Display d = shell.getDisplay(); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); + shell.setText(Messages.GraphJFaceSnippet1_Title); Button button = new Button(shell, SWT.PUSH); - button.setText("Reload"); + button.setText(Messages.GraphJFaceSnippet1_Reload); button.addSelectionListener(new SelectionAdapter() { @Override @@ -125,7 +127,7 @@ public void widgetSelected(SelectionEvent e) { viewer.setContentProvider(new MyContentProvider()); viewer.setLabelProvider(new MyLabelProvider()); viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm()); - viewer.addSelectionChangedListener(event -> System.out.println("Selection changed: " + (event.getSelection()))); + viewer.addSelectionChangedListener(event -> System.out.println("Selection changed: " + (event.getSelection()))); //$NON-NLS-1$ viewer.setInput(new Object()); shell.open(); diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet2.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet2.java index 8499065cc..2ffd9b379 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet2.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet2.java @@ -22,6 +22,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.zest.core.viewers.GraphViewer; import org.eclipse.zest.core.viewers.IGraphContentProvider; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; /** @@ -43,29 +44,29 @@ static class MyContentProvider implements IGraphContentProvider { @Override public Object getDestination(Object rel) { - if ("Rock2Paper".equals(rel)) { - return "Rock"; - } else if ("Paper2Scissors".equals(rel)) { - return "Paper"; - } else if ("Scissors2Rock".equals(rel)) { - return "Scissors"; + if (Messages.Rock2Paper.equals(rel)) { + return Messages.Rock; + } else if (Messages.Paper2Scissors.equals(rel)) { + return Messages.Paper; + } else if (Messages.Scissors2Rock.equals(rel)) { + return Messages.Scissors; } return null; } @Override public Object[] getElements(Object input) { - return new Object[] { "Rock2Paper", "Paper2Scissors", "Scissors2Rock" }; + return new Object[] { Messages.Rock2Paper, Messages.Paper2Scissors, Messages.Scissors2Rock }; } @Override public Object getSource(Object rel) { - if ("Rock2Paper".equals(rel)) { - return "Paper"; - } else if ("Paper2Scissors".equals(rel)) { - return "Scissors"; - } else if ("Scissors2Rock".equals(rel)) { - return "Rock"; + if (Messages.Rock2Paper.equals(rel)) { + return Messages.Paper; + } else if (Messages.Paper2Scissors.equals(rel)) { + return Messages.Scissors; + } else if (Messages.Scissors2Rock.equals(rel)) { + return Messages.Rock; } return null; } @@ -89,7 +90,7 @@ static class MyLabelProvider extends LabelProvider { @Override public Image getImage(Object element) { - if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { + if (element.equals(Messages.Rock) || element.equals(Messages.Paper) || element.equals(Messages.Scissors)) { return image; } return null; @@ -110,7 +111,7 @@ public String getText(Object element) { public static void main(String[] args) { Shell shell = new Shell(); Display d = shell.getDisplay(); - shell.setText("GraphJFaceSnippet2"); + shell.setText(Messages.GraphJFaceSnippet2_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); viewer = new GraphViewer(shell, SWT.NONE); diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet3.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet3.java index 28cbf7d6e..32493cbef 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet3.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet3.java @@ -29,6 +29,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.zest.core.viewers.GraphViewer; import org.eclipse.zest.core.viewers.IGraphContentProvider; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm; /** @@ -83,7 +84,7 @@ public void dispose() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (newInput != null) { - graph = new StringTokenizer((String) newInput, "\n"); //$NON-NLS-1$ + graph = new StringTokenizer((String) newInput, System.lineSeparator()); } } @@ -94,7 +95,7 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { public static void main(String[] args) throws IOException { Shell shell = new Shell(); Display display = shell.getDisplay(); - shell.setText("Simple Graph File Format"); //$NON-NLS-1$ + shell.setText(Messages.GraphJFaceSnippet3_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); @@ -110,7 +111,7 @@ public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); StringBuilder stringBuffer = new StringBuilder(); while (bufferedReader.ready()) { - stringBuffer.append(bufferedReader.readLine() + "\n"); //$NON-NLS-1$ + stringBuffer.append(bufferedReader.readLine()).append(System.lineSeparator()); } viewer.setInput(stringBuffer.toString()); } diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet4.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet4.java index 47dbb537d..6dbe46085 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet4.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet4.java @@ -27,6 +27,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.zest.core.viewers.GraphViewer; import org.eclipse.zest.core.viewers.IGraphContentProvider; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; public class GraphJFaceSnippet4 { @@ -34,29 +35,29 @@ static class MyContentProvider implements IGraphContentProvider { @Override public Object getDestination(Object rel) { - if ("Rock2Paper".equals(rel)) { - return "Rock"; - } else if ("Paper2Scissors".equals(rel)) { - return "Paper"; - } else if ("Scissors2Rock".equals(rel)) { - return "Scissors"; + if (Messages.Rock2Paper.equals(rel)) { + return Messages.Rock; + } else if (Messages.Paper2Scissors.equals(rel)) { + return Messages.Paper; + } else if (Messages.Scissors2Rock.equals(rel)) { + return Messages.Scissors; } return null; } @Override public Object[] getElements(Object input) { - return new Object[] { "Rock2Paper", "Paper2Scissors", "Scissors2Rock" }; + return new Object[] { Messages.Rock2Paper, Messages.Paper2Scissors, Messages.Scissors2Rock }; } @Override public Object getSource(Object rel) { - if ("Rock2Paper".equals(rel)) { - return "Paper"; - } else if ("Paper2Scissors".equals(rel)) { - return "Scissors"; - } else if ("Scissors2Rock".equals(rel)) { - return "Rock"; + if (Messages.Rock2Paper.equals(rel)) { + return Messages.Paper; + } else if (Messages.Paper2Scissors.equals(rel)) { + return Messages.Scissors; + } else if (Messages.Scissors2Rock.equals(rel)) { + return Messages.Rock; } return null; } @@ -80,7 +81,7 @@ static class MyLabelProvider extends LabelProvider { @Override public Image getImage(Object element) { - if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { + if (element.equals(Messages.Rock) || element.equals(Messages.Paper) || element.equals(Messages.Scissors)) { return image; } return null; @@ -101,7 +102,7 @@ public String getText(Object element) { public static void main(String[] args) { Shell shell = new Shell(); Display d = shell.getDisplay(); - shell.setText("GraphJFaceSnippet2"); + shell.setText(Messages.GraphJFaceSnippet4_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); viewer = new GraphViewer(shell, SWT.NONE); @@ -114,7 +115,7 @@ public static void main(String[] args) { @Override public void selectionChanged(SelectionChangedEvent event) { System.out - .println("Selection Changed: " + selectionToString((StructuredSelection) event.getSelection())); + .println("Selection Changed: " + selectionToString((StructuredSelection) event.getSelection())); //$NON-NLS-1$ } private String selectionToString(StructuredSelection selection) { @@ -125,7 +126,7 @@ private String selectionToString(StructuredSelection selection) { if (first) { first = false; } else { - stringBuffer.append(" : "); + stringBuffer.append(" : "); //$NON-NLS-1$ } stringBuffer.append(iterator.next()); } diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet5.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet5.java index b8c8c76aa..da32b3a35 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet5.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet5.java @@ -28,6 +28,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.zest.core.viewers.GraphViewer; import org.eclipse.zest.core.viewers.IGraphContentProvider; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; /** @@ -37,17 +38,17 @@ public class GraphJFaceSnippet5 { static class MyContentProvider implements IGraphContentProvider { - Object[] elements = { "Rock2Paper", "Paper2Scissors", "Scissors2Rock" }; + Object[] elements = { Messages.Rock2Paper, Messages.Paper2Scissors, Messages.Scissors2Rock }; @Override public Object getDestination(Object rel) { - if ("Rock2Paper".equals(rel)) { - return "Rock"; + if (Messages.Rock2Paper.equals(rel)) { + return Messages.Rock; } - if ("Paper2Scissors".equals(rel) || "Scissors2Paper".equals(rel)) { - return "Paper"; - } else if ("Scissors2Rock".equals(rel)) { - return "Scissors"; + if (Messages.Paper2Scissors.equals(rel) || Messages.Scissors2Paper.equals(rel)) { + return Messages.Paper; + } else if (Messages.Scissors2Rock.equals(rel)) { + return Messages.Scissors; } return null; } @@ -59,13 +60,13 @@ public Object[] getElements(Object input) { @Override public Object getSource(Object rel) { - if ("Rock2Paper".equals(rel)) { - return "Paper"; + if (Messages.Rock2Paper.equals(rel)) { + return Messages.Paper; } - if ("Paper2Scissors".equals(rel) || "Scissors2Paper".equals(rel)) { - return "Scissors"; - } else if ("Scissors2Rock".equals(rel)) { - return "Rock"; + if (Messages.Paper2Scissors.equals(rel) || Messages.Scissors2Paper.equals(rel)) { + return Messages.Scissors; + } else if (Messages.Scissors2Rock.equals(rel)) { + return Messages.Rock; } return null; } @@ -115,7 +116,7 @@ public Image getImage(Object element) { public static void main(String[] args) { Shell shell = new Shell(); Display d = shell.getDisplay(); - shell.setText("GraphJFaceSnippet2"); + shell.setText(Messages.GraphJFaceSnippet5_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); Composite parent = new Composite(shell, SWT.NONE); @@ -133,11 +134,12 @@ public static void main(String[] args) { private static void buildButton(Composite parent) { Button button = new Button(parent, SWT.PUSH); - button.setText("Refresh"); + button.setText(Messages.GraphJFaceSnippet5_Refresh); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - contentProvider.setElements(new Object[] { "Rock2Paper", "Scissors2Paper", "Scissors2Rock" }); + contentProvider.setElements( + new Object[] { Messages.Rock2Paper, Messages.Scissors2Paper, Messages.Scissors2Rock }); viewer.refresh(); } }); diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet6.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet6.java index 63f327d77..371f64907 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet6.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet6.java @@ -25,6 +25,7 @@ import org.eclipse.zest.core.viewers.GraphViewer; import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; import org.eclipse.zest.core.viewers.INestedContentProvider; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; /** @@ -41,35 +42,29 @@ * */ public class GraphJFaceSnippet6 { - private static final String SCISSORS = "scissors"; //$NON-NLS-1$ - private static final String PAPER = "paper"; //$NON-NLS-1$ - private static final String ROCK = "rock"; //$NON-NLS-1$ - private static final String THIRD = "Third"; //$NON-NLS-1$ - private static final String SECOND = "Second"; //$NON-NLS-1$ - private static final String FIRST = "First"; //$NON-NLS-1$ static class MyContentProvider implements IGraphEntityContentProvider, INestedContentProvider { @Override public Object[] getConnectedTo(Object entity) { - if (entity.equals(FIRST)) { - return new Object[] { SECOND }; + if (entity.equals(Messages.First)) { + return new Object[] { Messages.Second }; } - if (entity.equals(SECOND)) { - return new Object[] { THIRD, ROCK }; + if (entity.equals(Messages.Second)) { + return new Object[] { Messages.Third, Messages.Rock }; } - if (entity.equals(THIRD)) { - return new Object[] { FIRST }; + if (entity.equals(Messages.Third)) { + return new Object[] { Messages.First }; } - if (entity.equals(ROCK)) { - return new Object[] { PAPER }; + if (entity.equals(Messages.Rock)) { + return new Object[] { Messages.Paper }; } return null; } @Override public Object[] getElements(Object inputElement) { - return new String[] { FIRST, SECOND, THIRD }; + return new String[] { Messages.First, Messages.Second, Messages.Third }; } public double getWeight(Object entity1, Object entity2) { @@ -88,12 +83,12 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @Override public Object[] getChildren(Object element) { - return new Object[] { ROCK, PAPER, SCISSORS }; + return new Object[] { Messages.Rock, Messages.Paper, Messages.Scissors }; } @Override public boolean hasChildren(Object element) { - return element.equals(FIRST); + return element.equals(Messages.First); } } @@ -103,7 +98,7 @@ static class MyLabelProvider extends LabelProvider { @Override public Image getImage(Object element) { - if (ROCK.equals(element) || PAPER.equals(element) || SCISSORS.equals(element)) { + if (Messages.Rock.equals(element) || Messages.Paper.equals(element) || Messages.Scissors.equals(element)) { return image; } return null; @@ -127,7 +122,7 @@ public String getText(Object element) { public static void main(String[] args) { Shell shell = new Shell(); Display d = shell.getDisplay(); - shell.setText("GraphJFaceSnippet2"); //$NON-NLS-1$ + shell.setText(Messages.GraphJFaceSnippet6_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); viewer = new GraphViewer(shell, SWT.NONE); @@ -137,7 +132,7 @@ public static void main(String[] args) { viewer.setInput(new Object()); Button button = new Button(shell, SWT.PUSH); - button.setText("push"); //$NON-NLS-1$ + button.setText(Messages.GraphJFaceSnippet6_Push); button.addListener(SWT.Selection, e -> viewer.setInput(new Object())); shell.open(); diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet7.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet7.java index f079a4067..f28601615 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet7.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet7.java @@ -27,6 +27,7 @@ import org.eclipse.zest.core.viewers.IFigureProvider; import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; import org.eclipse.zest.core.viewers.INestedContentProvider; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.examples.uml.UMLClassFigure; import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; @@ -48,24 +49,17 @@ */ public class GraphJFaceSnippet7 { - private static final String SCISSORS = "scissors"; //$NON-NLS-1$ - private static final String PAPER = "paper"; //$NON-NLS-1$ - private static final String ROCK = "rock"; //$NON-NLS-1$ - private static final String THIRD = "Third"; //$NON-NLS-1$ - private static final String SECOND = "Second"; //$NON-NLS-1$ - private static final String FIRST = "First"; //$NON-NLS-1$ - public static IFigure createClassFigure1(Font classFont, Image classImage, Image publicField, Image privateField) { - Label classLabel1 = new Label("Table", classImage); //$NON-NLS-1$ + Label classLabel1 = new Label(Messages.GraphJFaceSnippet7_Class, classImage); classLabel1.setFont(classFont); UMLClassFigure classFigure = new UMLClassFigure(classLabel1); - Label attribute1 = new Label("columns: Column[]", privateField); //$NON-NLS-1$ + Label attribute1 = new Label(Messages.GraphJFaceSnippet7_Field_Columns, privateField); - Label attribute2 = new Label("rows: Row[]", privateField); //$NON-NLS-1$ + Label attribute2 = new Label(Messages.GraphJFaceSnippet7_Field_Rows, privateField); - Label method1 = new Label("getColumns(): Column[]", publicField); //$NON-NLS-1$ - Label method2 = new Label("getRows(): Row[]", publicField); //$NON-NLS-1$ + Label method1 = new Label(Messages.GraphJFaceSnippet7_Method_GetColumns, publicField); + Label method2 = new Label(Messages.GraphJFaceSnippet7_Method_GetRows, publicField); classFigure.getAttributesCompartment().add(attribute1); classFigure.getAttributesCompartment().add(attribute2); classFigure.getMethodsCompartment().add(method1); @@ -79,24 +73,24 @@ static class MyContentProvider implements IGraphEntityContentProvider, INestedCo @Override public Object[] getConnectedTo(Object entity) { - if (entity.equals(FIRST)) { - return new Object[] { SECOND }; + if (entity.equals(Messages.First)) { + return new Object[] { Messages.Second }; } - if (entity.equals(SECOND)) { - return new Object[] { THIRD, ROCK }; + if (entity.equals(Messages.Second)) { + return new Object[] { Messages.Third, Messages.Rock }; } - if (entity.equals(THIRD)) { - return new Object[] { FIRST }; + if (entity.equals(Messages.Third)) { + return new Object[] { Messages.First }; } - if (entity.equals(ROCK)) { - return new Object[] { PAPER }; + if (entity.equals(Messages.Rock)) { + return new Object[] { Messages.Paper }; } return null; } @Override public Object[] getElements(Object inputElement) { - return new String[] { FIRST, SECOND, THIRD }; + return new String[] { Messages.First, Messages.Second, Messages.Third }; } public double getWeight(Object entity1, Object entity2) { @@ -115,12 +109,12 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @Override public Object[] getChildren(Object element) { - return new Object[] { ROCK, PAPER, SCISSORS }; + return new Object[] { Messages.Rock, Messages.Paper, Messages.Scissors }; } @Override public boolean hasChildren(Object element) { - return element.equals(FIRST); + return element.equals(Messages.First); } } @@ -137,7 +131,7 @@ static class MyLabelProvider extends LabelProvider implements IFigureProvider { @Override public Image getImage(Object element) { - if (ROCK.equals(element) || PAPER.equals(element) || SCISSORS.equals(element)) { + if (Messages.Rock.equals(element) || Messages.Paper.equals(element) || Messages.Scissors.equals(element)) { return image; } return null; @@ -174,7 +168,7 @@ public void dispose() { public static void main(String[] args) { Shell shell = new Shell(); Display d = shell.getDisplay(); - shell.setText("GraphJFaceSnippet2"); //$NON-NLS-1$ + shell.setText(Messages.GraphJFaceSnippet7_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); viewer = new GraphViewer(shell, SWT.NONE); @@ -184,7 +178,7 @@ public static void main(String[] args) { viewer.setInput(new Object()); Button button = new Button(shell, SWT.PUSH); - button.setText("push"); //$NON-NLS-1$ + button.setText(Messages.GraphJFaceSnippet7_Push); button.addListener(SWT.Selection, e -> viewer.setInput(new Object())); shell.open(); diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet8.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet8.java index 2e94191cd..279e90428 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet8.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet8.java @@ -26,6 +26,7 @@ import org.eclipse.zest.core.viewers.ISelfStyleProvider; import org.eclipse.zest.core.widgets.GraphConnection; import org.eclipse.zest.core.widgets.GraphNode; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm; import org.eclipse.draw2d.ColorConstants; @@ -44,21 +45,21 @@ static class MyContentProvider implements IGraphEntityContentProvider { @Override public Object[] getConnectedTo(Object entity) { - if (entity.equals("First")) { - return new Object[] { "First", "Second" }; + if (entity.equals(Messages.First)) { + return new Object[] { Messages.First, Messages.Second }; } - if (entity.equals("Second")) { - return new Object[] { "Third" }; + if (entity.equals(Messages.Second)) { + return new Object[] { Messages.Third }; } - if (entity.equals("Third")) { - return new Object[] { "Second" }; + if (entity.equals(Messages.Third)) { + return new Object[] { Messages.Second }; } return null; } @Override public Object[] getElements(Object inputElement) { - return new String[] { "First", "Second", "Third" }; + return new String[] { Messages.First, Messages.Second, Messages.Third }; } public double getWeight(Object entity1, Object entity2) { @@ -124,6 +125,7 @@ public void selfStyleNode(Object element, GraphNode node) { public static void main(String[] args) { Shell shell = new Shell(); Display d = shell.getDisplay(); + shell.setText(Messages.GraphJFaceSnippet8_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); viewer = new GraphViewer(shell, SWT.NONE); diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet9.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet9.java index 3bad3927c..926c0f277 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet9.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/GraphJFaceSnippet9.java @@ -24,6 +24,7 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.zest.core.viewers.GraphViewer; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; /** @@ -33,7 +34,8 @@ public class GraphJFaceSnippet9 { static class MyContentProvider implements ITreeContentProvider { - private static final String n1 = "First", n2 = "Second", n3 = "Third", n4 = "Fourth"; + private static final String n1 = Messages.First, n2 = Messages.Second, n3 = Messages.Third, + n4 = Messages.Fourth; @Override public Object[] getElements(Object inputElement) { @@ -75,7 +77,7 @@ public Object getParent(Object element) { @Override public boolean hasChildren(Object element) { - return element.equals("First") || element.equals("Second"); + return element.equals(Messages.First) || element.equals(Messages.Second); } } @@ -105,10 +107,11 @@ public String getText(Object element) { public static void main(String[] args) { Display d = new Display(); Shell shell = new Shell(d); + shell.setText(Messages.GraphJFaceSnippet9_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); Button button = new Button(shell, SWT.PUSH); - button.setText("Reload"); + button.setText(Messages.GraphJFaceSnippet9_Reload); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -119,7 +122,7 @@ public void widgetSelected(SelectionEvent e) { viewer.setContentProvider(new MyContentProvider()); viewer.setLabelProvider(new MyLabelProvider()); viewer.setLayoutAlgorithm(new TreeLayoutAlgorithm()); - viewer.addSelectionChangedListener(event -> System.out.println("Selection changed: " + (event.getSelection()))); + viewer.addSelectionChangedListener(event -> System.out.println("Selection changed: " + (event.getSelection()))); //$NON-NLS-1$ viewer.setInput(new Object()); shell.open(); while (!shell.isDisposed()) { diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/ManhattanLayoutJFaceSnippet.java b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/ManhattanLayoutJFaceSnippet.java index e3f861534..0b79ceccd 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/ManhattanLayoutJFaceSnippet.java +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/jface/ManhattanLayoutJFaceSnippet.java @@ -32,6 +32,7 @@ import org.eclipse.zest.core.viewers.IConnectionStyleProvider2; import org.eclipse.zest.core.viewers.IEntityConnectionStyleProvider2; import org.eclipse.zest.core.viewers.IGraphContentProvider; +import org.eclipse.zest.examples.Messages; import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; import org.eclipse.draw2d.ConnectionRouter; @@ -54,33 +55,33 @@ static class MyContentProvider implements IGraphContentProvider { @Override public Object getDestination(Object rel) { - if ("Rock2Paper".equals(rel)) { - return "Rock"; + if (Messages.Rock2Paper.equals(rel)) { + return Messages.Rock; } - if ("Paper2Scissors".equals(rel)) { - return "Paper"; + if (Messages.Paper2Scissors.equals(rel)) { + return Messages.Paper; } - if ("Scissors2Rock".equals(rel)) { - return "Scissors"; + if (Messages.Scissors2Rock.equals(rel)) { + return Messages.Scissors; } return null; } @Override public Object[] getElements(Object input) { - return new Object[] { "Rock2Paper", "Paper2Scissors", "Scissors2Rock" }; + return new Object[] { Messages.Rock2Paper, Messages.Paper2Scissors, Messages.Scissors2Rock }; } @Override public Object getSource(Object rel) { - if ("Rock2Paper".equals(rel)) { - return "Paper"; + if (Messages.Rock2Paper.equals(rel)) { + return Messages.Paper; } - if ("Paper2Scissors".equals(rel)) { - return "Scissors"; + if (Messages.Paper2Scissors.equals(rel)) { + return Messages.Scissors; } - if ("Scissors2Rock".equals(rel)) { - return "Rock"; + if (Messages.Scissors2Rock.equals(rel)) { + return Messages.Rock; } return null; } @@ -104,7 +105,7 @@ static class MyConnectionRelationLabelProvider extends LabelProvider implements @Override public Image getImage(Object element) { - if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { + if (element.equals(Messages.Rock) || element.equals(Messages.Paper) || element.equals(Messages.Scissors)) { return image; } return null; @@ -118,7 +119,7 @@ public String getText(Object element) { /* Relation-based customization: IConnectionStyleProvider */ public ConnectionRouter getRouter(Object rel) { - if (!rel.equals("Scissors2Rock")) { + if (!rel.equals(Messages.Scissors2Rock)) { return new ManhattanConnectionRouter(); } return null; @@ -156,7 +157,7 @@ static class MyEndpointEntityLabelProvider extends LabelProvider implements IEnt @Override public Image getImage(Object element) { - if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { + if (element.equals(Messages.Rock) || element.equals(Messages.Paper) || element.equals(Messages.Scissors)) { return image; } return null; @@ -171,8 +172,8 @@ public String getText(Object element) { @Override public ConnectionRouter getRouter(Object src, Object dest) { - System.out.println(src + " -> " + dest); - if (!(src.equals("Paper") && dest.equals("Rock"))) { + System.out.println(src + " -> " + dest); //$NON-NLS-1$ + if (!(src.equals(Messages.Paper) && dest.equals(Messages.Rock))) { return new ManhattanConnectionRouter(); } return null; @@ -218,7 +219,7 @@ public IFigure getTooltip(Object entity) { public static void main(String[] args) { Display d = new Display(); Shell shell = new Shell(d); - shell.setText("GraphJFaceSnippet2"); + shell.setText(Messages.ManhattanLayoutJFaceSnippet_Title); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); viewer = new GraphViewer(shell, SWT.NONE); @@ -231,7 +232,7 @@ public static void main(String[] args) { @Override public void selectionChanged(SelectionChangedEvent event) { System.out - .println("Selection Changed: " + selectionToString((StructuredSelection) event.getSelection())); + .println("Selection Changed: " + selectionToString((StructuredSelection) event.getSelection())); //$NON-NLS-1$ } private String selectionToString(StructuredSelection selection) { @@ -242,7 +243,7 @@ private String selectionToString(StructuredSelection selection) { if (first) { first = false; } else { - stringBuffer.append(" : "); + stringBuffer.append(" : "); //$NON-NLS-1$ } stringBuffer.append(iterator.next()); } diff --git a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/messages.properties b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/messages.properties index 8f32d37e5..82e8ae4a9 100644 --- a/org.eclipse.zest.examples/src/org/eclipse/zest/examples/messages.properties +++ b/org.eclipse.zest.examples/src/org/eclipse/zest/examples/messages.properties @@ -1,13 +1,44 @@ Paper=Paper Rock=Rock Scissors=Scissors +Rock2Paper=Rock2Paper +Paper2Scissors=Paper2Scissors +Scissors2Paper=Scissors2Paper +Scissors2Rock=Scissors2Rock Information=Information Warning=Warning Error=Error Root=Root +One=One +Two=Two +Three=Three +First=First +Second=Second +Third=Third +Fourth=Fourth AnimationSnippet_Animate=Animate AnimationSnippet_Title=Animation Example +CustomFigureJFaceSnippet_Title=CustomFigureJFaceSnippet CustomLayout_Title=Custom Layout Example +GraphJFaceSnippet1_Title=GraphJFaceSnippet1 +GraphJFaceSnippet1_Reload=Reload +GraphJFaceSnippet2_Title=GraphJFaceSnippet2 +GraphJFaceSnippet3_Title=Simple Graph File Format +GraphJFaceSnippet4_Title=GraphJFaceSnippet4 +GraphJFaceSnippet5_Title=GraphJFaceSnippet5 +GraphJFaceSnippet5_Refresh=Refresh +GraphJFaceSnippet6_Title=GraphJFaceSnippet6 +GraphJFaceSnippet6_Push=push +GraphJFaceSnippet7_Title=GraphJFaceSnippet7 +GraphJFaceSnippet7_Push=push +GraphJFaceSnippet7_Class=Table +GraphJFaceSnippet7_Field_Columns=columns: Column[] +GraphJFaceSnippet7_Field_Rows=rows: Row[] +GraphJFaceSnippet7_Method_GetColumns=getColumns(): Column[] +GraphJFaceSnippet7_Method_GetRows=getRows(): Row[] +GraphJFaceSnippet8_Title=GraphJFaceSnippet8 +GraphJFaceSnippet9_Title=GraphJFaceSnippet9 +GraphJFaceSnippet9_Reload=Reload GraphSnippet1_Title=GraphSnippet1 GraphSnippet10_Title=GraphSnippet10 GraphSnippet10_ChangeCurve=Change Curve @@ -57,6 +88,7 @@ LayoutExample_Node1=1 - {0} LayoutExample_Node2=2 - {0} ManhattanLayoutGraphSnippet_Title=ManhattanLayout GraphSnippet ManhattanLayoutGraphSnippet_ChangeRouter=Change Router +ManhattanLayoutJFaceSnippet_Title=ManhattanLayoutJFaceSnippet NestedGraphSnippet_Title=NestedGraphSnippet1 NestedGraphSnippet_Container1=SomeClass.java NestedGraphSnippet_Container2=SomeNestedClass.java diff --git a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/GraphJFaceTests.java b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/GraphJFaceTests.java index 40fb505c0..b23d82d63 100644 --- a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/GraphJFaceTests.java +++ b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/GraphJFaceTests.java @@ -193,14 +193,14 @@ public void testGraphJFaceSnippet6() { assertEquals(graph.getNodes().size(), 3); GraphContainer container = (GraphContainer) graph.getNodes().get(0); - assertNode(container.getNodes().get(0), "rock"); - assertNode(container.getNodes().get(1), "paper"); - assertNode(container.getNodes().get(2), "scissors"); + assertNode(container.getNodes().get(0), "Rock"); + assertNode(container.getNodes().get(1), "Paper"); + assertNode(container.getNodes().get(2), "Scissors"); assertEquals(container.getNodes().size(), 3); - assertConnection(graph.getConnections().get(0), "rock", "paper"); + assertConnection(graph.getConnections().get(0), "Rock", "Paper"); assertConnection(graph.getConnections().get(1), "Second", "Third"); - assertConnection(graph.getConnections().get(2), "Second", "rock"); + assertConnection(graph.getConnections().get(2), "Second", "Rock"); assertConnection(graph.getConnections().get(3), "Third", "First"); assertConnection(graph.getConnections().get(4), "First", "Second"); assertEquals(graph.getConnections().size(), 5);