Mercurial > hg > thermostat-tools-eclipse
changeset 0:430e3d29c3ac
First Commit
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.classpath Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>Thermostat-Plugin</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.jdt.core.prefs Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/META-INF/MANIFEST.MF Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Thermostat-Plugin +Bundle-SymbolicName: Thermostat-Plugin;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: com.redhat.thermostat.plugin.eclipse.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.jface.text, + org.eclipse.ui.editors, + org.eclipse.core.resources, + org.eclipse.ui.ide, + org.eclipse.jdt;bundle-version="3.9.0", + org.eclipse.jdt.launching, + org.eclipse.jdt.core;bundle-version="3.9.0", + org.eclipse.ui.forms;bundle-version="3.6.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-ActivationPolicy: lazy
Binary file bin/com/redhat/thermostat/plugin/eclipse/form/editors/ExtensionsPage$1.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/form/editors/OpenThermostatPluginEditor.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/form/editors/ThermostatFormEditor.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizard.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPage$1.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPage$2.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPage$3.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPage$4.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPage$5.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPage.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPageTwo$1.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPageTwo.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatWizardPage$1.class has changed
Binary file bin/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatWizardPage$2.class has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build.properties Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugin.xml Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + + <extension + point="org.eclipse.ui.editors"> + <editor + name="Sample XML Editor" + extensions="xml" + icon="icons/sample.gif" + contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor" + class="com.redhat.thermostat.plugin.eclipse.editors.XMLEditor" + id="thermostatplugin.editors.XMLEditor"> + </editor> + <editor + class="thermostatplugin.editors.MultiPageEditor" + contributorClass="thermostatplugin.editors.MultiPageEditorContributor" + extensions="xml" + icon="icons/sample.gif" + id="thermostatplugin.editors.MultiPageEditor" + name="Thermostat Plugin Editor"> + </editor> + </extension> + + <extension + point="org.eclipse.ui.actionSets"> + <actionSet + label="Thermostat Action Set" + visible="true" + id="Thermostat-Plugin.actionSet"> + <menu + label="Thermostat" + id="thermostatMenu"> + <separator + name="thermostatGroup"> + </separator> + </menu> + <action + label="Create new Thermostat Plugin" + icon="icons/thermostat.gif" + class="com.redhat.thermostat.plugin.eclipse.actions.ThermostatAction" + tooltip="Create new Thermostat Plugin" + menubarPath="thermostatMenu/thermostatGroup" + toolbarPath="thermostatGroup" + id="thermostatplugin.actions.ThermostatAction"> + </action> + </actionSet> + </extension> + + <extension + point="org.eclipse.ui.newWizards"> + <category + name="Thermostat" + id="Thermostat-Plugin"> + </category> + <wizard + name="Thermostat Plugin" + icon="icons/thermostat.gif" + category="Thermostat-Plugin" + class="com.redhat.thermostat.plugin.eclipse.wizards.ThermostatProjectCreationWizard" + id="thermostatplugin.wizards.CreateNewThermostatPluginWizard"> + </wizard> + </extension> + + <extension + point="org.eclipse.ui.editors"> + <editor + name="Thermostat Plugin" + default="true" + icon="icons/thermostat.gif" + class="com.redhat.thermostat.plugin.eclipse.form.editors.ThermostatFormEditor" + id="org.eclipse.ui.forms.article.base-editor"> + </editor> + </extension> + + <extension + point="org.eclipse.ui.actionSets"> + <actionSet + label="Thermostat Action Set" + id="org.eclipse.ui.forms.article.actionSet"> + <menu + label="Thermostat Form Editor" + id="org.eclipse.ui.forms.article.menu"> + <groupMarker + name="group"> + </groupMarker> + </menu> + <action + label="Thermostat Plugin Editor" + class="com.redhat.thermostat.plugin.eclipse.form.editors.OpenThermostatPluginEditor" + menubarPath="org.eclipse.ui.forms.article.menu/group" + id="org.eclipse.ui.forms.article.simple"> + </action> + </actionSet> + </extension> +</plugin>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/Activator.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,61 @@ +package com.redhat.thermostat.plugin.eclipse; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "Thermostat-Plugin"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/actions/ThermostatAction.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,66 @@ +package com.redhat.thermostat.plugin.eclipse.actions; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; + +import com.redhat.thermostat.plugin.eclipse.wizards.ThermostatWizard; + +/** + * Our sample action implements workbench action delegate. + * The action proxy will be created by the workbench and + * shown in the UI. When the user tries to use the action, + * this delegate will be created and execution will be + * delegated to it. + * @see IWorkbenchWindowActionDelegate + */ +public class ThermostatAction implements IWorkbenchWindowActionDelegate { + private IWorkbenchWindow window; + /** + * The constructor. + */ + public ThermostatAction() { + } + + /** + * The action has been activated. The argument of the + * method represents the 'real' action sitting + * in the workbench UI. + * @see IWorkbenchWindowActionDelegate#run + */ + public void run(IAction action) { +// ThermostatProjectCreationWizard wizard = new ThermostatProjectCreationWizard(); + ThermostatWizard wizard = new ThermostatWizard(); + WizardDialog wizardDialog = new WizardDialog(window.getShell(), wizard); + wizardDialog.open(); + } + + /** + * Selection in the workbench has been changed. We + * can change the state of the 'real' action here + * if we want, but this can only happen after + * the delegate has been created. + * @see IWorkbenchWindowActionDelegate#selectionChanged + */ + public void selectionChanged(IAction action, ISelection selection) { + } + + /** + * We can use this method to dispose of any system + * resources we previously allocated. + * @see IWorkbenchWindowActionDelegate#dispose + */ + public void dispose() { + } + + /** + * We will cache window object in order to + * be able to provide parent shell for the message dialog. + * @see IWorkbenchWindowActionDelegate#init + */ + public void init(IWorkbenchWindow window) { + this.window = window; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/form/editors/ExtensionsPage.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,72 @@ +package com.redhat.thermostat.plugin.eclipse.form.editors; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.editor.FormEditor; +import org.eclipse.ui.forms.editor.FormPage; +import org.eclipse.ui.forms.widgets.ScrolledForm; + +public class ExtensionsPage extends FormPage { + public ExtensionsPage(FormEditor editor) { + super(editor, "first", "Extension"); + } + + protected void createFormContent(IManagedForm managedForm) { + ScrolledForm form = managedForm.getForm(); + managedForm.getToolkit(); + form.setText("All Extensions"); + + managedForm.getForm().getBody().setLayout(new GridLayout(2, false)); + + Label extensionNameLabel = new Label(managedForm.getForm().getBody(), + SWT.NONE); + extensionNameLabel.setText("Initial Extension Name: "); + extensionNameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, + false, false, 1, 1)); + + final Text extensionNameText = new Text(managedForm.getForm().getBody(), + SWT.BORDER); + extensionNameText.setText("Extension name..."); + extensionNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, + false, false, 1, 1)); + + Label extensionEnvironmentLabel = new Label(managedForm.getForm().getBody(), + SWT.NONE); + extensionEnvironmentLabel.setText("Extension Environment: "); + extensionEnvironmentLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, + false, false, 1, 1)); + + Text extensionEnvironmentText = new Text(managedForm.getForm().getBody(), + SWT.BORDER); + extensionEnvironmentText.setText("Extension Environment..."); + extensionEnvironmentText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, + false, false, 1, 1)); + + Button saveButton = new Button(managedForm.getForm().getBody(), SWT.NONE); + saveButton.setText("Save..."); + saveButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, + false, false, 1, 1)); + saveButton.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + extensionNameText.setText("Saved..."); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + + } + + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/form/editors/FormEditorInput.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,47 @@ +package com.redhat.thermostat.plugin.eclipse.form.editors; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.*; + +public class FormEditorInput implements IEditorInput { + + public FormEditorInput(String name) { + // TODO Auto-generated constructor stub + } + + @Override + public Object getAdapter(Class adapter) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean exists() { + // TODO Auto-generated method stub + return true; + } + + @Override + public ImageDescriptor getImageDescriptor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IPersistableElement getPersistable() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getToolTipText() { + // TODO Auto-generated method stub + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/form/editors/OpenThermostatPluginEditor.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,42 @@ +package com.redhat.thermostat.plugin.eclipse.form.editors; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PartInitException; + +public class OpenThermostatPluginEditor implements + IWorkbenchWindowActionDelegate { + private IWorkbenchWindow window; + + @Override + public void run(IAction action) { + IWorkbenchPage page = window.getActivePage(); + try { + page.openEditor(new FormEditorInput("Simple Editor..."), + "org.eclipse.ui.forms.article.base-editor"); + } catch (PartInitException e) { + System.out.println(e); + } + } + + @Override + public void selectionChanged(IAction action, ISelection selection) { + // TODO Auto-generated method stub + + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + + @Override + public void init(IWorkbenchWindow window) { + this.window = window; + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/form/editors/ThermostatFormEditor.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,43 @@ +package com.redhat.thermostat.plugin.eclipse.form.editors; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.forms.editor.FormEditor; +public class ThermostatFormEditor extends FormEditor { + + public ThermostatFormEditor() { + } + + protected void addPages() { + try { + addPage(new ExtensionsPage(this)); +// int index = addPage(new Composite(getContainer(), SWT.NULL)); +// setPageText(index, "Composite"); + } + catch (PartInitException e) { + // + } + } + + @Override + public void doSave(IProgressMonitor monitor) { + // TODO Auto-generated method stub + + } + + @Override + public void doSaveAs() { + // TODO Auto-generated method stub + + } + + @Override + public boolean isSaveAsAllowed() { + // TODO Auto-generated method stub + return false; + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizard.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,174 @@ +package com.redhat.thermostat.plugin.eclipse.wizards; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.launching.IVMInstall; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jdt.launching.LibraryLocation; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWizard; + +public class ThermostatProjectCreationWizard extends Wizard implements + INewWizard { + private ThermostatProjectCreationWizardPage page; + private ThermostatProjectCreationWizardPageTwo pageTwo; + private HashMap<String, Boolean> selectedComponents; + + public ThermostatProjectCreationWizard() { + super(); + setNeedsProgressMonitor(true); + } + + public void addPages() { + setWindowTitle("Create New Thermostat Plugin"); + page = new ThermostatProjectCreationWizardPage(); + addPage(page); + pageTwo = new ThermostatProjectCreationWizardPageTwo(); + addPage(pageTwo); + } + + public boolean performFinish() { + try { + selectedComponents = page.getSelectedComponents(); + + createProject(page.getProjectName()); + for (Entry<String, Boolean> temp : selectedComponents.entrySet()) { + if (temp.getValue()) { + createProject(page.getProjectName() + "-" + temp.getKey()); + } + } + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return true; + } + + private void createProject(String projectTitle) throws CoreException { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IProject project = root.getProject(projectTitle); + if (project.exists()) { + project.delete(true, null); + } + try { + project.create(null); + project.open(null); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // Set the Java nature to created project + IProjectDescription description = project.getDescription(); + description.setNatureIds(new String[] { JavaCore.NATURE_ID }); + project.setDescription(description, null); + + // Create Java project + IJavaProject javaProject = JavaCore.create(project); + + // Add bin/ouput folder + IFolder binFolder = project.getFolder("bin"); + binFolder.create(false, true, null); + javaProject.setOutputLocation(binFolder.getFullPath(), null); + + // Add libs to project class path + List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); + IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall(); + LibraryLocation[] locations = JavaRuntime + .getLibraryLocations(vmInstall); + for (LibraryLocation element : locations) { + entries.add(JavaCore.newLibraryEntry( + element.getSystemLibraryPath(), null, null)); + } + + javaProject.setRawClasspath( + entries.toArray(new IClasspathEntry[entries.size()]), null); + + // If root then folder create sub directories corresponding components + if (page.getProjectName().equals(projectTitle)) { + for (Entry<String, Boolean> currentComponent : selectedComponents + .entrySet()) { + if (currentComponent.getValue()) { + IFolder componentFolder = project.getFolder(currentComponent + .getKey()); + componentFolder.create(false, true, null); + } + } + } + + // Create src folder + IFolder srcFolder = project.getFolder("src"); + srcFolder.create(false, true, null); + + IFolder srcMainFolder = srcFolder.getFolder("main"); + srcMainFolder.create(true, true, null); + + IFolder srcMainJavaFolder = srcMainFolder.getFolder("java"); + srcMainJavaFolder.create(true, true, null); + + IPackageFragmentRoot packageFragmentRoot = javaProject + .getPackageFragmentRoot(srcMainJavaFolder); + IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); + IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; + System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); + newEntries[oldEntries.length] = JavaCore + .newSourceEntry(packageFragmentRoot.getPath()); + javaProject.setRawClasspath(newEntries, null); + + IPackageFragment pack = javaProject.getPackageFragmentRoot( + srcMainJavaFolder).createPackageFragment(pageTwo.getPackageName(), + false, null); + + StringBuffer buffer = new StringBuffer(); + buffer.append("package " + pack.getElementName() + ";\n"); + buffer.append("\n"); + // Empty file for testing + ICompilationUnit cu = pack.createCompilationUnit( + "ThermostatPlugin.java", buffer.toString(), false, null); + + // Create thermostat-plugin.xml in the main project + if (page.getProjectName().equals(projectTitle)) { + final IFile file = project.getFile("thermostat-plugin.xml"); + try { + InputStream stream = openContentStream(); + if (file.exists()) { + file.setContents(stream, true, true, null); + } else { + file.create(stream, true, null); + } + stream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private InputStream openContentStream() { + String contents = "<--!Welcome to Thermostat-->"; // Sample content + return new ByteArrayInputStream(contents.getBytes()); + } + public void init(IWorkbench workbench, IStructuredSelection selection) { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPage.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,155 @@ +package com.redhat.thermostat.plugin.eclipse.wizards; + +import java.util.HashMap; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +public class ThermostatProjectCreationWizardPage extends WizardPage { + private Text projectText; + + private boolean agentSelected = false; + private boolean clientSelected = false; + private boolean commonSelected = false; + private boolean distributionSelected = false; + + public ThermostatProjectCreationWizardPage() { + super("wizardPage"); + setTitle("Thermostat Wizard"); + setDescription("This wizard creates a new Thermostat Plugin."); + } + + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + Label projectNameLabel = new Label(container, SWT.NULL); + projectNameLabel.setText("&Project name:"); + + projectText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + projectText.setLayoutData(gd); + projectText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + dialogChanged(); + } + }); + + Label componentLabel = new Label(container, SWT.NULL); + componentLabel.setText("&Select components you would like to include in the project: "); + + Button agentButton = new Button(container, SWT.CHECK); + agentButton.setText("Agent"); + agentButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e){ + Button button = (Button) e.widget; + if (button.getSelection()) { + agentSelected = true; + } else { + agentSelected = false; + } + } + }); + + Button clientButton = new Button(container, SWT.CHECK); + clientButton.setText("Client"); + clientButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e){ + Button button = (Button) e.widget; + if (button.getSelection()) { + clientSelected = true; + } else { + clientSelected = false; + } + } + }); + + Button commonButton = new Button(container, SWT.CHECK); + commonButton.setText("Common"); + commonButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e){ + Button button = (Button) e.widget; + if (button.getSelection()) { + commonSelected = true; + } else { + commonSelected = false; + } + } + }); + + Button distributionButton = new Button(container, SWT.CHECK); + distributionButton.setText("Distribution"); + distributionButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e){ + Button button = (Button) e.widget; + if (button.getSelection()) { + distributionSelected = true; + } else { + distributionSelected = false; + } + } + }); + + initialize(); + dialogChanged(); + + setControl(container); + } + + private void initialize() { + projectText.setText("Thermostat-Plugin-Project"); + } + + private void dialogChanged() { + String projectName = getProjectName(); + if (projectName.length() == 0) { + updateStatus("Project name must be specified"); + return; + } + if (projectName.replace('\\', '/').indexOf('/', 1) > 0) { + updateStatus("Project name must be valid"); + return; + } + if (projectName.contains(" ")) { + updateStatus("Project name must be valid"); + return; + } + updateStatus(null); + } + + private void updateStatus(String message) { + setErrorMessage(message); + setPageComplete(message == null); + } + + public String getProjectName() { + return projectText.getText(); + } + + public HashMap<String, Boolean> getSelectedComponents() { + HashMap<String, Boolean> selectedComponentBoxes = new HashMap<String, Boolean>(); + + selectedComponentBoxes.put("agent", agentSelected); + selectedComponentBoxes.put("client", clientSelected); + selectedComponentBoxes.put("common", commonSelected); + selectedComponentBoxes.put("distribution", distributionSelected); + + return selectedComponentBoxes; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatProjectCreationWizardPageTwo.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,71 @@ +package com.redhat.thermostat.plugin.eclipse.wizards; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +public class ThermostatProjectCreationWizardPageTwo extends WizardPage { + private Text packageText; + + public ThermostatProjectCreationWizardPageTwo() { + super("wizardPage"); + setTitle("Thermostat Wizard"); + setDescription("This wizard creates a new Thermostat Plugin."); + } + + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + Label packageNameLabel = new Label(container, SWT.NULL); + packageNameLabel.setText("&Package name:"); + + packageText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + packageText.setLayoutData(gd); + packageText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + dialogChanged(); + } + }); + + initialize(); + dialogChanged(); + + setControl(container); + } + + private void initialize() { + packageText.setText("com.redhat.thermostat.plugin"); + } + + private void dialogChanged() { + String packageName = getPackageName(); + if (packageName.length() == 0) { + updateStatus("Package name must be specified"); + return; + } + if (packageName.contains(" ")) { + updateStatus("Package name must be valid"); + return; + } + updateStatus(null); + } + + private void updateStatus(String message) { + setErrorMessage(message); + setPageComplete(message == null); + } + + public String getPackageName() { + return packageText.getText(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatWizard.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,146 @@ +package com.redhat.thermostat.plugin.eclipse.wizards; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.core.runtime.*; +import org.eclipse.jface.operation.*; +import java.lang.reflect.InvocationTargetException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.CoreException; +import java.io.*; +import org.eclipse.ui.*; +import org.eclipse.ui.ide.IDE; + +public class ThermostatWizard extends Wizard implements INewWizard { + private ThermostatWizardPage page; + private ISelection selection; + + /** + * Constructor for SampleNewWizard. + */ + public ThermostatWizard() { + super(); + setNeedsProgressMonitor(true); + } + + public void addPages() { + setWindowTitle("Extract"); + page = new ThermostatWizardPage(selection); + addPage(page); + } + + /** + * This method is called when 'Finish' button is pressed in the wizard. We + * will create an operation and run it using wizard as execution context. + */ + public boolean performFinish() { + final String containerName = page.getContainerName(); + final String fileName = "thermostat-plugin.xml"; + IRunnableWithProgress op = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) + throws InvocationTargetException { + try { + doFinish(containerName, fileName, monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + } + }; + try { + getContainer().run(true, false, op); + } catch (InterruptedException e) { + return false; + } catch (InvocationTargetException e) { + Throwable realException = e.getTargetException(); + MessageDialog.openError(getShell(), "Error", + realException.getMessage()); + return false; + } + return true; + } + + private void doFinish(String containerName, String fileName, + IProgressMonitor monitor) throws CoreException { + // create a sample file + monitor.beginTask("Creating " + fileName, 2); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource resource = root.findMember(new Path(containerName)); + if (!resource.exists() || !(resource instanceof IContainer)) { + throwCoreException("Container \"" + containerName + + "\" does not exist."); + } + IContainer container = (IContainer) resource; + final IFile file = container.getFile(new Path(fileName)); + try { + InputStream stream = openContentStream(); + if (file.exists()) { + file.setContents(stream, true, true, monitor); + } else { + file.create(stream, true, monitor); + } + stream.close(); + } catch (IOException e) { + } + monitor.worked(1); + monitor.setTaskName("Opening file for editing..."); + getShell().getDisplay().asyncExec(new Runnable() { + public void run() { + IWorkbenchPage page = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage(); + try { + IDE.openEditor(page, file, true); + } catch (PartInitException e) { + } + } + }); + monitor.worked(1); + } + + private InputStream openContentStream() { + String contents = "<?xml version=\"1.0\"?>\n" + + "<plugin xmlns=\"http://icedtea.classpath.org/thermostat/plugins/v1.0\"\n" + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + + "xsi:schemaLocation=\"http://icedtea.classpath.org/thermostat/plugins/v1.0 thermostat-plugin.xsd\">\n" + + "<commands>\n" + + "<command>\n" + + "<name>test</name>\n" + + "<description>print the kernel cmdline for a host</description>\n" + + "<options>\n" + + "<option>\n" + + "<long>aaaa</long>\n" + + "<short>a</short>\n" + + "</option>\n" + + "</options>\n" + + "<bundles>\n" + + "</bundles>\n" + + "<dependencies>\n" + + "</dependencies>\n" + + "</command>\n" + + "</commands>\n" + + "<extensions>\n" + + "<extension>\n" + + "<name>agent</name>\n" + + "<bundles>\n" + + "<bundle>thermostat-plug-in-agent-0.0.2-SNAPSHOT.jar</bundle>\n" + + "<bundle>thermostat-plug-in-storage-common-0.0.2-SNAPSHOT.jar</bundle>\n" + + "</bundles>\n" + "</extension>\n" + "</extensions>\n" + "</plugin>"; + + return new ByteArrayInputStream(contents.getBytes()); + } + + private void throwCoreException(String message) throws CoreException { + IStatus status = new Status(IStatus.ERROR, "Thermostat-Plugin", + IStatus.OK, message, null); + throw new CoreException(status); + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.selection = selection; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/wizards/ThermostatWizardPage.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,124 @@ +package com.redhat.thermostat.plugin.eclipse.wizards; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ContainerSelectionDialog; + +public class ThermostatWizardPage extends WizardPage { + private Text containerText; + + private ISelection selection; + + public ThermostatWizardPage(ISelection selection) { + super("wizardPage"); + setTitle("Thermostat Wizard"); + setDescription("This wizard creates a new Thermostat Plugin."); + this.selection = selection; + } + + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + layout.numColumns = 3; + layout.verticalSpacing = 9; + Label label = new Label(container, SWT.NULL); + label.setText("&Container:"); + + containerText = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + containerText.setLayoutData(gd); + containerText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + dialogChanged(); + } + }); + + Button button = new Button(container, SWT.PUSH); + button.setText("Browse..."); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleBrowse(); + } + }); + initialize(); + dialogChanged(); + + setControl(container); + } + + private void initialize() { + if (selection != null && selection.isEmpty() == false + && selection instanceof IStructuredSelection) { + IStructuredSelection ssel = (IStructuredSelection) selection; + if (ssel.size() > 1) + return; + Object obj = ssel.getFirstElement(); + if (obj instanceof IResource) { + IContainer container; + if (obj instanceof IContainer) + container = (IContainer) obj; + else + container = ((IResource) obj).getParent(); + containerText.setText(container.getFullPath().toString()); + } + } + } + + private void handleBrowse() { + ContainerSelectionDialog dialog = new ContainerSelectionDialog( + getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, + "Select new file container"); + if (dialog.open() == ContainerSelectionDialog.OK) { + Object[] result = dialog.getResult(); + if (result.length == 1) { + containerText.setText(((Path) result[0]).toString()); + } + } + } + + private void dialogChanged() { + IResource container = ResourcesPlugin.getWorkspace().getRoot() + .findMember(new Path(getContainerName())); + + if (getContainerName().length() == 0) { + updateStatus("File container must be specified"); + return; + } + if (container == null + || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) { + updateStatus("File container must exist"); + return; + } + if (!container.isAccessible()) { + updateStatus("Project must be writable"); + return; + } + updateStatus(null); + } + + private void updateStatus(String message) { + setErrorMessage(message); + setPageComplete(message == null); + } + + public String getContainerName() { + return containerText.getText(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thermostatplugin/editors/MultiPageEditor.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,344 @@ +package thermostatplugin.editors; + +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.StringTokenizer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FontDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.ui.part.MultiPageEditorPart; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import org.w3c.dom.CharacterData; + +/** + * An example showing how to create a multi-page editor. This example has 3 + * pages: + * <ul> + * <li>page 0 contains a nested text editor. + * <li>page 1 allows you to change the font used in page 2 + * <li>page 2 shows the words in page 0 in sorted order + * </ul> + */ +public class MultiPageEditor extends MultiPageEditorPart implements + IResourceChangeListener { + + /** The text editor used in page 0. */ + private TextEditor editor; + + /** The font chosen in page 1. */ + private Font font; + + /** The text widget used in page 2. */ + private StyledText text; + + private String extensionName; + private String extensionDescription; + + /** + * Creates a multi-page editor example. + */ + public MultiPageEditor() { + super(); + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + extensionName = new String(""); + } + + /** + * Creates page 0 of the multi-page editor, which contains a text editor. + */ + void createPage0() { + try { + editor = new TextEditor(); + int index = addPage(editor, getEditorInput()); + setPageText(index, editor.getTitle()); + } catch (PartInitException e) { + ErrorDialog.openError(getSite().getShell(), + "Error creating nested text editor", null, e.getStatus()); + } + } + + /** + * Creates page 2 of the multi-page editor, which shows the sorted text. + */ + void createPage1() { + Composite composite = new Composite(getContainer(), SWT.NONE); + FillLayout layout = new FillLayout(); + composite.setLayout(layout); + text = new StyledText(composite, SWT.H_SCROLL | SWT.V_SCROLL); + text.setEditable(false); + + int index = addPage(composite); + setPageText(index, "Preview"); + } + + /** + * Creates the pages of the multi-page editor. + */ + protected void createPages() { + createPage0(); + createExtensionsPage(); + createPage1(); + } + + private void createExtensionsPage() { + getEditorInput(); + Composite composite = new Composite(getContainer(), SWT.NONE); + GridLayout layout = new GridLayout(); + composite.setLayout(layout); + layout.numColumns = 2; + + Label extensionNameLabel = new Label(composite, SWT.NONE); + extensionNameLabel.setText("Initial Extension Name: "); + extensionNameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, + false, false, 1, 1)); + getAttributes(); + final Text extensionNameText = new Text(composite, SWT.BORDER); + extensionNameText.setText(extensionName); + // extensionNameText.setText("stringgg"); + extensionNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, + false, false, 1, 1)); + + Label extensionDescriptionLabel = new Label(composite, SWT.NONE); + extensionDescriptionLabel.setText("Extension Description: "); + extensionDescriptionLabel.setLayoutData(new GridData(SWT.RIGHT, + SWT.CENTER, false, false, 1, 1)); + + Text extensionEnvironmentText = new Text(composite, SWT.BORDER); + extensionEnvironmentText.setText(extensionDescription); + extensionEnvironmentText.setLayoutData(new GridData(SWT.FILL, + SWT.CENTER, false, false, 1, 1)); + Button fontButton = new Button(composite, SWT.NONE); + GridData gd = new GridData(GridData.BEGINNING); + gd.horizontalSpan = 2; + fontButton.setLayoutData(gd); + fontButton.setText("Save..."); + + fontButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { +// setFont(); + extensionNameText.setText("Saved..."); + } + }); + + int index = addPage(composite); + setPageText(index, "Extensions"); + + } + + /** + * The <code>MultiPageEditorPart</code> implementation of this + * <code>IWorkbenchPart</code> method disposes all nested editors. + * Subclasses may extend. + */ + public void dispose() { + ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + super.dispose(); + } + + /** + * Saves the multi-page editor's document. + */ + public void doSave(IProgressMonitor monitor) { + getEditor(0).doSave(monitor); + } + + /** + * Saves the multi-page editor's document as another file. Also updates the + * text for page 0's tab, and updates this multi-page editor's input to + * correspond to the nested editor's. + */ + public void doSaveAs() { + IEditorPart editor = getEditor(0); + editor.doSaveAs(); + setPageText(0, editor.getTitle()); + setInput(editor.getEditorInput()); + } + + /* + * (non-Javadoc) Method declared on IEditorPart + */ + public void gotoMarker(IMarker marker) { + setActivePage(0); + IDE.gotoMarker(getEditor(0), marker); + } + + /** + * The <code>MultiPageEditorExample</code> implementation of this method + * checks that the input is an instance of <code>IFileEditorInput</code>. + */ + public void init(IEditorSite site, IEditorInput editorInput) + throws PartInitException { + if (!(editorInput instanceof IFileEditorInput)) + throw new PartInitException( + "Invalid Input: Must be IFileEditorInput"); + super.init(site, editorInput); + } + + /* + * (non-Javadoc) Method declared on IEditorPart. + */ + public boolean isSaveAsAllowed() { + return true; + } + + /** + * Calculates the contents of page 2 when the it is activated. + */ + protected void pageChange(int newPageIndex) { + super.pageChange(newPageIndex); + if (newPageIndex == 2) { + sortWords(); + } + } + + /** + * Closes all project files on project close. + */ + public void resourceChanged(final IResourceChangeEvent event) { + if (event.getType() == IResourceChangeEvent.PRE_CLOSE) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + IWorkbenchPage[] pages = getSite().getWorkbenchWindow() + .getPages(); + for (int i = 0; i < pages.length; i++) { + if (((FileEditorInput) editor.getEditorInput()) + .getFile().getProject() + .equals(event.getResource())) { + IEditorPart editorPart = pages[i].findEditor(editor + .getEditorInput()); + pages[i].closeEditor(editorPart, true); + } + } + } + }); + } + } + + /** + * Sets the font related data to be applied to the text in page 2. + */ + void setFont() { + FontDialog fontDialog = new FontDialog(getSite().getShell()); + fontDialog.setFontList(text.getFont().getFontData()); + FontData fontData = fontDialog.open(); + if (fontData != null) { + if (font != null) + font.dispose(); + font = new Font(text.getDisplay(), fontData); + text.setFont(font); + } + } + + void getAttributes() { + String editorText = editor.getDocumentProvider() + .getDocument(editor.getEditorInput()).get(); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder; + + InputSource inputStream = new InputSource(); + inputStream.setCharacterStream(new StringReader(editorText)); + try { + dBuilder = factory.newDocumentBuilder(); + Document doc = dBuilder.parse(inputStream); + + NodeList nList = doc.getElementsByTagName("command"); + for (int i = 0; i < nList.getLength(); i++) { + Element element = (Element) nList.item(i); + extensionName = getCharacterDataFromElement(element, "name"); + extensionDescription = getCharacterDataFromElement(element, "description"); + } + } catch (SAXException e) { + // TODO Auto-generated catch block + extensionName = new String(e.getMessage()); + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + extensionName = new String(e.getMessage()); + e.printStackTrace(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + extensionName = new String(e.getMessage()); + e.printStackTrace(); + } + } + + public static String getCharacterDataFromElement(Element element, String attribute) { + NodeList name = element.getElementsByTagName(attribute); + Element line = (Element) name.item(0); + + Node child = line.getFirstChild(); + if (child instanceof CharacterData) { + CharacterData cd = (CharacterData) child; + return cd.getData(); + } + return ""; + } + + /** + * Sorts the words in page 0, and shows them in page 2. + */ + void sortWords() { + + String editorText = editor.getDocumentProvider() + .getDocument(editor.getEditorInput()).get(); + + StringTokenizer tokenizer = new StringTokenizer(editorText, + " \t\n\r\f!@#\u0024%^&*()-_=+`~[]{};:'\",.<>/?|\\"); + ArrayList editorWords = new ArrayList(); + while (tokenizer.hasMoreTokens()) { + editorWords.add(tokenizer.nextToken()); + } + + Collections.sort(editorWords, Collator.getInstance()); + StringWriter displayText = new StringWriter(); + for (int i = 0; i < editorWords.size(); i++) { + displayText.write(((String) editorWords.get(i))); + displayText.write(System.getProperty("line.separator")); + } + text.setText(displayText.toString()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thermostatplugin/editors/MultiPageEditorContributor.java Thu Nov 07 12:56:08 2013 -0500 @@ -0,0 +1,103 @@ +package thermostatplugin.editors; + +import org.eclipse.jface.action.*; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.ide.IDEActionFactory; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; + +/** + * Manages the installation/deinstallation of global actions for multi-page editors. + * Responsible for the redirection of global actions to the active editor. + * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor. + */ +public class MultiPageEditorContributor extends MultiPageEditorActionBarContributor { + private IEditorPart activeEditorPart; + private Action sampleAction; + /** + * Creates a multi-page contributor. + */ + public MultiPageEditorContributor() { + super(); + createActions(); + } + /** + * Returns the action registed with the given text editor. + * @return IAction or null if editor is null. + */ + protected IAction getAction(ITextEditor editor, String actionID) { + return (editor == null ? null : editor.getAction(actionID)); + } + /* (non-JavaDoc) + * Method declared in AbstractMultiPageEditorActionBarContributor. + */ + + public void setActivePage(IEditorPart part) { + if (activeEditorPart == part) + return; + + activeEditorPart = part; + + IActionBars actionBars = getActionBars(); + if (actionBars != null) { + + ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null; + + actionBars.setGlobalActionHandler( + ActionFactory.DELETE.getId(), + getAction(editor, ITextEditorActionConstants.DELETE)); + actionBars.setGlobalActionHandler( + ActionFactory.UNDO.getId(), + getAction(editor, ITextEditorActionConstants.UNDO)); + actionBars.setGlobalActionHandler( + ActionFactory.REDO.getId(), + getAction(editor, ITextEditorActionConstants.REDO)); + actionBars.setGlobalActionHandler( + ActionFactory.CUT.getId(), + getAction(editor, ITextEditorActionConstants.CUT)); + actionBars.setGlobalActionHandler( + ActionFactory.COPY.getId(), + getAction(editor, ITextEditorActionConstants.COPY)); + actionBars.setGlobalActionHandler( + ActionFactory.PASTE.getId(), + getAction(editor, ITextEditorActionConstants.PASTE)); + actionBars.setGlobalActionHandler( + ActionFactory.SELECT_ALL.getId(), + getAction(editor, ITextEditorActionConstants.SELECT_ALL)); + actionBars.setGlobalActionHandler( + ActionFactory.FIND.getId(), + getAction(editor, ITextEditorActionConstants.FIND)); + actionBars.setGlobalActionHandler( + IDEActionFactory.BOOKMARK.getId(), + getAction(editor, IDEActionFactory.BOOKMARK.getId())); + actionBars.updateActionBars(); + } + } + private void createActions() { + sampleAction = new Action() { + public void run() { + MessageDialog.openInformation(null, "Thermostat-Plugin", "Sample Action Executed"); + } + }; + sampleAction.setText("Sample Action"); + sampleAction.setToolTipText("Sample Action tool tip"); + sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK)); + } + public void contributeToMenu(IMenuManager manager) { + IMenuManager menu = new MenuManager("Editor &Menu"); + manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu); + menu.add(sampleAction); + } + public void contributeToToolBar(IToolBarManager manager) { + manager.add(new Separator()); + manager.add(sampleAction); + } +}