diff --git a/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF b/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF index 8e2cbf0c9..b12c1d49a 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF +++ b/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: TeaVM plugin for Eclipse -Bundle-SymbolicName: teavm-eclipse-plugin;singleton:=true +Bundle-SymbolicName: org.teavm.eclipse;singleton:=true Bundle-Version: 0.2.0.qualifer Bundle-Vendor: Alexey Andreev Bundle-RequiredExecutionEnvironment: JavaSE-1.7 diff --git a/teavm-eclipse/teavm-eclipse-plugin/plugin.xml b/teavm-eclipse/teavm-eclipse-plugin/plugin.xml index 1b78c5488..ec6c9a8e6 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/plugin.xml +++ b/teavm-eclipse/teavm-eclipse-plugin/plugin.xml @@ -45,4 +45,16 @@ id="org.teavm.eclipse.debugger"> + + + + + + + + + + \ No newline at end of file diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java index 876552f08..afe47a4ee 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java @@ -22,10 +22,13 @@ import org.eclipse.core.runtime.Plugin; * @author Alexey Andreev */ public class TeaVMEclipsePlugin extends Plugin { + public static final String ID = "org.teavm.eclipse"; + + public static final String NATURE_ID = "org.teavm.eclipse.nature"; + private static TeaVMEclipsePlugin defaultInstance; static { - System.out.println(); } public TeaVMEclipsePlugin() { @@ -35,6 +38,4 @@ public class TeaVMEclipsePlugin extends Plugin { public static TeaVMEclipsePlugin getDefault() { return defaultInstance; } - - public static final String ID = "org.teavm.eclipse"; } diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProjectNature.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProjectNature.java new file mode 100644 index 000000000..aa734f209 --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProjectNature.java @@ -0,0 +1,31 @@ +package org.teavm.eclipse; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; + +/** + * + * @author Alexey Andreev + */ +public class TeaVMProjectNature implements IProjectNature { + private IProject project; + + @Override + public void configure() throws CoreException { + } + + @Override + public void deconfigure() throws CoreException { + } + + @Override + public IProject getProject() { + return project; + } + + @Override + public void setProject(IProject project) { + this.project = project; + } +} diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyPage.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyPage.java new file mode 100644 index 000000000..c1ba8eb0a --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyPage.java @@ -0,0 +1,28 @@ +package org.teavm.eclipse.ui; + +import org.eclipse.core.resources.IProject; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.eclipse.ui.dialogs.PropertyPage; + +/** + * + * @author Alexey Andreev + */ +public class TeaVMProjectPropertyPage extends PropertyPage implements IWorkbenchPropertyPage { + private TeaVMProjectPropertyWidget widget; + + @Override + protected Control createContents(Composite parent) { + widget = new TeaVMProjectPropertyWidget(parent); + widget.load((IProject)getElement().getAdapter(IProject.class)); + return widget; + } + + @Override + public boolean performOk() { + widget.save((IProject)getElement().getAdapter(IProject.class)); + return super.performOk(); + } +} diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyWidget.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyWidget.java new file mode 100644 index 000000000..dd71da014 --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyWidget.java @@ -0,0 +1,121 @@ +package org.teavm.eclipse.ui; + +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +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.teavm.eclipse.TeaVMEclipsePlugin; + +/** + * + * @author Alexey Andreev + */ +public class TeaVMProjectPropertyWidget extends Composite { + private Button natureButton; + + public TeaVMProjectPropertyWidget(Composite parent) { + super(parent, SWT.NONE); + GridLayout layout = new GridLayout(1, false); + layout.verticalSpacing = 12; + layout.marginWidth = 12; + setLayout(layout); + natureButton = new Button(this, SWT.CHECK); + natureButton.setText("TeaVM build enabled"); + } + + public void load(IProject project) { + try { + natureButton.setSelection(project.hasNature(TeaVMEclipsePlugin.NATURE_ID)); + } catch (CoreException e) { + reportError(e); + } + } + + private void reportError(Throwable e) { + e.printStackTrace(); + Status status = new Status(Status.ERROR, TeaVMEclipsePlugin.ID, getToolTipText(), e); + ErrorDialog.openError(getShell(), "Error occured", "Error occured", status); + } + + public boolean save(IProject project) { + try { + if (natureButton.getSelection()) { + if (!project.hasNature(TeaVMEclipsePlugin.NATURE_ID)) { + addNature(project); + } + } else { + if (project.hasNature(TeaVMEclipsePlugin.NATURE_ID)) { + removeNature(project); + } + } + return true; + } catch (CoreException e) { + reportError(e); + return false; + } + } + + private void addNature(final IProject project) { + ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell()); + try { + progressDialog.run(false, true, new IRunnableWithProgress() { + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + IProjectDescription projectDescription = project.getDescription(); + String[] natureIds = projectDescription.getNatureIds(); + natureIds = Arrays.copyOf(natureIds, natureIds.length + 1); + natureIds[natureIds.length - 1] = TeaVMEclipsePlugin.NATURE_ID; + projectDescription.setNatureIds(natureIds); + project.setDescription(projectDescription, monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } + } + }); + } catch (InterruptedException e) { + reportError(e); + } catch (InvocationTargetException e) { + reportError(e.getTargetException()); + } + } + + private void removeNature(final IProject project) { + ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell()); + try { + progressDialog.run(false, true, new IRunnableWithProgress() { + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + String[] natureIds = project.getDescription().getNatureIds(); + String[] newNatureIds = new String[natureIds.length - 1]; + for (int i = 0; i < natureIds.length; ++i) { + if (natureIds.equals(TeaVMEclipsePlugin.NATURE_ID)) { + System.arraycopy(natureIds, 0, newNatureIds, 0, i - 1); + System.arraycopy(natureIds, i + 1, newNatureIds, i, newNatureIds.length - i); + project.getDescription().setNatureIds(newNatureIds); + break; + } + } + } catch (CoreException e) { + throw new InvocationTargetException(e); + } + } + }); + } catch (InterruptedException e) { + reportError(e); + } catch (InvocationTargetException e) { + reportError(e.getTargetException()); + } + } +}