diff options
author | Anithra P Janakiraman | 2010-01-29 12:05:15 +0000 |
---|---|---|
committer | Anithra P Janakiraman | 2010-01-29 12:05:15 +0000 |
commit | 3490226d8350fcb856ee8f6cb052f3258a40c673 (patch) | |
tree | 1062092f48ee204e13be527ee6efc3f77b530cff /systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension | |
parent | ffe4c798be0ca70141f64616f84a14bad3427da6 (diff) | |
download | org.eclipse.linuxtools-3490226d8350fcb856ee8f6cb052f3258a40c673.tar.gz org.eclipse.linuxtools-3490226d8350fcb856ee8f6cb052f3258a40c673.tar.xz org.eclipse.linuxtools-3490226d8350fcb856ee8f6cb052f3258a40c673.zip |
Anithra P Janakiraman - Dashboard Changes
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension')
20 files changed, 1647 insertions, 0 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/.classpath b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/.classpath new file mode 100644 index 0000000000..2035d8e135 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry exported="true" kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/.project b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/.project new file mode 100644 index 0000000000..57309d69e8 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.linuxtools.systemtap.ui.dashboardextension</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> diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/ChangeLog b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/ChangeLog new file mode 100644 index 0000000000..dcbfa6f897 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/ChangeLog @@ -0,0 +1,22 @@ +2010-01-29 Anithra P Janakiraman <anithra@linux.vnet.ibm.com> + + * .classpath: New file. + * .project: New file. + * bin: New file. + * build.properties: New file. + * icons/actions/export_wiz.gif: New file. + * icons/actions/file_obj.gif: New file. + * icons/actions/mod_obj.gif: New file. + * META-INF/MANIFEST.MF: New file. + * plugin.properties: New file. + * plugin.xml: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/AddScriptAction.java: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/CreateModuleAction.java: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/DeleteScriptAction.java: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/ExportScriptAction.java: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/ViewScriptAction.java: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/dialogs/ExportScriptDialog.java: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/dialogs/ScriptDetails.java: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/DashboardExtensionPlugin.java: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/Localization.java: New file. + * src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/localization.properties:
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/META-INF/MANIFEST.MF b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..7c002d0871 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: DashboardExtension Plug-in +Bundle-SymbolicName: org.eclipse.linuxtools.systemtap.ui.dashboardextension; singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.linuxtools.systemtap.ui.dashboardextension.internal.DashboardExtensionPlugin +Bundle-Vendor: IBM +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.linuxtools.systemtap.ui.ide, + org.eclipse.linuxtools.systemtap.ui.editor, + org.eclipse.linuxtools.systemtap.ui.graphing, + org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui, + org.eclipse.linuxtools.systemtap.ui.logging, + org.eclipse.linuxtools.systemtap.ui.systemtapgui, + org.eclipse.linuxtools.systemtap.ui.structures, + org.eclipse.linuxtools.systemtap.ui.dashboard, + org.eclipse.linuxtools.systemtap.ui.graphingapi.ui +Eclipse-AutoStart: true diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/build.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/build.properties new file mode 100644 index 0000000000..c88359b87e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + plugin.properties diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/icons/actions/export_wiz.gif b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/icons/actions/export_wiz.gif Binary files differnew file mode 100644 index 0000000000..5a0837d1e4 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/icons/actions/export_wiz.gif diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/icons/actions/file_obj.gif b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/icons/actions/file_obj.gif Binary files differnew file mode 100755 index 0000000000..7ccc6a7031 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/icons/actions/file_obj.gif diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/icons/actions/mod_obj.gif b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/icons/actions/mod_obj.gif Binary files differnew file mode 100644 index 0000000000..8bbfd04204 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/icons/actions/mod_obj.gif diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/plugin.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/plugin.properties new file mode 100644 index 0000000000..bdc6f14513 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/plugin.properties @@ -0,0 +1,18 @@ +command.exportScript.name=&Export Script... +command.exportScript.desc=Export Script to the Dashboard + +actionset.export.name=Export Action Set +action.exportScript.name=&Export Script... +action.exportScript.desc=Export Script to the Dashboard + +command.createModule.name=&Create Module... +command.createModule.desc=Create new Dashboard Module + +actionset.createModule.name=Create Module Action Set +action.createModule.name=&Create Module... +action.createModule.desc=Create new Dashboard Module + + +action.viewScript.name=View Script +action.addScript.name=Add Script +action.deleteScript.name=Delete Script
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/plugin.xml b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/plugin.xml new file mode 100644 index 0000000000..b7d8e6739e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/plugin.xml @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> +<plugin> + <extension + point="org.eclipse.ui.startup"> + <!--startup class=""--> + </extension> + + <extension + point="org.eclipse.ui.commands"> + <command + name="%command.exportScript.name" + description="%command.exportScript.desc" + categoryId="org.eclipse.linuxtools.systemtap.ui.ide.category.file" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.commands.ExportScript"/> + <command + name="%command.createModule.name" + description="%command.createModule.desc" + categoryId="org.eclipse.linuxtools.systemtap.ui.dashboard.category.file" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.commands.CreateModuleAction"/> + </extension> + <extension + point="org.eclipse.ui.bindings"> + <key + commandId="org.eclipse.linuxtools.systemtap.ui.dashboardextension.commands.ExportScript" + contextId="org.eclipse.ui.contexts.window" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" + sequence="M1+X"/> + <key + commandId="org.eclipse.linuxtools.systemtap.ui.dashboardextension.commands.CreateModuleAction" + contextId="org.eclipse.ui.contexts.window" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" + sequence="M1+Y"/> + </extension> + <extension + point="org.eclipse.ui.actionSets"> + <actionSet + label="%actionset.export.name" + visible="true" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.ExportScriptActionSet"> + <action + label="%action.exportScript.name" + tooltip="%action.exportScript.desc" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions.ExportScript" + icon="icons/actions/export_wiz.gif" + toolbarPath="org.eclipse.ui.workbench.file/export.ext" + menubarPath="file2/export.ext" + class="org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions.ExportScriptAction" + definitionId="org.eclipse.linuxtools.systemtap.ui.dashboardextension.commands.ExportScript" + style="push" + state="false"/> + </actionSet> + </extension> + <extension + point="org.eclipse.ui.actionSets"> + <actionSet + label="%actionset.createModule.name" + visible="true" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.CreateModuleActionSet"> + <action + label="%action.createModule.name" + tooltip="%action.createModule.desc" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions.CreateModuleAction" + icon="icons/actions/mod_obj.gif" + toolbarPath="org.eclipse.ui.workbench.file/export.ext" + menubarPath="file2/export.ext" + class="org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions.CreateModuleAction" + definitionId="org.eclipse.linuxtools.systemtap.ui.dashboardextension.commands.CreateModuleAction" + style="push" + state="true"/> + </actionSet> + </extension> + + + <extension + point="org.eclipse.ui.popupMenus"> + <objectContribution + adaptable="false" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.ViewScriptMenu" + objectClass="org.eclipse.linuxtools.systemtap.ui.dashboard.structures.ModuleTreeNode"> + <action + label="%action.viewScript.name" + class="org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions.ViewScriptAction" + icon="icons/actions/file_obj.gif" + menubarPath="file.ext" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.ViewScriptAction" + style="push"/> + <!--<action + class="org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions.AddScriptAction" + icon="icons/actions/file_obj.gif" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.AddScriptAction" + label="%action.addScript.name" + menubarPath="file.ext" + style="push"> + </action>--> + ,<!--<action + class="org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions.DeleteScriptAction" + icon="icons/actions/file_obj.gif" + id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.DeleteScriptAction" + label="%action.deleteScript.name" + menubarPath="file.ext" + style="push"> + </action>--> + </objectContribution> + </extension> + + <extension + point="org.eclipse.ui.perspectiveExtensions"> + <perspectiveExtension + targetID="org.eclipse.linuxtools.systemtap.ui.ide.IDEPerspective"> + <actionSet id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.ExportScriptActionSet"/> + </perspectiveExtension> + <perspectiveExtension + targetID="org.eclipse.linuxtools.systemtap.ui.dashboard.DashboardPerspective"> + <actionSet id="org.eclipse.linuxtools.systemtap.ui.dashboardextension.CreateModuleActionSet"/> + </perspectiveExtension> + </extension> +</plugin> diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/AddScriptAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/AddScriptAction.java new file mode 100644 index 0000000000..a71f04126e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/AddScriptAction.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions; + +import java.io.FileInputStream; +import java.io.IOException; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.WorkbenchException; + +import org.eclipse.linuxtools.systemtap.ui.editor.SimpleEditor; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardModule; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.ModuleTreeNode; +import org.eclipse.linuxtools.systemtap.ui.ide.IDEPerspective; +import org.eclipse.linuxtools.systemtap.ui.ide.actions.TempFileAction; + +/** + * A class that handles extracting the original script from the dashboard module. + * It will then create a new active editor in the IDE perspective and display the + * module in a temp file. Users can then modify this script and use the modified + * version as well as the original. + * @author Ryan Morse + */ +public class AddScriptAction extends Action implements IViewActionDelegate { + /** + * This method sets what item the user has selected to view. + */ + public void init(IViewPart view) { + selectedItem = null; + } + + /** + * This method will retreive the script from the selected module for the user + * to see. It will then create a new active editor in the IDE perspective and + * display the module in a temp file. Users can then modify this script and + * use the modified version as well as the original. + * @param act An action representing the click event used to start this method. + */ + public void run(IAction act) { + DashboardModule data = (DashboardModule)selectedItem.getData(); + + try { + IWorkbenchPage p = PlatformUI.getWorkbench().showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + + TempFileAction tfa = new TempFileAction(); + tfa.run(); + + IEditorPart edit = p.getActiveEditor(); + + if(null != edit) { + if(edit instanceof SimpleEditor) { + SimpleEditor editor = (SimpleEditor)edit; + + //Copy the file just to ensure the user has to save their own copy if they want it + FileInputStream fin; + try { + fin = new FileInputStream(data.script); + StringBuilder sb = new StringBuilder(); + + int c; + while((c = fin.read()) != -1) + sb.append((char)c); + + fin.close(); + editor.insertText(sb.toString()); + } catch (IOException e) {} + } + } + } catch(WorkbenchException we) {} + } + + /** + * This method will update the selected item when a new item is selected. + * @param action The action that fired this method. + * @param selection The newly selected item. + */ + public void selectionChanged(IAction action, ISelection selection) { + if(selection instanceof IStructuredSelection) { + IStructuredSelection selected = (IStructuredSelection)selection; + Object o = selected.getFirstElement(); + if(o instanceof ModuleTreeNode) { + selectedItem = (ModuleTreeNode)o; + o = selectedItem.getData(); + if(null != o) { + setEnabled(true); + return; + } + } + } + setEnabled(false); + } + + private ModuleTreeNode selectedItem; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/CreateModuleAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/CreateModuleAction.java new file mode 100644 index 0000000000..7497e58351 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/CreateModuleAction.java @@ -0,0 +1,273 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; + + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.XMLMemento; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSetParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.IDataSetFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.dataset.DataSetWizard; +import org.eclipse.linuxtools.systemtap.ui.structures.TreeNode; +import org.eclipse.linuxtools.systemtap.ui.structures.ZipArchive; +import org.eclipse.linuxtools.systemtap.ui.dashboard.DashboardPerspective; +import org.eclipse.linuxtools.systemtap.ui.dashboard.internal.DashboardPlugin; +import org.eclipse.linuxtools.systemtap.ui.dashboard.preferences.DashboardPreferenceConstants; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardMetaData; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardModule; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardModuleFileFilter; +import org.eclipse.linuxtools.systemtap.ui.dashboard.views.DashboardModuleBrowserView; +import org.eclipse.linuxtools.systemtap.ui.dashboardextension.dialogs.ExportScriptDialog; +import org.eclipse.linuxtools.systemtap.ui.dashboardextension.dialogs.ScriptDetails; +import org.eclipse.linuxtools.systemtap.ui.graphing.GraphingConstants; +import org.eclipse.linuxtools.systemtap.ui.systemtapgui.SystemTapGUISettings; + +/** + * This class brings up a dialog box for the user to select what they want the + * new module to contain. If a new module is build, it will be exported to the + * dashboard for use at any time. + * @author Ryan Morse + */ +public class CreateModuleAction extends Action implements IWorkbenchWindowActionDelegate { + /** + * This method will bring up the export script dialog window for the user + * to select what they want to new module to contain. If the user enters + * module information and clicks ok the module will be built and added to + * the dashboard. + */ + + //private static String scriptFileName = "/script.stp"; + public String script = null; + + public void init(IWorkbenchWindow window) { + fWindow= window; + } + + protected IWorkbenchWindow fWindow = null; + + public void run(IAction action) { + // if(null == script || script.length() <= 0) { + // String msg = MessageFormat.format(Localization.getString("ExportScriptAction.NoFileToExport"), null); + // MessageDialog.openWarning(fWindow.getShell(), Localization.getString("ExportScriptAction.Error"), msg); + // } else { + ScriptDetails sd = new ScriptDetails(fWindow.getShell()); + sd.open(); + if (sd.isCanceled()) return; + + script = DashboardPlugin.getDefault().getPreferenceStore().getString(DashboardPreferenceConstants.P_DASHBOARD_SCRIPT); + DataSetWizard wizard = new DataSetWizard(GraphingConstants.DataSetMetaData, script); + IWorkbench workbench = PlatformUI.getWorkbench(); + wizard.init(workbench, null); + WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard); + dialog.create(); + dialog.open(); + + IDataSetParser parser = wizard.getParser(); + IDataSet dataSet = wizard.getDataSet(); + + wizard.dispose(); + + if(null == parser || null == dataSet) + return; + + ExportScriptDialog exportDialog = new ExportScriptDialog(fWindow.getShell(), dataSet); + exportDialog.open(); + + exportDialog.dispose(); + if(!exportDialog.isCanceled()) { + String category = exportDialog.getCategory(); + String display = exportDialog.getDisplay(); + String description = exportDialog.getDescription(); + GraphData[] gd = exportDialog.getGraphs(); + TreeNode filters = exportDialog.getGraphFilters(); + + validateDirectory(); + File meta = saveMetaData(display, category, description, dataSet, parser, gd, filters,DashboardPlugin.getDefault().getPreferenceStore().getString(DashboardPreferenceConstants.P_DASHBOARD_EXAMPLES_DIR)); + String archiveName = getSaveDirectory() + "/" + category.replace(' ', '_') + "." + display.replace(' ', '_'); + buildArchive(archiveName, new File(script), meta); + cleanupFiles(new String[] {archiveName, meta.getAbsolutePath()}); + updateDashboard(); + // } + } + } + + /** + * This method will check to make sure the exported module directory is valid. + * If it isn't then the foleders will be created in order to make the directory + * valid. + */ + private void validateDirectory() { + File folder = new File(getSaveDirectory()); + + if(!folder.exists()) + folder.mkdir(); + } + + /** + * This method will create a new XML Memento used to store all of the meta data + * for the module. This data is all based on what the user selected from the + * dialog box. + * @param disp The string to display that represents this module. + * @param cat The category string representing where this module will be placed + * @param desc The description string for this module + * @param dataSet The IDataSet that holds the data for this module + * @param parser The parer that can obtain the information from the raw output + * @param gd GraphData Array specifying all of the information needed to create the selected graphs + * @param filters TreeNode containing all of the selected filters for each graph. + */ + private File saveMetaData(String disp, String cat, String desc, IDataSet dataSet, IDataSetParser parser, GraphData[] gd, TreeNode filters, String location) { + File meta = null; + XMLMemento data = XMLMemento.createWriteRoot(DashboardMetaData.XMLDashboardItem); + + try { + IMemento child, child2, child3; + + data.putString(DashboardMetaData.XMLdDisplay, disp); + data.putString(DashboardMetaData.XMLdCategory, cat); + data.putString(DashboardMetaData.XMLdDescription, desc); + data.putString(DashboardMetaData.XMLdDataset, dataSet.getID()); + data.putString(DashboardMetaData.XMLdScript, script); + data.putString(DashboardMetaData.XMLdLocation, location); + data.putString(DashboardMetaData.XMLdScriptFileName, script); + + + child = data.createChild(DashboardMetaData.XMLParsingExpressions); + String[] cols = dataSet.getTitles(); + for(int i=0; i<cols.length; i++) { + child2 = child.createChild(DashboardMetaData.XMLpColumn); + child2.putString(DashboardMetaData.XMLpName, cols[i]); + } + parser.saveXML(child.createChild(DashboardMetaData.XMLpParser)); + + child = data.createChild(DashboardMetaData.XMLGraphDisplays); + for(int j,i=0; i<gd.length; i++) { + child2 = child.createChild(DashboardMetaData.XMLgGraph); + child2.putString(DashboardMetaData.XMLgId, gd[i].graphID); + child2.putString(DashboardMetaData.XMLgTitle, gd[i].title); + + TreeNode treeChild = filters.getChildAt(i); + for(j=0; j<treeChild.getChildCount(); j++) { + ((IDataSetFilter)(treeChild.getChildAt(j).getData())).writeXML(child2); + } + + child3 = child2.createChild(DashboardMetaData.XMLgSeries); + child3.putString(DashboardMetaData.XMLgAxis, DashboardMetaData.XMLgAxisX); + child3.putInteger(DashboardMetaData.XMLgColumn, gd[i].xSeries); + for(j=0; j<gd[i].ySeries.length; j++) { + child3 = child2.createChild(DashboardMetaData.XMLgSeries); + child3.putString(DashboardMetaData.XMLgAxis, DashboardMetaData.XMLgAxisY); + child3.putInteger(DashboardMetaData.XMLgColumn, gd[i].ySeries[j]); + } + } + + meta = new File(getSaveDirectory() + DashboardModule.metaFileName); + FileWriter writer = new FileWriter(meta); + data.save(writer); + writer.close(); + } catch(FileNotFoundException fnfe) { + return meta; + } catch(Exception e) { + return meta; + } + return meta; + } + + /** + * This method will create the module archive by first zipping the .stp file and the meta data + * together. Then it will compress the .zip file into a .gz file. The .gz file's extension is + * set to .dash to discurage users from trying to modify it and to make it sepecific to the + * SystemTapGUI dashboard. + * @param archiveName The name to use for the file containing the new module data. + * @param script The file representing the .stp script file to use for the module + * @param meta The XML Memento file representing the module details. + */ + private void buildArchive(String archiveName, File script, File meta) { + String[] files = new String[] {meta.getAbsolutePath()}; + String[] names = new String[] {DashboardModule.metaFileName}; + + ZipArchive.zipFiles(archiveName, files, names); + ZipArchive.compressFile(archiveName + DashboardModuleFileFilter.DashboardModuleExtension, archiveName); + } + + /** + * This method will delete any extra files that were generated as a result of building + * the Dashboard module. + * @param files A list of all of the file paths that should be removed + */ + private void cleanupFiles(String[] files) { + if(null == files) + return; + + File f; + for(int i=0; i<files.length; i++) { + f = new File(files[i]); + if(f.exists()) + f.delete(); + } + } + + /** + * This method will get the directory name that should be used for saving the dashboard modules. + */ + private String getSaveDirectory() { + return SystemTapGUISettings.settingsFolder + "/dashboard"; + } + + /** + * This method forces the Dashboard's DashboardModuleBrowserView to refresh itself to ensure + * that is contains the most up-to-date module list. + */ + private void updateDashboard() { + try { + IWorkbenchPage p = PlatformUI.getWorkbench().showPerspective(DashboardPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + IViewPart ivp = p.findView(DashboardModuleBrowserView.ID); + ((DashboardModuleBrowserView)ivp).refresh(); + + //p = PlatformUI.getWorkbench().showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + } catch(WorkbenchException we) {} + } + + /** + * Removes all internal references to objects. No other method should be called after this. + */ + /*public void dispose() { + super.dispose(); + }*/ + + public void selectionChanged(IAction action, ISelection selection) { + // TODO Auto-generated method stub + + } + + public void dispose() { + // TODO Auto-generated method stub + + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/DeleteScriptAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/DeleteScriptAction.java new file mode 100644 index 0000000000..bb49c8fff2 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/DeleteScriptAction.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions; + +import java.io.FileInputStream; +import java.io.IOException; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.WorkbenchException; + +import org.eclipse.linuxtools.systemtap.ui.editor.SimpleEditor; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardModule; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.ModuleTreeNode; +import org.eclipse.linuxtools.systemtap.ui.ide.IDEPerspective; +import org.eclipse.linuxtools.systemtap.ui.ide.actions.TempFileAction; + +/** + * A class that handles extracting the original script from the dashboard module. + * It will then create a new active editor in the IDE perspective and display the + * module in a temp file. Users can then modify this script and use the modified + * version as well as the original. + * @author Ryan Morse + */ +public class DeleteScriptAction extends Action implements IViewActionDelegate { + /** + * This method sets what item the user has selected to view. + */ + public void init(IViewPart view) { + selectedItem = null; + } + + /** + * This method will retreive the script from the selected module for the user + * to see. It will then create a new active editor in the IDE perspective and + * display the module in a temp file. Users can then modify this script and + * use the modified version as well as the original. + * @param act An action representing the click event used to start this method. + */ + public void run(IAction act) { + DashboardModule data = (DashboardModule)selectedItem.getData(); + + try { + IWorkbenchPage p = PlatformUI.getWorkbench().showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + + TempFileAction tfa = new TempFileAction(); + tfa.run(); + + IEditorPart edit = p.getActiveEditor(); + + if(null != edit) { + if(edit instanceof SimpleEditor) { + SimpleEditor editor = (SimpleEditor)edit; + + //Copy the file just to ensure the user has to save their own copy if they want it + FileInputStream fin; + try { + fin = new FileInputStream(data.script); + StringBuilder sb = new StringBuilder(); + + int c; + while((c = fin.read()) != -1) + sb.append((char)c); + + fin.close(); + editor.insertText(sb.toString()); + } catch (IOException e) {} + } + } + } catch(WorkbenchException we) {} + } + + /** + * This method will update the selected item when a new item is selected. + * @param action The action that fired this method. + * @param selection The newly selected item. + */ + public void selectionChanged(IAction action, ISelection selection) { + if(selection instanceof IStructuredSelection) { + IStructuredSelection selected = (IStructuredSelection)selection; + Object o = selected.getFirstElement(); + if(o instanceof ModuleTreeNode) { + selectedItem = (ModuleTreeNode)o; + o = selectedItem.getData(); + if(null != o) { + setEnabled(true); + return; + } + } + } + setEnabled(false); + } + + private ModuleTreeNode selectedItem; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/ExportScriptAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/ExportScriptAction.java new file mode 100644 index 0000000000..5e0baba00f --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/ExportScriptAction.java @@ -0,0 +1,250 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.text.MessageFormat; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.XMLMemento; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSetParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.IDataSetFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.dataset.DataSetWizard; +import org.eclipse.linuxtools.systemtap.ui.structures.TreeNode; +import org.eclipse.linuxtools.systemtap.ui.structures.ZipArchive; +import org.eclipse.linuxtools.systemtap.ui.dashboard.DashboardPerspective; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardMetaData; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardModule; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardModuleFileFilter; +import org.eclipse.linuxtools.systemtap.ui.dashboard.views.DashboardModuleBrowserView; +import org.eclipse.linuxtools.systemtap.ui.dashboardextension.dialogs.ExportScriptDialog; +import org.eclipse.linuxtools.systemtap.ui.dashboardextension.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.graphing.GraphingConstants; +import org.eclipse.linuxtools.systemtap.ui.ide.IDEPerspective; +import org.eclipse.linuxtools.systemtap.ui.ide.actions.RunScriptAction; +import org.eclipse.linuxtools.systemtap.ui.systemtapgui.SystemTapGUISettings; + +/** + * This class brings up a dialog box for the user to select what they want the + * new module to contain. If a new module is build, it will be exported to the + * dashboard for use at any time. + * @author Ryan Morse + */ +public class ExportScriptAction extends RunScriptAction implements IWorkbenchWindowActionDelegate { + /** + * This method will bring up the export script dialog window for the user + * to select what they want to new module to contain. If the user enters + * module information and clicks ok the module will be built and added to + * the dashboard. + */ + + private static String scriptFileName = "/script.stp"; + + public void run(IAction action) { + String script = getFilePath(); + if(null == script || script.length() <= 0) { + String msg = MessageFormat.format(Localization.getString("ExportScriptAction.NoFileToExport"), null); + MessageDialog.openWarning(fWindow.getShell(), Localization.getString("ExportScriptAction.Error"), msg); + } else { + DataSetWizard wizard = new DataSetWizard(GraphingConstants.DataSetMetaData, script); + IWorkbench workbench = PlatformUI.getWorkbench(); + wizard.init(workbench, null); + WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard); + dialog.create(); + dialog.open(); + + IDataSetParser parser = wizard.getParser(); + IDataSet dataSet = wizard.getDataSet(); + + wizard.dispose(); + + if(null == parser || null == dataSet) + return; + + ExportScriptDialog exportDialog = new ExportScriptDialog(fWindow.getShell(), dataSet); + exportDialog.open(); + + exportDialog.dispose(); + if(!exportDialog.isCanceled()) { + String category = exportDialog.getCategory(); + String display = exportDialog.getDisplay(); + String description = exportDialog.getDescription(); + GraphData[] gd = exportDialog.getGraphs(); + TreeNode filters = exportDialog.getGraphFilters(); + + validateDirectory(); + File meta = saveMetaData(display, category, description, dataSet, parser, gd, filters,"local"); + String archiveName = getSaveDirectory() + "/" + category.replace(' ', '_') + "." + display.replace(' ', '_'); + buildArchive(archiveName, new File(script), meta); + cleanupFiles(new String[] {archiveName, meta.getAbsolutePath()}); + updateDashboard(); + } + } + } + + /** + * This method will check to make sure the exported module directory is valid. + * If it isn't then the foleders will be created in order to make the directory + * valid. + */ + private void validateDirectory() { + File folder = new File(getSaveDirectory()); + + if(!folder.exists()) + folder.mkdir(); + } + + /** + * This method will create a new XML Memento used to store all of the meta data + * for the module. This data is all based on what the user selected from the + * dialog box. + * @param disp The string to display that represents this module. + * @param cat The category string representing where this module will be placed + * @param desc The description string for this module + * @param dataSet The IDataSet that holds the data for this module + * @param parser The parer that can obtain the information from the raw output + * @param gd GraphData Array specifying all of the information needed to create the selected graphs + * @param filters TreeNode containing all of the selected filters for each graph. + */ + private File saveMetaData(String disp, String cat, String desc, IDataSet dataSet, IDataSetParser parser, GraphData[] gd, TreeNode filters, String location) { + File meta = null; + XMLMemento data = XMLMemento.createWriteRoot(DashboardMetaData.XMLDashboardItem); + + try { + IMemento child, child2, child3; + + data.putString(DashboardMetaData.XMLdDisplay, disp); + data.putString(DashboardMetaData.XMLdCategory, cat); + data.putString(DashboardMetaData.XMLdDescription, desc); + data.putString(DashboardMetaData.XMLdDataset, dataSet.getID()); + data.putString(DashboardMetaData.XMLdScript, scriptFileName); + data.putString(DashboardMetaData.XMLdLocation, location); + data.putString(DashboardMetaData.XMLdScriptFileName, scriptFileName); + + + child = data.createChild(DashboardMetaData.XMLParsingExpressions); + String[] cols = dataSet.getTitles(); + for(int i=0; i<cols.length; i++) { + child2 = child.createChild(DashboardMetaData.XMLpColumn); + child2.putString(DashboardMetaData.XMLpName, cols[i]); + } + parser.saveXML(child.createChild(DashboardMetaData.XMLpParser)); + + child = data.createChild(DashboardMetaData.XMLGraphDisplays); + for(int j,i=0; i<gd.length; i++) { + child2 = child.createChild(DashboardMetaData.XMLgGraph); + child2.putString(DashboardMetaData.XMLgId, gd[i].graphID); + child2.putString(DashboardMetaData.XMLgTitle, gd[i].title); + + TreeNode treeChild = filters.getChildAt(i); + for(j=0; j<treeChild.getChildCount(); j++) { + ((IDataSetFilter)(treeChild.getChildAt(j).getData())).writeXML(child2); + } + + child3 = child2.createChild(DashboardMetaData.XMLgSeries); + child3.putString(DashboardMetaData.XMLgAxis, DashboardMetaData.XMLgAxisX); + child3.putInteger(DashboardMetaData.XMLgColumn, gd[i].xSeries); + for(j=0; j<gd[i].ySeries.length; j++) { + child3 = child2.createChild(DashboardMetaData.XMLgSeries); + child3.putString(DashboardMetaData.XMLgAxis, DashboardMetaData.XMLgAxisY); + child3.putInteger(DashboardMetaData.XMLgColumn, gd[i].ySeries[j]); + } + } + + meta = new File(getSaveDirectory() + DashboardModule.metaFileName); + FileWriter writer = new FileWriter(meta); + data.save(writer); + writer.close(); + } catch(FileNotFoundException fnfe) { + return meta; + } catch(Exception e) { + return meta; + } + return meta; + } + + /** + * This method will create the module archive by first zipping the .stp file and the meta data + * together. Then it will compress the .zip file into a .gz file. The .gz file's extension is + * set to .dash to discurage users from trying to modify it and to make it sepecific to the + * SystemTapGUI dashboard. + * @param archiveName The name to use for the file containing the new module data. + * @param script The file representing the .stp script file to use for the module + * @param meta The XML Memento file representing the module details. + */ + private void buildArchive(String archiveName, File script, File meta) { + String[] files = new String[] {script.getAbsolutePath(), meta.getAbsolutePath()}; + String[] names = new String[] {scriptFileName, DashboardModule.metaFileName}; + + ZipArchive.zipFiles(archiveName, files, names); + ZipArchive.compressFile(archiveName + DashboardModuleFileFilter.DashboardModuleExtension, archiveName); + } + + /** + * This method will delete any extra files that were generated as a result of building + * the Dashboard module. + * @param files A list of all of the file paths that should be removed + */ + private void cleanupFiles(String[] files) { + if(null == files) + return; + + File f; + for(int i=0; i<files.length; i++) { + f = new File(files[i]); + if(f.exists()) + f.delete(); + } + } + + /** + * This method will get the directory name that should be used for saving the dashboard modules. + */ + private String getSaveDirectory() { + return SystemTapGUISettings.settingsFolder + "/dashboard"; + } + + /** + * This method forces the Dashboard's DashboardModuleBrowserView to refresh itself to ensure + * that is contains the most up-to-date module list. + */ + private void updateDashboard() { + try { + IWorkbenchPage p = PlatformUI.getWorkbench().showPerspective(DashboardPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + IViewPart ivp = p.findView(DashboardModuleBrowserView.ID); + ((DashboardModuleBrowserView)ivp).refresh(); + + p = PlatformUI.getWorkbench().showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + } catch(WorkbenchException we) {} + } + + /** + * Removes all internal references to objects. No other method should be called after this. + */ + public void dispose() { + super.dispose(); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/ViewScriptAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/ViewScriptAction.java new file mode 100644 index 0000000000..14550bdfc8 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/actions/ViewScriptAction.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.dashboardextension.actions; + +import java.io.FileInputStream; +import java.io.IOException; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.WorkbenchException; + +import org.eclipse.linuxtools.systemtap.ui.editor.SimpleEditor; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardModule; +import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.ModuleTreeNode; +import org.eclipse.linuxtools.systemtap.ui.ide.IDEPerspective; +import org.eclipse.linuxtools.systemtap.ui.ide.actions.TempFileAction; + +/** + * A class that handles extracting the original script from the dashboard module. + * It will then create a new active editor in the IDE perspective and display the + * module in a temp file. Users can then modify this script and use the modified + * version as well as the original. + * @author Ryan Morse + */ +public class ViewScriptAction extends Action implements IViewActionDelegate { + /** + * This method sets what item the user has selected to view. + */ + public void init(IViewPart view) { + selectedItem = null; + } + + /** + * This method will retreive the script from the selected module for the user + * to see. It will then create a new active editor in the IDE perspective and + * display the module in a temp file. Users can then modify this script and + * use the modified version as well as the original. + * @param act An action representing the click event used to start this method. + */ + public void run(IAction act) { + DashboardModule data = (DashboardModule)selectedItem.getData(); + + try { + IWorkbenchPage p = PlatformUI.getWorkbench().showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + + TempFileAction tfa = new TempFileAction(); + tfa.run(); + + IEditorPart edit = p.getActiveEditor(); + + if(null != edit) { + if(edit instanceof SimpleEditor) { + SimpleEditor editor = (SimpleEditor)edit; + + //Copy the file just to ensure the user has to save their own copy if they want it + FileInputStream fin; + try { + fin = new FileInputStream(data.script); + StringBuilder sb = new StringBuilder(); + + int c; + while((c = fin.read()) != -1) + sb.append((char)c); + + fin.close(); + editor.insertText(sb.toString()); + } catch (IOException e) {} + } + } + } catch(WorkbenchException we) {} + } + + /** + * This method will update the selected item when a new item is selected. + * @param action The action that fired this method. + * @param selection The newly selected item. + */ + public void selectionChanged(IAction action, ISelection selection) { + if(selection instanceof IStructuredSelection) { + IStructuredSelection selected = (IStructuredSelection)selection; + Object o = selected.getFirstElement(); + if(o instanceof ModuleTreeNode) { + selectedItem = (ModuleTreeNode)o; + o = selectedItem.getData(); + if(null != o) { + setEnabled(true); + return; + } + } + } + setEnabled(false); + } + + private ModuleTreeNode selectedItem; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/dialogs/ExportScriptDialog.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/dialogs/ExportScriptDialog.java new file mode 100644 index 0000000000..1974699567 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/dialogs/ExportScriptDialog.java @@ -0,0 +1,339 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.dashboardextension.dialogs; + +import java.text.MessageFormat; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.IDataSetFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.filter.AvailableFilterTypes; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.filter.SelectFilterWizard; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.graph.GraphFactory; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.graph.SelectGraphWizard; +import org.eclipse.linuxtools.systemtap.ui.structures.TreeNode; +import org.eclipse.linuxtools.systemtap.ui.dashboardextension.internal.Localization; + +/** + * This class handles creating a dialog that the user is able to select + * features that they want to be part of their new dashboard module. + * Once the user is done configuring the module, it will create the new + * module for the dashboard from the active script in the editor. + * @author Ryan Morse + */ +public class ExportScriptDialog extends Dialog { + public ExportScriptDialog(Shell parentShell, IDataSet data) { + super(parentShell); + this.data = data; + canceled = false; + } + + /** + * This method will setup the size of the dialog window and set its title. + * @param shell The shell that will contain this dialog box + */ + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(Localization.getString("ExportScriptDialog.ExportScript")); + shell.setSize(330, 375); + } + + /** + * This method adds all of the components to the dialog and positions them. + * Actions are added to all of the buttons to deal with user interaction. + * @param parent The Composite that will contain all components created in this method + * @return The main Control created by this method. + */ + protected Control createDialogArea(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + + //Dialog reference labels + Label lblDisplay = new Label(comp, SWT.NONE); + lblDisplay.setText(Localization.getString("ExportScriptDialog.Display")); + lblDisplay.setBounds(10, 12, 100, 25); + Label lblCategory = new Label(comp, SWT.NONE); + lblCategory.setText(Localization.getString("ExportScriptDialog.Category")); + lblCategory.setBounds(10, 42, 100, 25); + Label lblDescription = new Label(comp, SWT.NONE); + lblDescription.setText(Localization.getString("ExportScriptDialog.Description")); + lblDescription.setBounds(10, 72, 100, 25); + Label lblGraphs = new Label(comp, SWT.NONE); + lblGraphs.setText(Localization.getString("ExportScriptDialog.Graphs")); + lblGraphs.setBounds(10, 150, 100, 25); + + //Text boxes for how to display the new module in the dashboard + txtDisplay = new Text(comp, SWT.BORDER); + txtDisplay.setBounds(120, 10, 200, 25); + txtCategory = new Text(comp, SWT.BORDER); + txtCategory.setBounds(120, 40, 200, 25); + txtDescription = new Text(comp, SWT.MULTI | SWT.WRAP | SWT.BORDER); + txtDescription.setBounds(120, 70, 200, 75); + + treeGraphs = new Tree(comp, SWT.SINGLE | SWT.BORDER); + treeGraphs.setBounds(10, 175, 200, 125); + + //Button to add another graph + btnAdd = new Button(comp, SWT.PUSH); + btnAdd.setText(Localization.getString("ExportScriptDialog.Add")); + btnAdd.setBounds(220, 175, 100, 26); + + //Button to filter the script output data + btnAddFilter = new Button(comp, SWT.PUSH); + btnAddFilter.setText(Localization.getString("ExportScriptDialog.AddFilter")); + btnAddFilter.setBounds(220, 205, 100, 26); + btnAddFilter.setEnabled(false); + + //Button to remove the selected graph/filter + btnRemove = new Button(comp, SWT.PUSH); + btnRemove.setText(Localization.getString("ExportScriptDialog.Remove")); + btnRemove.setBounds(220, 265, 100, 26); + btnRemove.setEnabled(false); + + //Action to notify the buttons when to enable/disable themselves based on list selection + treeGraphs.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + selectedTreeItem = (TreeItem)e.item; + if(null == selectedTreeItem.getParentItem()) + btnAddFilter.setEnabled(true); + else + btnAddFilter.setEnabled(false); + btnRemove.setEnabled(true); + } + + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + //Brings up a new dialog box when user clicks the add button. Allows selecting a new graph to display. + btnAdd.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + SelectGraphWizard wizard = new SelectGraphWizard(data); + IWorkbench workbench = PlatformUI.getWorkbench(); + wizard.init(workbench, null); + WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard); + dialog.create(); + dialog.open(); + + GraphData gd = wizard.getGraphData(); + if(null != gd) { + TreeItem item = new TreeItem(treeGraphs, SWT.NONE); + item.setText(GraphFactory.getGraphName(gd.graphID) + ":" + gd.title); + item.setData(gd); + } + } + + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + //Brings up a new dialog for selecting filter options when the user clicks the filter button. + btnAddFilter.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + SelectFilterWizard wizard = new SelectFilterWizard(data.getTitles()); + IWorkbench workbench = PlatformUI.getWorkbench(); + wizard.init(workbench, null); + WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard); + dialog.create(); + dialog.open(); + + IDataSetFilter f = wizard.getFilter(); + if(null != f) { + TreeItem item = new TreeItem(treeGraphs.getSelection()[0], SWT.NONE); + item.setText(AvailableFilterTypes.getFilterName(f.getID())); + item.setData(f); + } + } + + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + //Removes the selected graph/filter from the tree + btnRemove.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + selectedTreeItem.dispose(); + btnRemove.setEnabled(false); + } + + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + return comp; + } + + /** + * This method haddles what to do when the user clicks the ok or cancel button. + * If canceled it will just close without doing anything. If the user clicked ok + * and the data entered is valid it will set up variables that can be accessed + * later to build the actual module. This method should not be called explicitly. + * @param buttonID A reference to the button that was pressed. 0 - ID, 1- for others + */ + protected void buttonPressed(int buttonID) { + if(0 == buttonID) { //OK + if(txtDisplay.getText().length() <= 0 || + txtCategory.getText().length() <= 0 || + txtDescription.getText().length() <= 0 || + treeGraphs.getItemCount() <= 0) { + String msg = MessageFormat.format(Localization.getString("ExportScriptDialog.FillFields"), null); + MessageDialog.openWarning(this.getShell(), Localization.getString("ExportScriptDialog.Error"), msg); + return; + } + + display = txtDisplay.getText(); + category = txtCategory.getText(); + description = txtDescription.getText(); + buildGraphData(); + buildFilterData(); + } else { + canceled = true; + } + + super.buttonPressed(buttonID); + } + + /** + * This allows outside classes to determine if the user clicked ok or cancel. + * @return boolean representing whether the cancel button was pressed or not + */ + public boolean isCanceled() { + return canceled; + } + + /** + * This allows an outside class to determin what was chosen to be the Category. + * @return String representing the selected Category name. + */ + public String getCategory() { + return category; + } + + /** + * This allows an outside class to determin what was chosen to be the Description. + * @return String representing the selected Description. + */ + public String getDescription() { + return description; + } + + /** + * This allows an outside class to determin what was chosen to be the Display name. + * @return String representing the selected Display name. + */ + public String getDisplay() { + return display; + } + + /** + * This allows an outside class to determin what graph types were selected. + * @return GraphData[] for each selected graph. + */ + public GraphData[] getGraphs() { + return graphData; + } + + /** + * This allows an outside class to determin what filter types were chosen. + * @return TreeNode organized as follows: Root->Graphs->Filters. + */ + public TreeNode getGraphFilters() { + return filters; + } + + /** + * This cleans up all internal references to objects. No other method should + * be called after the dispose method. + */ + public void dispose() { + if(null != txtDisplay) + txtDisplay.dispose(); + if(null != txtCategory) + txtCategory.dispose(); + if(null != txtDescription) + txtDescription.dispose(); + if(null != treeGraphs) + treeGraphs.dispose(); + if(null != btnAdd) + btnAdd.dispose(); + if(null != btnRemove) + btnRemove.dispose(); + if(null != btnAddFilter) + btnAddFilter.dispose(); + if(null != selectedTreeItem) + selectedTreeItem.dispose(); + txtDisplay = null; + txtCategory = null; + txtDescription = null; + treeGraphs = null; + btnAdd = null; + btnRemove = null; + btnAddFilter = null; + selectedTreeItem = null; + data = null; + } + + /** + * This method converts what was selected in the tree into a simple array + * of all of the selected graphs and their data. + */ + private void buildGraphData() { + TreeItem[] children = treeGraphs.getItems(); + graphData = new GraphData[children.length]; + for(int i=0; i<graphData.length; i++) + graphData[i] = (GraphData)children[i].getData(); + } + + /** + * This mothod takes the data from the tree and builds another tree that + * has all the information about the graph and Filters in an easily + * accessable structure. + */ + private void buildFilterData() { + TreeItem[] items = treeGraphs.getItems(); + TreeItem[] filterItems; + + filters = new TreeNode("", false); //$NON-NLS-1$ + TreeNode graphLevel; + for(int i=0; i<items.length; i++) { + filterItems = items[i].getItems(); + + graphLevel = new TreeNode("graph", false); //$NON-NLS-1$ + filters.add(graphLevel); + + for(int j=0; j<filterItems.length; j++) + graphLevel.add(new TreeNode(filterItems[j].getData(), false)); + } + } + + private IDataSet data; + private Tree treeGraphs; + private Text txtDisplay, txtCategory, txtDescription; + private Button btnAdd, btnRemove, btnAddFilter; + private String display, category, description; + private GraphData[] graphData; + private TreeNode filters; + private boolean canceled; + private TreeItem selectedTreeItem; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/dialogs/ScriptDetails.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/dialogs/ScriptDetails.java new file mode 100644 index 0000000000..0bef3a1855 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/dialogs/ScriptDetails.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Anithra P J + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.dashboardextension.dialogs; + + + +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.events.SelectionEvent; + +import org.eclipse.linuxtools.systemtap.ui.dashboard.internal.DashboardPlugin; +import org.eclipse.linuxtools.systemtap.ui.dashboard.preferences.DashboardPreferenceConstants; + +public class ScriptDetails extends Dialog { + private Text dirText; + private Text scriptText; + private Button OKButton; + private Button cancelButton; + private boolean canceled = false; + + public ScriptDetails(Shell parent) { + super(parent); + } + + /** + * This allows outside classes to determine if the user clicked ok or cancel. + * @return boolean representing whether the cancel button was pressed or not + */ + public boolean isCanceled() { + return canceled; + } + + public void open() { + + Shell parent = getParent(); + final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); + shell.setText("Enter Script details"); + shell.setSize(350, 160); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + shell.setLayout(layout); + + GridData data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.horizontalAlignment = SWT.LEFT; + Label dirLabel = new Label(shell, SWT.NONE); + dirLabel.setText("Examples Dir: "); + dirLabel.setLayoutData(data); + + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = SWT.FILL; + dirText = new Text(shell, SWT.SINGLE | SWT.BORDER); + dirText.setLayoutData(data); + dirText.setText(DashboardPlugin.getDefault().getPluginPreferences().getString(DashboardPreferenceConstants.P_DASHBOARD_EXAMPLES_DIR)); + + data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.horizontalAlignment = SWT.LEFT; + Label scriptLabel = new Label(shell, SWT.NONE); + scriptLabel.setText("Script: "); + scriptLabel.setLayoutData(data); + + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = SWT.FILL; + scriptText = new Text(shell, SWT.SINGLE | SWT.BORDER); + scriptText.setLayoutData(data); + //scriptText.setText(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_PASSWORD)); + + + data = new GridData(); + data.horizontalAlignment = SWT.RIGHT; + cancelButton = new Button(shell, SWT.PUSH); + cancelButton.setLayoutData(data); + cancelButton.setSize(50, 100); + cancelButton.setText("Cancel"); + cancelButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + shell.dispose(); + canceled = true; + } + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + data = new GridData(); + data.horizontalAlignment = SWT.RIGHT; + OKButton = new Button(shell, SWT.PUSH); + OKButton.setLayoutData(data); + OKButton.setSize(50, 100); + OKButton.setText("OK"); + OKButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + // FIXME: no error handling is done, should probably be + // pushed down to the connection level + // Set the preferences to this new info. + DashboardPlugin.getDefault().getPreferenceStore().setValue(DashboardPreferenceConstants.P_DASHBOARD_EXAMPLES_DIR, dirText.getText()); + DashboardPlugin.getDefault().getPreferenceStore().setValue(DashboardPreferenceConstants.P_DASHBOARD_SCRIPT, scriptText.getText()); + + shell.close(); + } + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + shell.open(); + Display display = parent.getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/DashboardExtensionPlugin.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/DashboardExtensionPlugin.java new file mode 100644 index 0000000000..e2910d8b85 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/DashboardExtensionPlugin.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.dashboardextension.internal; + +import org.eclipse.ui.IStartup; +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class DashboardExtensionPlugin extends AbstractUIPlugin implements IStartup { + + //The shared instance. + private static DashboardExtensionPlugin plugin; + + /** + * The constructor. + */ + public DashboardExtensionPlugin() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static DashboardExtensionPlugin 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 AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.linuxtools.systemtap.ui.dashboardextension", path); + } + + public void earlyStartup() {} +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/Localization.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/Localization.java new file mode 100644 index 0000000000..a105d5821a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/Localization.java @@ -0,0 +1,22 @@ +package org.eclipse.linuxtools.systemtap.ui.dashboardextension.internal; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Localization { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.systemtap.ui.dashboardextension.internal.localization"; + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle(BUNDLE_NAME); + + private Localization() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/localization.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/localization.properties new file mode 100644 index 0000000000..51fcc6b046 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/systemtap/ui/dashboardextension/internal/localization.properties @@ -0,0 +1,12 @@ +ExportScriptAction.NoFileToExport=No file open to export\! + +ExportScriptDialog.ExportScript=Export Script +ExportScriptDialog.Description=Description: +ExportScriptDialog.FillFields=You must fill in all the fields\! +ExportScriptAction.Error=Error +ExportScriptDialog.Display=Display: +ExportScriptDialog.Category=Category: +ExportScriptDialog.Graphs=Graphs: +ExportScriptDialog.Add=Add +ExportScriptDialog.AddFilter=Add Filter +ExportScriptDialog.Remove=Remove |