blob: dd99a50bcaebd828195f9629fe88a2106be8f63d (
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
|
/*****************************************************************************
* Copyright (c) 2011 CEA LIST.
*
* 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:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.views.properties.toolsmiths.editor.actions;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.papyrus.views.properties.toolsmiths.Activator;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
/**
* An action to toggle the UIEditor Preview
*
* @author Camille Letavernier
*/
public class TogglePreviewAction extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// System.out.println("Toggle");
event.getCommand().getState("org.eclipse.papyrus.customization.properties.previewstate"); //$NON-NLS-1$
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (activePage == null) {
return null;
}
// System.out.println("ActivePage is " + activePage);
IViewReference viewReference = null;
for (IViewReference reference : activePage.getViewReferences()) {
if (reference.getId().equals(Activator.PREVIEW_ID)) {
viewReference = reference;
}
}
try {
if (viewReference == null) {
// System.out.println("Opening view");
activePage.showView(Activator.PREVIEW_ID);
} else {
// System.out.println("Closing view");
activePage.hideView((ViewPart) viewReference.getPart(false));
}
} catch (PartInitException ex) {
Activator.log.error(ex);
}
return null;
}
}
|