blob: a677472881c5eeadd1ab16195a0349de5f74e2e8 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 Obeo.
* 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:
* Obeo - initial API and implementation and/or initial documentation
* ...
*******************************************************************************/
package org.eclipse.intent.mapping.ide.ui.command;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.intent.mapping.base.ILink;
import org.eclipse.intent.mapping.base.IReport;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
/**
* Describe the selected {@link ILink} or {@link IReport}.
*
* @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a>
*/
public class Describe extends AbstractHandler {
/**
* {@inheritDoc}
*
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getSelectionService().getSelection();
if (selection instanceof IStructuredSelection) {
final Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof ILink) {
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MultiLineTextDialog dialog = new MultiLineTextDialog(shell, ((ILink)element)
.getDescription());
if (dialog.open() == Window.OK) {
((ILink)element).setDescription(dialog.getText());
}
} else if (element instanceof IReport) {
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MultiLineTextDialog dialog = new MultiLineTextDialog(shell, ((IReport)element)
.getDescription());
if (dialog.open() == Window.OK) {
((IReport)element).setDescription(dialog.getText());
}
}
}
return null;
}
}