blob: caf9ea5e12fd9c53a379d8898f73c88b34aeb42b (
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
|
/*******************************************************************************
* Copyright (c) 2012 Wind River Systems, Inc. and others. 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:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.ui.views.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.tcf.te.ui.views.ViewsUtil;
import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.part.EditorPart;
/**
* "Show In System Management" command handler implementation.
*/
public class ShowInSystemManagementHandler extends AbstractHandler {
/* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Show the view
ViewsUtil.show(IUIConstants.ID_EXPLORER);
// Get the active part
IWorkbenchPart part = HandlerUtil.getActivePart(event);
// Get the current selection
ISelection selection = HandlerUtil.getCurrentSelection(event);
// If the handler is invoked from an editor part, than we do not have a selection.
// Determine the active editor input and construct a fake selection object from it.
if ((selection == null || selection.isEmpty()) && part instanceof EditorPart) {
IEditorInput input = ((EditorPart)part).getEditorInput();
Object element = input != null ? input.getAdapter(Object.class) : null;
if (element != null) selection = new StructuredSelection(element);
}
// Pass on to the view
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
ViewsUtil.setSelection(IUIConstants.ID_EXPLORER, selection);
}
return null;
}
}
|