Skip to content

Commit ae4347f

Browse files
committed
updates
1 parent 0b25292 commit ae4347f

9 files changed

Lines changed: 162 additions & 69 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package de.vogella.rcp.dialogs.swt;
2+
3+
import org.eclipse.swt.SWT;
4+
import org.eclipse.swt.events.SelectionAdapter;
5+
import org.eclipse.swt.events.SelectionEvent;
6+
import org.eclipse.swt.graphics.FontData;
7+
import org.eclipse.swt.graphics.RGB;
8+
import org.eclipse.swt.widgets.Button;
9+
import org.eclipse.swt.widgets.ColorDialog;
10+
import org.eclipse.swt.widgets.Composite;
11+
import org.eclipse.swt.widgets.DirectoryDialog;
12+
import org.eclipse.swt.widgets.FileDialog;
13+
import org.eclipse.swt.widgets.FontDialog;
14+
import org.eclipse.swt.widgets.MessageBox;
15+
import org.eclipse.swt.widgets.Shell;
16+
17+
public class MyComposite extends Composite {
18+
19+
public MyComposite(final Composite parent, int style) {
20+
super(parent, style);
21+
Button button = new Button(parent, SWT.PUSH);
22+
button.setText("Press me");
23+
button.addSelectionListener(new SelectionAdapter() {
24+
@Override
25+
public void widgetSelected(SelectionEvent e) {
26+
Shell shell = parent.getShell();
27+
openDialogs(shell);
28+
}
29+
});
30+
31+
}
32+
33+
private void openDialogs(Shell shell) {
34+
// File standard dialog
35+
FileDialog fileDialog = new FileDialog(shell);
36+
// Set the text
37+
fileDialog.setText("Select File");
38+
// Set filter on .txt files
39+
fileDialog.setFilterExtensions(new String[] { "*.txt" });
40+
// Put in a readable name for the filter
41+
fileDialog.setFilterNames(new String[] { "Textfiles(*.txt)" });
42+
// Open Dialog and save result of selection
43+
String selected = fileDialog.open();
44+
System.out.println(selected);
45+
46+
// Directly standard selection
47+
DirectoryDialog dirDialog = new DirectoryDialog(shell);
48+
dirDialog.setText("Select your home directory");
49+
String selectedDir = dirDialog.open();
50+
System.out.println(selectedDir);
51+
52+
// Select Font
53+
FontDialog fontDialog = new FontDialog(shell);
54+
fontDialog.setText("Select your favorite font");
55+
FontData selectedFont = fontDialog.open();
56+
System.out.println(selectedFont);
57+
58+
// Select Color
59+
ColorDialog colorDialog = new ColorDialog(shell);
60+
colorDialog.setText("Select your favorite color");
61+
RGB selectedColor = colorDialog.open();
62+
System.out.println(selectedColor);
63+
64+
// Message
65+
MessageBox messageDialog = new MessageBox(shell, SWT.ERROR);
66+
messageDialog.setText("Evil Error has happend");
67+
messageDialog.setMessage("This is fatal!!!");
68+
int returnCode = messageDialog.open();
69+
System.out.println(returnCode);
70+
71+
// Message with ok and cancel button and info icon
72+
messageDialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK
73+
| SWT.CANCEL);
74+
messageDialog.setText("My info");
75+
messageDialog.setMessage("Do you really want to do this.");
76+
returnCode = messageDialog.open();
77+
System.out.println(returnCode);
78+
}
79+
80+
}

‎de.vogella.rcp.dialogs.swt/src/de/vogella/rcp/dialogs/swt/Perspective.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
public class Perspective implements IPerspectiveFactory {
77

88
public void createInitialLayout(IPageLayout layout) {
9+
layout.addView(View.ID, IPageLayout.LEFT, 0.9f, layout.getEditorArea());
910
}
1011
}
Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
package de.vogella.rcp.dialogs.swt;
22

