1 package javafxmlpackage.wizards;
3 import java.util.regex.Matcher;
4 import java.util.regex.Pattern;
6 import org.eclipse.core.resources.IContainer;
7 import org.eclipse.core.resources.IResource;
8 import org.eclipse.core.resources.ResourcesPlugin;
9 import org.eclipse.core.runtime.Path;
10 import org.eclipse.jface.dialogs.IDialogPage;
11 import org.eclipse.jface.viewers.ISelection;
12 import org.eclipse.jface.viewers.IStructuredSelection;
13 import org.eclipse.jface.window.Window;
14 import org.eclipse.jface.wizard.WizardPage;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.swt.widgets.Text;
24 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
44 setTitle(
"Uusi JavaFXML Package");
45 setDescription(
"Luo uusi package");
54 Composite container =
new Composite(parent, SWT.NULL);
56 GridLayout layout =
new GridLayout();
58 container.setLayout(layout);
59 layout.numColumns = 3;
61 layout.verticalSpacing = 9;
62 Label label =
new Label(container, SWT.NULL);
63 label.setText(
"&Project src folder:");
66 GridData gd =
new GridData(GridData.FILL_HORIZONTAL);
72 Button button =
new Button(container, SWT.PUSH);
73 button.setText(
"Browse...");
75 button.addSelectionListener(
new SelectionAdapter() {
77 public void widgetSelected(SelectionEvent e) {
82 label =
new Label(container, SWT.NULL);
83 label.setText(
"&Packagen nimi:");
84 packageName =
new Text(container, SWT.BORDER | SWT.SINGLE);
86 gd =
new GridData(GridData.FILL_HORIZONTAL);
91 label =
new Label(container, SWT.NULL);
93 label =
new Label(container, SWT.NULL);
94 label.setText(
"&Ohjelman nimi:");
96 fileName =
new Text(container, SWT.BORDER | SWT.SINGLE);
97 gd =
new GridData(GridData.FILL_HORIZONTAL);
104 setControl(container);
113 &&
selection instanceof IStructuredSelection) {
114 IStructuredSelection ssel = (IStructuredSelection)
selection;
117 Object obj = ssel.getFirstElement();
119 if (obj instanceof IResource) {
120 IContainer container;
122 if (obj instanceof IContainer) {
123 container = (IContainer) obj;
124 pathi = container.getFullPath().toString();
125 if (!pathi.matches(
".*/src/"))
126 pathi = container.getFullPath().toString() +
"/src/";
129 container = ((IResource) obj).getParent();
130 pathi = container.getFullPath().toString();
132 Pattern
p = Pattern.compile(
"^(.*/src)(.*)");
133 Matcher m = p.matcher(pathi);
136 if (!m.group(2).isEmpty()) {
137 String mg = m.group(2).replace(
'/',
'.');
139 if (mg.charAt(0) ==
'.')
152 String stringi = obj.toString();
155 Pattern
p = Pattern.compile(
"(.*)src \\[in ([^\\]]+)\\]*.");
156 Matcher m = p.matcher(stringi);
160 if (!m.group(1).isEmpty()) {
161 String[] splitti = m.group(1).split(
" ");
164 if (!splitti[0].matches(
".*\\.java$") && !splitti[0].matches(
"^\\[.*"))
179 ContainerSelectionDialog dialog =
new ContainerSelectionDialog(
180 getShell(), ResourcesPlugin.getWorkspace().getRoot(),
false,
181 "Select project src folder");
182 if (dialog.open() == Window.OK) {
183 Object[] result = dialog.getResult();
184 if (result.length == 1) {
195 IResource container = ResourcesPlugin.getWorkspace().getRoot()
205 if (container == null
206 || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
210 if (!container.isAccessible()) {
214 if (fileN.length() == 0 || packageN.length() == 0) {
215 updateStatus(
"Paketin tai ohjelman nimi määrittämättä");
220 if (!Pattern.matches(
"[a-zA-ZäöåÅÄÖ0-9]+", fileN) || !Pattern.matches(
"[a-zA-ZäöåÅÄÖ/.0-9]+", packageN)) {
221 updateStatus(
"Ohjelman tai packagen nimessä ei voi olla merkkejä");
225 if (packageN.lastIndexOf(
'.') == packageN.length() - 1) {
230 if (packageN.indexOf(
'.') == 0) {
235 if (fileN.lastIndexOf(
'.') != -1) {
244 setErrorMessage(message);
245 setPageComplete(message == null);