imakerplugin/com.nokia.s60tools.imaker/src/com/nokia/s60tools/imaker/internal/actions/Flashmenu.java
author dpodwall
Tue, 12 Jan 2010 13:17:53 -0600
changeset 0 61163b28edca
child 1 7ff23301fe22
permissions -rw-r--r--
initial EPL conversion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     1
/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     3
* All rights reserved.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     4
* This component and the accompanying materials are made available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     6
* which accompanies this distribution, and is available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     8
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     9
* Initial Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    11
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    12
* Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    13
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    14
* Description:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    15
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    16
*/
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    17
package com.nokia.s60tools.imaker.internal.actions;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    18
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    19
import java.lang.reflect.InvocationTargetException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    20
import java.util.List;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    21
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    22
import org.eclipse.core.resources.IFile;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    23
import org.eclipse.core.resources.IProject;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    24
import org.eclipse.core.resources.IResource;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    25
import org.eclipse.core.runtime.IStatus;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    26
import org.eclipse.core.runtime.Path;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    27
import org.eclipse.core.runtime.jobs.Job;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    28
import org.eclipse.jface.action.IAction;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    29
import org.eclipse.jface.dialogs.IDialogConstants;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    30
import org.eclipse.jface.dialogs.MessageDialog;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    31
import org.eclipse.jface.resource.ImageDescriptor;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    32
import org.eclipse.jface.viewers.ISelection;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    33
import org.eclipse.jface.viewers.IStructuredSelection;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    34
import org.eclipse.swt.SWT;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    35
import org.eclipse.swt.events.SelectionEvent;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    36
import org.eclipse.swt.events.SelectionListener;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    37
import org.eclipse.swt.widgets.Control;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    38
import org.eclipse.swt.widgets.Menu;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    39
import org.eclipse.swt.widgets.MenuItem;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    40
import org.eclipse.swt.widgets.Shell;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    41
import org.eclipse.ui.IWorkbenchWindow;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    42
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    43
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    44
import com.nokia.s60tools.imaker.IEnvironment;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    45
import com.nokia.s60tools.imaker.IEnvironmentManager;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    46
import com.nokia.s60tools.imaker.IIMakerWrapper;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    47
import com.nokia.s60tools.imaker.IMakerPlugin;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    48
import com.nokia.s60tools.imaker.IMakerUtils;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    49
import com.nokia.s60tools.imaker.Messages;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    50
import com.nokia.s60tools.imaker.StatusHandler;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    51
import com.nokia.s60tools.imaker.exceptions.IMakerCoreCancelledException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    52
import com.nokia.s60tools.imaker.exceptions.IMakerCoreExecutionException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    53
import com.nokia.s60tools.imaker.exceptions.IMakerCoreNotFoundException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    54
import com.nokia.s60tools.imaker.internal.console.IMakerJob;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    55
import com.nokia.s60tools.imaker.internal.dialogs.LaunchIMakerDialog;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    56
import com.nokia.s60tools.imaker.internal.managers.EnvironmentManager;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    57
import com.nokia.s60tools.imaker.internal.managers.ProjectManager;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    58
import com.nokia.s60tools.imaker.internal.model.ImakerProperties;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    59
import com.nokia.s60tools.imaker.internal.wrapper.IMakerWrapper;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    60
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    61
/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    62
 * @version 0.1
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    63
 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    64