33
import org.eclipse.swt.SWT;
4-
import org.eclipse.swt.events.SelectionAdapter;
5-
import org.eclipse.swt.events.SelectionEvent;
6-
import org.eclipse.swt.graphics.FontData;
7-
import org.eclipse.swt.graphics.RGB;
8-
import org.eclipse.swt.widgets.Button;
9-
import org.eclipse.swt.widgets.ColorDialog;
104
import org.eclipse.swt.widgets.Composite;
11-
import org.eclipse.swt.widgets.DirectoryDialog;
12-
import org.eclipse.swt.widgets.FileDialog;
13-
import org.eclipse.swt.widgets.FontDialog;
14-
import org.eclipse.swt.widgets.MessageBox;
15-
import org.eclipse.swt.widgets.Shell;
165
import org.eclipse.ui.part.ViewPart;
176

187
public class View extends ViewPart {
@@ -21,62 +10,13 @@ public class View extends ViewPart {
2110

2211
@Override
2312
public void createPartControl(Composite parent) {
24-
Button button = new Button(parent, SWT.PUSH);
25-
button.addSelectionListener(new SelectionAdapter() {
26-
@Override
27-
public void widgetSelected(SelectionEvent e) {
28-
Shell shell = getViewSite().getShell();
29-
// File standard dialog
30-
FileDialog fileDialog = new FileDialog(shell);
31-
// Set the text
32-
fileDialog.setText("Select File");
33-
// Set filter on .txt files
34-
fileDialog.setFilterExtensions(new String[] { "*.txt" });
35-
// Put in a readable name for the filter
36-
fileDialog.setFilterNames(new String[] { "Textfiles(*.txt)" });
37-
// Open Dialog and save result of selection
38-
String selected = fileDialog.open();
39-
System.out.println(selected);
13+
new MyComposite(parent, SWT.NONE);
4014

41-
// Directly standard selection
42-
DirectoryDialog dirDialog = new DirectoryDialog(shell);
43-
dirDialog.setText("Select your home directory");
44-
String selectedDir = dirDialog.open();
45-
System.out.println(selectedDir);
46-
47-
// Select Font
48-
FontDialog fontDialog = new FontDialog(shell);
49-
fontDialog.setText("Select your favorite font");
50-
FontData selectedFont = fontDialog.open();
51-
System.out.println(selectedFont);
52-
53-
// Select Color
54-
ColorDialog colorDialog = new ColorDialog(shell);
55-
colorDialog.setText("Select your favorite color");
56-
RGB selectedColor = colorDialog.open();
57-
System.out.println(selectedColor);
58-
59-
// Message
60-
MessageBox messageDialog = new MessageBox(shell, SWT.ERROR);
61-
messageDialog.setText("Evil Error has happend");
62-
messageDialog.setMessage("This is fatal!!!");
63-
int returnCode = messageDialog.open();
64-
System.out.println(returnCode);
65-
66-
// Message with ok and cancel button and info icon
67-
messageDialog = new MessageBox(shell, SWT.ICON_QUESTION
68-
| SWT.OK | SWT.CANCEL);
69-
messageDialog.setText("My info");
70-
messageDialog.setMessage("Do you really want to do this.");
71-
returnCode = messageDialog.open();
72-
System.out.println(returnCode);
73-
}
74-
});
7515
}
7616

7717
@Override
7818
public void setFocus() {
79-
// Set the focus
19+
8020
}
8121

8222
}
983 Bytes
Loading

‎de.vogella.rcp.intro.wizards/plugin.xml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,19 @@
3838
</command>
3939
</menuContribution>
4040
</extension>
41+
<extension
42+
point="org.eclipse.ui.views">
43+
<category
44+
id="de.vogella.rcp.intro.wizards"
45+
name="MyView">
46+
</category>
47+
<view
48+
category="de.vogella.rcp.intro.wizards"
49+
class="de.vogella.rcp.intro.wizards.views.MyView"
50+
icon="icons/sample.gif"
51+
id="de.vogella.rcp.intro.wizards.views.MyView"
52+
name="MyView">
53+
</view>
54+
</extension>
4155

4256
</plugin>

‎de.vogella.rcp.intro.wizards/src/de/vogella/rcp/intro/wizards/Perspective.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import org.eclipse.ui.IPageLayout;
44
import org.eclipse.ui.IPerspectiveFactory;
55

6+
import de.vogella.rcp.intro.wizards.views.MyView;
7+
68
public class Perspective implements IPerspectiveFactory {
79

810
public void createInitialLayout(IPageLayout layout) {
11+
layout.addView(MyView.ID, IPageLayout.RIGHT, 0.95f,
12+
layout.getEditorArea());
913
}
1014
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package de.vogella.rcp.intro.wizards.views;
2+
3+
import org.eclipse.jface.window.Window;
4+
import org.eclipse.jface.wizard.WizardDialog;
5+
import org.eclipse.swt.SWT;
6+
import org.eclipse.swt.events.SelectionAdapter;
7+
import org.eclipse.swt.events.SelectionEvent;
8+
import org.eclipse.swt.widgets.Button;
9+
import org.eclipse.swt.widgets.Composite;
10+
import org.eclipse.ui.part.ViewPart;
11+
12+
import de.vogella.rcp.intro.wizards.wizard.MyWizard;
13+
14+
public class MyView extends ViewPart {
15+
16+
/**
17+
* The ID of the view as specified by the extension.
18+
*/
19+
public static final String ID = "de.vogella.rcp.intro.wizards.views.MyView";
20+
21+
/**
22+
* This is a callback that will allow us to create the viewer and initialize
23+
* it.
24+
*/
25+
public void createPartControl(final Composite parent) {
26+
Button button = new Button(parent, SWT.PUSH);
27+
button.setText("Open Wizard");
28+
button.addSelectionListener(new SelectionAdapter() {
29+
@Override
30+
public void widgetSelected(SelectionEvent e) {
31+
WizardDialog wizardDialog = new WizardDialog(parent.getShell(),
32+
new MyWizard());
33+
if (wizardDialog.open() == Window.OK) {
34+
System.out.println("Ok pressed");
35+
} else {
36+
System.out.println("Cancel pressed");
37+
}
38+
}
39+
});
40+
}
41+
42+
public void setFocus() {
43+
}
44+
}

‎de.vogella.rcp.intro.wizards/src/de/vogella/rcp/intro/wizards/wizard/MyPageOne.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
package de.vogella.rcp.intro.wizards.wizard;
22

3+
import org.eclipse.jface.wizard.IWizardPage;
34
import org.eclipse.jface.wizard.WizardPage;
45
import org.eclipse.swt.SWT;
56
import org.eclipse.swt.events.KeyEvent;
67
import org.eclipse.swt.events.KeyListener;
78
import org.eclipse.swt.layout.GridData;
89
import org.eclipse.swt.layout.GridLayout;
910
import org.eclipse.swt.widgets.Composite;
11+
import org.eclipse.swt.widgets.Display;
1012
import org.eclipse.swt.widgets.Label;
1113
import org.eclipse.swt.widgets.Text;
1214

1315
public class MyPageOne extends WizardPage {
1416
private Text text1;
1517
private Composite container;
18+
private int number = 0;
1619

1720
public MyPageOne() {
1821
super("First Page");
19-
setTitle("First Page2");
20-
setDescription("This wizard does not really do anything. But this is the first page");
22+
setTitle("First Page");
23+
setDescription("Fake Wizard. First page");
2124
}
2225

2326
@Override
@@ -58,4 +61,13 @@ public String getText1() {
5861
return text1.getText();
5962
}
6063

64+
public IWizardPage getNextPage() {
65+
Display.getDefault().asyncExec(new Runnable() {
66+
public void run() {
67+
// ... do any work that updates the screen ...
68+
}
69+
});
70+
71+
return super.getNextPage();
72+
}
6173
}

‎de.vogella.rcp.intro.wizards/src/de/vogella/rcp/intro/wizards/wizard/MyWizard.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
public class MyWizard extends Wizard {
66

7-
private MyPageOne one;
8-
private MyPageTwo two;
7+
protected MyPageOne one;
8+
protected MyPageTwo two;
99

1010
public MyWizard() {
1111
super();
@@ -22,9 +22,7 @@ public void addPages() {
2222

2323
@Override
2424
public boolean performFinish() {
25-
26-
// just put the result to the console, imagine here much more
27-
// intelligent stuff.
25+
// Print the result to the console
2826
System.out.println(one.getText1());
2927
System.out.println(two.getText1());
3028

0 commit comments

Comments
 (0)