/*******************************************************************************
* 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.IFile;
import org.eclipse.core.resources.IFolder;
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.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.eclipse.wgadesigner.dialogs.ChangeDirlinkTargetDialog;
public class ChangeDirlinkTarget implements IViewActionDelegate {
private IFolder _selectedFodler;
public void run(IAction action) {
Shell shell = new Shell(Display.getCurrent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
if (_selectedFodler != null) {
ChangeDirlinkTargetDialog dialog = new ChangeDirlinkTargetDialog(shell, _selectedFodler);
dialog.open();
} else {
Plugin.getDefault().logError("Can not open ChangeDirlinkTargetDialog. No Dirlinkfolder selected.");
}
}
public void selectionChanged(IAction action, ISelection selection) {
action.setEnabled(false);
if (selection != null && selection instanceof IStructuredSelection) {
IStructuredSelection structSelection = (IStructuredSelection) selection;
Object selectedElement = structSelection.getFirstElement();
if (selectedElement instanceof IFolder) {
IFolder folder = (IFolder)selectedElement;
if(WGADesignStructureHelper.isDirlinkFolder(folder)){
_selectedFodler = folder;
action.setEnabled(true);
}
}
if (selectedElement instanceof IFile) {
IFile file = (IFile)selectedElement;
if(file.getParent() instanceof IFolder){
IFolder folder = (IFolder)file.getParent();
if(WGADesignStructureHelper.isDirlinkFolder(folder)){
_selectedFodler = folder;
action.setEnabled(true);
}
}
}
}
}
public void init(IViewPart view) {
// TODO Auto-generated method stub
}
}