blob: f24edbb6c59b34a3da872ee85faf926c03917285 [file] [log] [blame]
/**
* Copyright (c) 2011, 2014 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* 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:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.vaaclipse.addons.perspective.handler;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.core.contexts.Active;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.model.application.ui.MContext;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
import org.eclipse.e4.ui.model.application.ui.menu.MItem;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osbp.vaaclipse.addons.application.handler.AbstractHandler;
import org.eclipse.osbp.vaaclipse.publicapi.perspective.IPerspectiveHandler;
/**
* The Class DeletePerspectiveHandler.
*/
public class DeletePerspectiveHandler extends AbstractHandler {
/** The handler. */
@Inject
private IPerspectiveHandler handler;
/** The user id. */
@Inject
@Optional
@Named("userId")
private String userId;
/**
* Execute.
*
* @param context
* the context
* @param perspective
* the perspective
* @param item
* the item
*/
@Execute
public void execute(@Active MContext context,
@Active MPerspective perspective, @Active MItem item) {
MPerspectiveStack stack = (MPerspectiveStack) ((EObject) perspective)
.eContainer();
if (handler.deletePerspective(userId, perspective)) {
// select the first perspective in the stack
if (stack.getSelectedElement() == null
&& !stack.getChildren().isEmpty()) {
stack.setSelectedElement(stack.getChildren().get(0));
}
}
}
/**
* Can execute.
*
* @param perspective
* the perspective
* @return true, if successful
*/
@CanExecute
public boolean canExecute(@Active MPerspective perspective) {
return handler.canDeletePerspective(userId, perspective);
}
}