public class Flashmenu implements IWorkbenchWindowPulldownDelegate {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    65
	/** menus items */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    66
	private Menu menu;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    67
	private final String MENU_ITEM_SETTINGS = Messages.getString("Flashmenu.17");
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    68
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    69
	/** private data members */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    70
	private MenuItem openDialogItem = null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    71
	private Shell shell;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    72
	private IProject selectedProject;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    73
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    74
	/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    75
	 * @see org.eclipse.ui.IWorkbenchWindowPulldownDelegate#getMenu(org.eclipse.swt.widgets.Control)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    76
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    77
	public Menu getMenu(Control parent) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    78
		/*dispose the previously used menu*/
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    79
		if(menu!=null) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    80
			menu.dispose();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    81
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    82
		/* Create new menu and listeners if first call */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    83
		MenuItem item = null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    84
		MenuSelectionListener msl = new MenuSelectionListener();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    85
		menu = new Menu(parent);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    86
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    87
		ImageDescriptor descriptor = IMakerPlugin.getImageDescriptor("icons/imakermenu16.png");
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    88
		ProjectManager pm = new ProjectManager(selectedProject);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    89
		List<IResource> files = pm.getImakerFiles();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    90
		for(IResource file: files) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    91
			IFile f = (IFile) file;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    92
			item = new MenuItem(menu, SWT.RADIO);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    93
			item.setText(f.getName());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    94
			item.setData(file);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    95
			item.setImage(descriptor.createImage());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    96
			item.addSelectionListener(msl);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    97
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    98
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    99
		item = new MenuItem(menu, SWT.SEPARATOR);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   100
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   101
		descriptor = IMakerPlugin.getImageDescriptor("icons/imakerdialog.png");
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   102
		openDialogItem = new MenuItem(menu, SWT.NULL);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   103
		openDialogItem.setText(MENU_ITEM_SETTINGS); //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   104
		openDialogItem.addSelectionListener(msl);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   105
		openDialogItem.setImage(descriptor.createImage());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   106
		return menu;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   107
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   108
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   109
	/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   110
	 * (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   111
	 * 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   112
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   113
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   114
	public void dispose() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   115
		if(menu!=null) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   116
			menu.dispose();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   117
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   118
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   119
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   120
	/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   121
	 * (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   122
	 * 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   123
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   124
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   125
	public void init(IWorkbenchWindow window) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   126
		this.shell = window.getShell();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   127
		window.getWorkbench();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   128
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   129
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   130
	/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   131
	 * (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   132
	 * 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   133
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   134
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   135
	public void run(IAction action) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   136
		IEnvironmentManager manager = EnvironmentManager.getInstance();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   137
		IEnvironment env = manager.getEnvironmentByDrive(getSelectionRoot());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   138
		ImakerProperties run = env.getRunProperties();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   139
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   140
		if(env!=null&&!run.isUsed()) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   141
			MessageDialog.openInformation(shell, "Unable To Launch iMaker", "The selection cannot be launched, and there are no recent " +
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   142
			"launches.\n Create new lauch using Open iMaker Dialog... from the pulldown menu.");			
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   143
		} else {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   144
			executeProperties(run);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   145
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   146
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   147
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   148
	public void selectionChanged(IAction action, ISelection selection) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   149
		if(selection instanceof IStructuredSelection) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   150
			IStructuredSelection ss = (IStructuredSelection) selection;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   151
			Object elem = ss.getFirstElement();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   152
			if(elem instanceof IResource) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   153
				selectedProject = ((IResource)elem).getProject();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   154
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   155
		} else {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   156
			selectedProject = null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   157
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   158
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   159
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   160
	private void initializeAndRunImaker(List<String> command) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   161
		String root = getSelectionRoot();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   162
		List<String> imaker = IMakerUtils.getImakerTool(root);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   163
		IIMakerWrapper wrapper = new IMakerWrapper(imaker);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   164
		IMakerJob job = new IMakerJob("Creating image", command,wrapper);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   165
		job.setPriority(Job.LONG);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   166
		job.setRule(IMakerPlugin.getDefault().getImakerRule());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   167
		job.schedule();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   168
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   169
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   170
	private String getSelectionRoot() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   171
		return IMakerUtils.getProjectRootLocation(selectedProject);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   172
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   173
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   174
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   175
	 * internal selectionlistener for menu items. 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   176
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   177
	private class MenuSelectionListener implements SelectionListener {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   178
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   179
		public void widgetDefaultSelected(SelectionEvent e) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   180
			widgetSelected(e);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   181
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   182
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   183
		public void widgetSelected(SelectionEvent e) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   184
			MenuItem selection = (MenuItem)e.widget;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   185
			if(selection==openDialogItem) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   186
				try {			
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   187
					ProjectManager projectManager = new ProjectManager(selectedProject);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   188
					IEnvironmentManager manager = IMakerPlugin.getEnvironmentManager();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   189
					manager.setActiveEnvironment(getSelectionRoot());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   190
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   191
					LaunchIMakerDialog dialog = new LaunchIMakerDialog(shell,
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   192
							projectManager,manager);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   193
					try {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   194
						manager.getActiveEnvironment().load();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   195
					} catch (InvocationTargetException ite) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   196
						Throwable cause = ite.getCause();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   197
						if(cause instanceof IMakerCoreCancelledException) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   198
							return;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   199
						} else if(cause instanceof IMakerCoreExecutionException) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   200
							StatusHandler.handle(IStatus.ERROR,Messages.getString("Error.1"),cause);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   201
						} else if(cause instanceof IMakerCoreNotFoundException) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   202
							StatusHandler.handle(IStatus.ERROR,Messages.getString("Error.2"),cause);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   203
						} else {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   204
							StatusHandler.handle(IStatus.ERROR,cause.getMessage(),cause);							
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   205
						}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   206
						return;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   207
					}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   208
					int returnValue = dialog.open();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   209
					if(returnValue == IDialogConstants.OK_ID) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   210
						String path = dialog.getFilePath();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   211
						ImakerProperties run = manager.getActiveEnvironment().getRunProperties();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   212
						if(!path.equals(ProjectManager.NEW_ITEM)) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   213
							IFile file = (IFile)projectManager.getImakerFile(new Path(path));
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   214
							ImakerProperties prop = ImakerProperties.createFromFile(file);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   215
							run.clear();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   216
							run.putAll(prop);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   217
						}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   218
						executeProperties(run);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   219
						run.setUsed(true);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   220
					}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   221
				} catch(NullPointerException ne) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   222
					ne.printStackTrace();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   223
				}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   224
			} else {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   225
				IFile file = (IFile) selection.getData();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   226
				if(file!=null) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   227
					ImakerProperties props = ImakerProperties.createFromFile(file);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   228
					executeProperties(props);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   229
				}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   230
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   231
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   232
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   233
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   234
	private void executeProperties(ImakerProperties prop) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   235
		String tempDirectory = System.getProperty("java.io.tmpdir"); 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   236
		String target = tempDirectory+ImakerProperties.GENERATED_FILES_FOLDER;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   237
		List<String> command = prop.parseImakerCommand(selectedProject, new Path(target));
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   238
		initializeAndRunImaker(command);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   239
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   240
}