/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.actions;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.dialogs.AddExternalDesignDialog;
public class AddExternalDesign implements IActionDelegate {
private IProject _selectedProject;
public void run(IAction action) {
Shell shell = new Shell(Display.getCurrent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
if (_selectedProject != null) {
AddExternalDesignDialog dialog = new AddExternalDesignDialog(shell, _selectedProject);
dialog.open();
}
}
public void selectionChanged(IAction action, ISelection selection) {
action.setEnabled(false);
_selectedProject = null;
if (selection != null && selection instanceof IStructuredSelection) {
IStructuredSelection structSelection = (IStructuredSelection) selection;
Object selectedElement = structSelection.getFirstElement();
if (selectedElement instanceof IProject || selectedElement instanceof IJavaProject) {
_selectedProject = (IProject) selectedElement;
} else if (selectedElement instanceof IContainer) {
IContainer container = (IContainer) selectedElement;
if (container.getParent() instanceof IProject &&
(container.getName().equalsIgnoreCase("designs") || container.getName().equalsIgnoreCase("plugins"))) {
_selectedProject = container.getProject();
}
}
}
try {
if (_selectedProject != null && _selectedProject.hasNature(WGADesignerPlugin.NATURE_WGA_RUNTIME)) {
action.setEnabled(true);
}
} catch (CoreException e) {
}
}
}