Skip to content

Commit

Permalink
Externalize Zest JFace examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ptziegler authored and azoitl committed Dec 27, 2024
1 parent 0bd5f17 commit 83c0e5d
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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);
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,37 @@
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 {
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;
}
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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());
}
Expand Down
Loading

0 comments on commit 83c0e5d

Please sign in to comment.