1
/*******************************************************************************
2
* Copyright (c) 2006 IBM Corporation.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J
10
*******************************************************************************/
12
package org.eclipse.linuxtools.internal.systemtap.ui.dashboardextension.actions;
14
import java.io.FileInputStream;
15
import java.io.IOException;
17
import org.eclipse.jface.action.Action;
18
import org.eclipse.jface.action.IAction;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.IViewActionDelegate;
23
import org.eclipse.ui.IViewPart;
24
import org.eclipse.ui.IWorkbenchPage;
25
import org.eclipse.ui.PlatformUI;
26
import org.eclipse.ui.WorkbenchException;
28
import org.eclipse.linuxtools.systemtap.ui.editor.SimpleEditor;
29
import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardModule;
30
import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.ModuleTreeNode;
31
import org.eclipse.linuxtools.systemtap.ui.ide.IDEPerspective;
32
import org.eclipse.linuxtools.systemtap.ui.ide.actions.TempFileAction;
35
* A class that handles extracting the original script from the dashboard module.
36
* It will then create a new active editor in the IDE perspective and display the
37
* module in a temp file. Users can then modify this script and use the modified
38
* version as well as the original.
41
public class ViewScriptAction extends Action implements IViewActionDelegate {
43
* This method sets what item the user has selected to view.
45
public void init(IViewPart view) {
50
* This method will retreive the script from the selected module for the user
51
* to see. It will then create a new active editor in the IDE perspective and
52
* display the module in a temp file. Users can then modify this script and
53
* use the modified version as well as the original.
54
* @param act An action representing the click event used to start this method.
56
public void run(IAction act) {
57
DashboardModule data = (DashboardModule)selectedItem.getData();
60
IWorkbenchPage p = PlatformUI.getWorkbench().showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
62
TempFileAction tfa = new TempFileAction();
65
IEditorPart edit = p.getActiveEditor();
68
if(edit instanceof SimpleEditor) {
69
SimpleEditor editor = (SimpleEditor)edit;
71
//Copy the file just to ensure the user has to save their own copy if they want it
74
fin = new FileInputStream(data.script);
75
StringBuilder sb = new StringBuilder();
78
while((c = fin.read()) != -1)
82
editor.insertText(sb.toString());
83
} catch (IOException e) {}
86
} catch(WorkbenchException we) {}
90
* This method will update the selected item when a new item is selected.
91
* @param action The action that fired this method.
92
* @param selection The newly selected item.
94
public void selectionChanged(IAction action, ISelection selection) {
95
if(selection instanceof IStructuredSelection) {
96
IStructuredSelection selected = (IStructuredSelection)selection;
97
Object o = selected.getFirstElement();
98
if(o instanceof ModuleTreeNode) {
99
selectedItem = (ModuleTreeNode)o;
100
o = selectedItem.getData();
110
private ModuleTreeNode selectedItem;