Commit 4faabc85 authored by Benedikt Engeser's avatar Benedikt Engeser

Wizard verbessert

parent 59387227
......@@ -2,6 +2,7 @@ package de.tum.in.www2.cupplugin.wizards;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.Thread.State;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -18,13 +19,17 @@ import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
......@@ -35,6 +40,7 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.ISetSelectionTarget;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
......@@ -47,6 +53,8 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
private NewJavaProjectWizardPageOne firstPage;
private NewJavaProjectWizardPageTwo secondPage;
private CupProjectWizardPage thirdPage;
private Map<String, Object> controls = new HashMap<String, Object>();
private Map<String, Object> options = new HashMap<String, Object>();
private static final String WIZARD_TITLE = "Create new CUP project";
private static final String WIZARD_DESCRIPTION1 = "CUP projects are based on Java projects. "
......@@ -72,7 +80,7 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
secondPage.setDescription(WIZARD_DESCRIPTION1);
addPage(secondPage);
thirdPage = new CupProjectWizardPage();
thirdPage = new CupProjectWizardPage(controls);
thirdPage.setTitle(WIZARD_TITLE);
thirdPage.setDescription(WIZARD_DESCRIPTION2);
addPage(thirdPage);
......@@ -151,7 +159,7 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
e2.printStackTrace();
return false;
}
createLaunchConfiguration(project, launchConfigFile);
ICommand[] commands = desc.getBuildSpec();
......@@ -179,6 +187,8 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
}
private void doFinish(IJavaProject jp, IProgressMonitor monitor) {
boolean generateCalculator = (Boolean) getOption("cup.createExamples.calculator");
boolean useJflex = (Boolean) getOption("cup.useFeature.jflex");
monitor.beginTask("Creating project ...", 2);
......@@ -189,24 +199,46 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
} catch (CoreException e1) {
e1.printStackTrace();
}
IContainer srcDir = (IContainer) project.findMember(new Path("src"));
IFolder cupDir = createDirectory(srcDir, monitor, "cup");
IFolder exampleDir = createDirectory(cupDir, monitor, "example");
IFile parserFile = createFile(project, monitor, "parser.cup",
getTemplate("parser.cup"));
createFile(project, monitor, "lexer.jflex", getTemplate("lexer.jflex"));
createFile(project, monitor, "input.txt", getTemplate("input.txt"));
createFile(project, monitor, "build.xml", getTemplate("build.xml"));
createFile(exampleDir, monitor, "Driver.java", getTemplate("Driver.java"));
IFile parserFile;
if (generateCalculator) {
parserFile = createFile(project, monitor, "parser.cup",
getTemplate("parser.cup"));
createFile(project, monitor, "lexer.jflex",
getTemplate("lexer.jflex"));
createFile(project, monitor, "input.txt", getTemplate("input.txt"));
createFile(project, monitor, "build.xml", getTemplate("build_jflex.xml"));
} else {
parserFile = createFile(project, monitor, "parser.cup",
getTemplate("empty_file"));
if (useJflex) {
createFile(project, monitor, "lexer.jflex",
getTemplate("empty_file"));
createFile(project, monitor, "build.xml", getTemplate("build_jflex.xml"));
}else{
createFile(project, monitor, "build.xml", getTemplate("build.xml"));
}
}
createFile(exampleDir, monitor, "Driver.java",
getTemplate("Driver.java"));
IFolder folder = createDirectory(project, monitor, "tools");
createFile(folder, monitor, "JFlex.jar", getTemplate("JFlex.jar"));
IFile runtimeFile = createFile(folder, monitor, "java-cup-11b-runtime.jar",
if(useJflex){
createFile(folder, monitor, "JFlex.jar", getTemplate("JFlex.jar"));
}
IFile runtimeFile = createFile(folder, monitor,
"java-cup-11b-runtime.jar",
getTemplate("java-cup-11b-runtime.jar"));
createFile(folder, monitor, "java-cup-11b.jar",
getTemplate("java-cup-11b.jar"));
......@@ -221,16 +253,17 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
IClasspathEntry[] newClassPath = new IClasspathEntry[oldClassPath.length + 1];
for (int i = 0; i < oldClassPath.length; i++)
newClassPath[i] = oldClassPath[i];
newClassPath[oldClassPath.length] = JavaCore.newLibraryEntry(runtimeFile.getFullPath(), null, null);
newClassPath[oldClassPath.length] = JavaCore.newLibraryEntry(
runtimeFile.getFullPath(), null, null);
try {
jp.setRawClasspath(newClassPath, monitor);
} catch (JavaModelException e1) {
e1.printStackTrace();
}
}
setBuilder(project);
monitor.worked(1);
......@@ -317,18 +350,54 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
+ "/build.xml}\"/>\n"
+ "<stringAttribute key=\"org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS\" value=\"full,incremental,\"/>\n"
+ "<booleanAttribute key=\"org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED\" value=\"true\"/>\n</launchConfiguration>";
IFile file = project.getFile(filename);
if (!file.exists()) {
byte[] bytes = FileContents.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
try {
byte[] bytes = FileContents.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
try {
file.create(source, IResource.NONE, null);
} catch (CoreException e) {
return false;
}
return true;
return true;
}
return false;
}
private void refreshOptions() {
UIJob j = new UIJob("refreshOptions") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
for (Map.Entry<String, Object> e : controls.entrySet()) {
if (e.getValue() instanceof Button) {
Button b = (Button) e.getValue();
if ((b.getStyle() & SWT.CHECK) == SWT.CHECK) {
options.put(e.getKey(),
new Boolean(b.getSelection()));
}
}
}
return Status.OK_STATUS;
}
};
j.setSystem(true);
j.schedule();
try {
j.join();
} catch (InterruptedException e) {
return;
}
return;
}
public Object getOption(String option) {
refreshOptions();
return options.get(option);
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.wizards;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
public class CupProjectWizardPage extends WizardPage {
public CupProjectWizardPage() {
private Map<String, Object> controls = new HashMap<String, Object>();
public CupProjectWizardPage(Map<String, Object> controls) {
super("wizardPage");
this.controls = controls;
setTitle("CUP Project Options");
setDescription("Configure CUP project ...");
}
......@@ -18,12 +25,26 @@ public class CupProjectWizardPage extends WizardPage {
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 3;
layout.numColumns = 1;
layout.verticalSpacing = 9;
Label label = new Label(container, SWT.NULL);
label.setText("&Test:");
label.setText("&CUP project options:");
addOptions(container);
setControl(container);
}
private void addOptions(Composite c) {
Button current = new Button(c, SWT.CHECK);
current.setText("Create calculator example files");
current.setSelection(true);
controls.put("cup.createExamples.calculator", current);
current = new Button(c, SWT.CHECK);
current.setText("Use jflex");
current.setSelection(true);
controls.put("cup.useFeature.jflex", current);
}
}
\ No newline at end of file
......@@ -7,7 +7,6 @@
<property name="tools" location="tools" />
<property name="base" location="." />
<taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="${tools}/JFlex.jar" />
<taskdef name="cup" classname="java_cup.anttask.CUPTask" classpath="${tools}/java-cup-11b.jar" />
<target name="generate">
......@@ -17,7 +16,7 @@
interface="true"
locations="true"
debugsymbols="true" />
<jflex file="lexer.jflex" destdir="${java}" />
</target>
<path id="libraries">
......
<project name="MyProject" default="compile" basedir=".">
<property name="java" location="src" />
<property name="classes" location="bin/cls" />
<property name="result" location="bin/jar" />
<property name="lib" location="lib" />
<property name="tools" location="tools" />
<property name="base" location="." />
<taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="${tools}/JFlex.jar" />
<taskdef name="cup" classname="java_cup.anttask.CUPTask" classpath="${tools}/java-cup-11b.jar" />
<target name="generate">
<cup srcfile="${base}/parser.cup" destdir="${java}"
parser="Parser"
interface="true"
locations="true"
debugsymbols="true" />
<jflex file="lexer.jflex" destdir="${java}" />
</target>
<path id="libraries">
<files includes="${tools}/java-cup-11b-runtime.jar" />
</path>
<target name="compile" depends="generate">
<mkdir dir="${classes}"/>
<mkdir dir="${result}"/>
<javac includeantruntime="false" srcdir="${java}" destdir="${classes}">
<classpath refid="libraries" />
</javac>
</target>
<target name="clean">
<delete file="${java}/Parser.java" />
<delete file="${java}/sym.java" />
<delete file="${java}/Scanner.java" />
<delete dir="${classes}" />
<delete dir="${result}" />
</target>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment