|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2013 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
******************************************************************************/ |
| 11 |
|
| 12 |
package org.eclipse.ui.internal; |
| 13 |
|
| 14 |
import java.util.List; |
| 15 |
import org.eclipse.core.commands.AbstractHandler; |
| 16 |
import org.eclipse.core.commands.ExecutionEvent; |
| 17 |
import org.eclipse.core.commands.ExecutionException; |
| 18 |
import org.eclipse.e4.core.di.annotations.Execute; |
| 19 |
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; |
| 20 |
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack; |
| 21 |
import org.eclipse.e4.ui.model.application.ui.basic.MWindow; |
| 22 |
import org.eclipse.e4.ui.workbench.modeling.EModelService; |
| 23 |
import org.eclipse.ui.IWorkbenchWindow; |
| 24 |
import org.eclipse.ui.handlers.HandlerUtil; |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* @since 3.5 |
| 29 |
* |
| 30 |
*/ |
| 31 |
public class FlipPerspectiveWithNextHandler extends AbstractHandler { |
| 32 |
|
| 33 |
/** |
| 34 |
* @throws ExecutionException |
| 35 |
*/ |
| 36 |
@Execute |
| 37 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
| 38 |
MPerspectiveStack perspectiveStack = findPerspectiveStack(event); |
| 39 |
MPerspective selectedPerspective = perspectiveStack.getSelectedElement(); |
| 40 |
List<MPerspective> perspectives = perspectiveStack.getChildren(); |
| 41 |
int selectedIndex = perspectives.indexOf(selectedPerspective); |
| 42 |
int maxIndex = perspectives.size() - 1; |
| 43 |
try { |
| 44 |
if (selectedIndex < maxIndex) { |
| 45 |
int nextIndex = selectedIndex + 1; |
| 46 |
MPerspective nextPerspective = perspectives.remove(nextIndex); |
| 47 |
perspectives.add(selectedIndex, nextPerspective); |
| 48 |
} |
| 49 |
} catch (Exception e) { |
| 50 |
System.out.println(e); |
| 51 |
} |
| 52 |
return null; |
| 53 |
} |
| 54 |
|
| 55 |
private MPerspectiveStack findPerspectiveStack(ExecutionEvent event) { |
| 56 |
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); |
| 57 |
MWindow model = (MWindow) window.getService(MWindow.class); |
| 58 |
EModelService modelService = (EModelService) window.getService(EModelService.class); |
| 59 |
List<MPerspectiveStack> perspectiveStacks = modelService.findElements(model, null, |
| 60 |
MPerspectiveStack.class, null); |
| 61 |
return perspectiveStacks.get(0); |
| 62 |
} |
| 63 |
|
| 64 |
} |