Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 15c4117a550265c6d40b72ddebbde80ad77c6de7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*****************************************************************************
 * Copyright (c) 2015 CEA LIST and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Shuai Li (CEA LIST) <shuai.li@cea.fr> - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.editor.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.papyrus.editor.Activator;
import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

/**
 * The handler for the next/previous tab commands that let the user navigate to
 * the next/previous page of the active tab-folder with Ctrl+Shift/Ctrl+Shift+Tab
 * 
 * @author Shuai Li
 */
public abstract class TraverseTabHandler extends AbstractHandler {
	private final boolean isPrevious;
	
	public TraverseTabHandler() {
		isPrevious = false;
	}
	
	public TraverseTabHandler(boolean isPrevious) {
		this.isPrevious = isPrevious;
	}
	
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		
		if (activeWorkbenchWindow != null) {
			IWorkbenchPart activePart = activeWorkbenchWindow.getActivePage().getActivePart();
			
			if (activePart instanceof PapyrusMultiDiagramEditor) {
				PapyrusMultiDiagramEditor papyrusEditor = (PapyrusMultiDiagramEditor) activePart;
				try {
					IPage nextPage = null;
					if (isPrevious) {
						nextPage = papyrusEditor.getISashWindowsContainer().getPreviousPage();
					} else {
						nextPage = papyrusEditor.getISashWindowsContainer().getNextPage();
					}
					
					papyrusEditor.getISashWindowsContainer().selectPage(nextPage);
				} catch (Exception e) {
					Activator.log.error(e);
				}
			}
		}

		return null;
	}
}

Back to the top