0
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
package com.nokia.s60tools.metadataeditor.ui.actions;
|
|
21 |
|
|
22 |
import org.eclipse.core.resources.IProject;
|
|
23 |
import org.eclipse.core.resources.ResourcesPlugin;
|
|
24 |
import org.eclipse.jface.action.IAction;
|
|
25 |
import org.eclipse.jface.dialogs.MessageDialog;
|
|
26 |
import org.eclipse.jface.viewers.ISelection;
|
|
27 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
28 |
import org.eclipse.jface.wizard.WizardDialog;
|
|
29 |
import org.eclipse.swt.widgets.Shell;
|
|
30 |
import org.eclipse.ui.ISelectionService;
|
|
31 |
import org.eclipse.ui.IWorkbench;
|
|
32 |
import org.eclipse.ui.IWorkbenchWindow;
|
|
33 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
|
34 |
|
|
35 |
import com.nokia.s60tools.metadataeditor.MetadataEditorActivator;
|
|
36 |
import com.nokia.s60tools.metadataeditor.common.ProductInfoRegistry;
|
|
37 |
import com.nokia.s60tools.metadataeditor.util.MetadataEditorConsole;
|
|
38 |
import com.nokia.s60tools.metadataeditor.wizards.APIMetadataFileNewWizard;
|
|
39 |
import com.nokia.s60tools.util.console.IConsolePrintUtility;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Action for menu action "API Metadata file". Launches {@link APIMetadataFileNewWizard} wizard.
|
|
43 |
*/
|
|
44 |
public class ToolsMenuAction implements IWorkbenchWindowActionDelegate {
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Reference to workbench window
|
|
48 |
*/
|
|
49 |
private IWorkbenchWindow window;
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Constructor.
|
|
53 |
*/
|
|
54 |
public ToolsMenuAction(){
|
|
55 |
}
|
|
56 |
|
|
57 |
/* (non-Javadoc)
|
|
58 |
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
|
|
59 |
*/
|
|
60 |
public void dispose() {
|
|
61 |
}
|
|
62 |
|
|
63 |
/* (non-Javadoc)
|
|
64 |
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
|
|
65 |
*/
|
|
66 |
public void init(IWorkbenchWindow window) {
|
|
67 |
this.window = window;
|
|
68 |
}
|
|
69 |
|
|
70 |
/* (non-Javadoc)
|
|
71 |
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
|
72 |
*/
|
|
73 |
public void run(IAction action) {
|
|
74 |
try {
|
|
75 |
|
|
76 |
IProject projects [] = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
|
77 |
if(projects.length < 1){
|
|
78 |
showErrorDialog( ProductInfoRegistry.getProductName() + " Error",
|
|
79 |
"No existing projects in workspace! Please create a project before creating files!");
|
|
80 |
return;
|
|
81 |
}
|
|
82 |
|
|
83 |
|
|
84 |
APIMetadataFileNewWizard wiz = new APIMetadataFileNewWizard();
|
|
85 |
IWorkbench wp = window.getWorkbench();
|
|
86 |
|
|
87 |
ISelectionService selser = window.getSelectionService();
|
|
88 |
ISelection sel = selser.getSelection();
|
|
89 |
IStructuredSelection structSel = null;
|
|
90 |
//pre-select selection if made in resource tree
|
|
91 |
if(sel instanceof IStructuredSelection){
|
|
92 |
structSel = (IStructuredSelection)sel;
|
|
93 |
}
|
|
94 |
|
|
95 |
|
|
96 |
wiz.init(wp, structSel);
|
|
97 |
//Opening new Creator script file dialog.
|
|
98 |
WizardDialog dialog = new WizardDialog
|
|
99 |
(wp.getActiveWorkbenchWindow().getShell(),wiz);
|
|
100 |
dialog.open();
|
|
101 |
|
|
102 |
|
|
103 |
} catch (Exception e) {
|
|
104 |
e.printStackTrace();
|
|
105 |
MetadataEditorConsole.getInstance().println(e.getMessage(),
|
|
106 |
IConsolePrintUtility.MSG_ERROR);
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
/**
|
|
111 |
* Show an error dialog
|
|
112 |
* @param title
|
|
113 |
* @param message
|
|
114 |
* @param errors
|
|
115 |
*/
|
|
116 |
private void showErrorDialog(String title, String message) {
|
|
117 |
Shell sh = MetadataEditorActivator.getCurrentlyActiveWbWindowShell();
|
|
118 |
MessageDialog.openError(sh, title, message);
|
|
119 |
|
|
120 |
}
|
|
121 |
|
|
122 |
/* (non-Javadoc)
|
|
123 |
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
|
|
124 |
*/
|
|
125 |
public void selectionChanged(IAction action, ISelection selection) {
|
|
126 |
}
|
|
127 |
|
|
128 |
}
|