|
1 | 1 | package net.servicestack.eclipse.wizard; |
2 | 2 |
|
| 3 | +import java.net.URL; |
| 4 | + |
| 5 | +import javax.swing.ImageIcon; |
| 6 | + |
| 7 | +import org.eclipse.core.runtime.FileLocator; |
| 8 | +import org.eclipse.core.runtime.Path; |
| 9 | +import org.eclipse.core.runtime.Platform; |
| 10 | +import org.eclipse.jface.resource.ImageDescriptor; |
3 | 11 | import org.eclipse.jface.wizard.WizardPage; |
4 | 12 | import org.eclipse.swt.SWT; |
5 | 13 | import org.eclipse.swt.events.VerifyEvent; |
6 | 14 | import org.eclipse.swt.events.VerifyListener; |
| 15 | +import org.eclipse.swt.graphics.Image; |
7 | 16 | import org.eclipse.swt.layout.GridData; |
8 | 17 | import org.eclipse.swt.layout.GridLayout; |
9 | 18 | import org.eclipse.swt.widgets.Button; |
10 | 19 | import org.eclipse.swt.widgets.Composite; |
11 | 20 | import org.eclipse.swt.widgets.Label; |
12 | 21 | import org.eclipse.swt.widgets.Text; |
| 22 | +import org.osgi.framework.Bundle; |
13 | 23 |
|
14 | 24 | public class AddReferencePage extends WizardPage { |
15 | 25 |
|
16 | 26 | Button _enabled; |
17 | | - private boolean _enabledValue = true; |
| 27 | + private boolean _enabledValue = true; |
18 | 28 | private String _applicationFolder; |
19 | | - |
20 | | - private Text addressUrlTextField; |
21 | | - private Text nameTextField; |
22 | | - |
23 | | - private String errorMessage; |
24 | | - private String selectedDirectory; |
25 | | - |
| 29 | + public boolean canFinish = false; |
| 30 | + |
| 31 | + private Text addressUrlTextField; |
| 32 | + private Text nameTextField; |
| 33 | + private Text packageTextField; |
| 34 | + |
| 35 | + private String errorMessage; |
| 36 | + private String selectedDirectory; |
| 37 | + |
26 | 38 | protected AddReferencePage() { |
27 | 39 | super("Add ServiceStack Reference"); |
28 | 40 | setTitle("Add ServiceStack Reference"); |
29 | | - setDescription("To generate the DTO Service Model types for a specific ServiceStack instance, enter the base URI for the remote ServiceStack server and click Finish."); |
| 41 | + setDescription("Enter the base URI for the remote ServiceStack server and click Finish."); |
| 42 | + Bundle bundle = Platform.getBundle("net.servicestack.eclipse"); |
| 43 | + final URL fullPathString = bundle.getEntry("/icons/logo-100.png"); |
| 44 | + |
| 45 | + ImageDescriptor imageDesc = ImageDescriptor.createFromURL(fullPathString); |
| 46 | + setImageDescriptor(imageDesc); |
| 47 | + |
30 | 48 | // TODO Auto-generated constructor stub |
31 | 49 | } |
| 50 | + |
| 51 | + public boolean canFlipToNextPage() { |
| 52 | + return canFinish; |
| 53 | + } |
32 | 54 |
|
33 | 55 | @Override |
34 | 56 | public void createControl(Composite parent) { |
35 | 57 | // TODO Auto-generated method stub |
36 | | - Composite composite = new Composite(parent, SWT.NULL); |
37 | | - composite.setBounds(100, 100, 450, 300); |
38 | | - GridLayout layout = new GridLayout(); |
39 | | - GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
40 | | - composite.setLayout(layout); |
41 | | - layout.numColumns = 1; |
42 | | - Label label1 = new Label(composite,SWT.NONE); |
43 | | - label1.setText("Address Url"); |
44 | | - addressUrlTextField = new Text(composite,SWT.BORDER | SWT.SINGLE); |
| 58 | + Composite composite = new Composite(parent, SWT.NULL); |
| 59 | + // composite.setBounds(100, 100, 450, 300); |
| 60 | + |
| 61 | + GridLayout layout = new GridLayout(); |
| 62 | + GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
| 63 | + composite.setLayout(layout); |
| 64 | + layout.numColumns = 1; |
| 65 | + Label addressLabel = new Label(composite, SWT.NONE); |
| 66 | + addressLabel.setText("Address Url"); |
| 67 | + addressUrlTextField = new Text(composite, SWT.BORDER | SWT.SINGLE); |
45 | 68 | addressUrlTextField.setToolTipText("eg, http://example.com/"); |
46 | 69 | addressUrlTextField.setLayoutData(gd); |
47 | 70 | addressUrlTextField.addVerifyListener(new VerifyListener() { |
48 | | - |
| 71 | + |
49 | 72 | @Override |
50 | 73 | public void verifyText(VerifyEvent event) { |
51 | | - String text = event.text; |
52 | | - //seriously..doit? |
53 | | - boolean result = text != null && text.length() > 0; |
54 | | - if(!result) { |
55 | | - setErrorMessage("URL Address is required"); |
56 | | - } |
57 | | - event.doit = result; |
| 74 | + String currentText = ((Text) event.widget).getText(); |
| 75 | + //Build current string.... |
| 76 | + String text = currentText.substring(0, event.start) + event.text + currentText.substring(event.end); |
| 77 | + |
| 78 | + boolean result = text != null && text.length() > 0; |
| 79 | + if (!result) { |
| 80 | + setErrorMessage("Address Url is required"); |
| 81 | + canFinish = false; |
| 82 | + } else { |
| 83 | + canFinish = true; |
| 84 | + } |
| 85 | + // seriously..doit? |
| 86 | + event.doit = true; |
| 87 | + getWizard().getContainer().updateButtons(); |
58 | 88 | } |
59 | 89 | }); |
60 | | - Label label3 = new Label(composite, SWT.NONE); |
61 | | - label3.setText("Name"); |
62 | | - nameTextField = new Text(composite,SWT.BORDER | SWT.SINGLE); |
| 90 | + |
| 91 | + Label packageLabel = new Label(composite, SWT.NONE); |
| 92 | + packageLabel.setText("Package"); |
| 93 | + packageTextField = new Text(composite, SWT.BORDER | SWT.SINGLE); |
| 94 | + packageTextField.setLayoutData(gd); |
| 95 | + |
| 96 | + Label nameLabel = new Label(composite, SWT.NONE); |
| 97 | + nameLabel.setText("Name"); |
| 98 | + nameTextField = new Text(composite, SWT.BORDER | SWT.SINGLE); |
63 | 99 | nameTextField.setText("dto.java"); |
64 | 100 | nameTextField.setLayoutData(gd); |
65 | 101 | nameTextField.addVerifyListener(new VerifyListener() { |
66 | | - |
| 102 | + |
67 | 103 | @Override |
68 | 104 | public void verifyText(VerifyEvent event) { |
69 | | - String text = event.text; |
70 | | - //seriously..doit? |
71 | | - boolean result = text != null && text.length() > 0; |
72 | | - if(!result) { |
73 | | - setErrorMessage("A file name is required."); |
74 | | - } |
75 | | - event.doit = result; |
| 105 | + String currentText = ((Text) event.widget).getText(); |
| 106 | + //Build current string.... |
| 107 | + String text = currentText.substring(0, event.start) + event.text + currentText.substring(event.end); |
| 108 | + boolean result = text != null && text.length() > 0; |
| 109 | + if (!result) { |
| 110 | + setErrorMessage("A file name is required."); |
| 111 | + canFinish = false; |
| 112 | + } else { |
| 113 | + canFinish = true; |
| 114 | + } |
| 115 | + event.doit = true; |
| 116 | + getWizard().getContainer().updateButtons(); |
76 | 117 | } |
77 | 118 | }); |
78 | 119 |
|
79 | 120 | setControl(composite); |
| 121 | + composite.getShell().setSize(550, 365); |
80 | 122 | dialogChanged(); |
81 | 123 | } |
82 | | - |
| 124 | + |
83 | 125 | public String getAddressUrl() { |
84 | 126 | return addressUrlTextField.getText(); |
85 | 127 | } |
86 | | - |
| 128 | + |
87 | 129 | public String getFileName() { |
88 | 130 | return nameTextField.getText(); |
89 | 131 | } |
90 | | - |
| 132 | + |
91 | 133 | private void dialogChanged() { |
92 | | - updateStatus(null); |
| 134 | + updateStatus(null); |
93 | 135 | } |
94 | | - |
| 136 | + |
95 | 137 | private void updateStatus(String message) { |
96 | 138 | setErrorMessage(message); |
97 | 139 | setPageComplete(message == null); |
98 | 140 | } |
99 | | - |
100 | 141 | } |
0 commit comments