Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2a592570131833e6b658d73fba4250e940f5e743 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
 * Copyright (c) 2006, 2008 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.internal.ui.navigator;

import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
import org.eclipse.ui.operations.UndoRedoActionGroup;

import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;

import org.eclipse.cdt.internal.ui.actions.SelectionConverter;

/**
 * A clone of org.eclipse.ui.internal.navigator.resources.actions.RefactorActionProvider.
 */
public class CNavigatorRefactorActionProvider extends CommonActionProvider {

	private UndoRedoActionGroup undoRedoGroup;
	private CNavigatorRefactorActionGroup resourceRefactorGroup;
	private CRefactoringActionGroup cElementRefactorGroup;

	private ICommonActionExtensionSite site;

	/*
	 * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
	 */
	@Override
	public void init(ICommonActionExtensionSite actionSite) {
		site = actionSite;
		resourceRefactorGroup= new CNavigatorRefactorActionGroup(site.getViewSite().getShell(), (Tree)site.getStructuredViewer().getControl());
		IUndoContext workspaceContext= (IUndoContext) ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
		ICommonViewerWorkbenchSite workbenchSite = null;
		if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) {
			workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite();
		}
		if (workbenchSite != null) {
			undoRedoGroup = new UndoRedoActionGroup(workbenchSite.getSite(), workspaceContext, true);
			cElementRefactorGroup= new CRefactoringActionGroup(workbenchSite.getPart());
		}
}

	@Override
	public void dispose() {
		undoRedoGroup.dispose();
		resourceRefactorGroup.dispose();
		cElementRefactorGroup.dispose();
	}

	@Override
	public void fillActionBars(IActionBars actionBars) {
		undoRedoGroup.fillActionBars(actionBars);
		resourceRefactorGroup.fillActionBars(actionBars);
		cElementRefactorGroup.updateActionBars();
		cElementRefactorGroup.fillActionBars(actionBars);
	}

	@Override
	public void fillContextMenu(IMenuManager menu) {
		undoRedoGroup.fillContextMenu(menu);
		resourceRefactorGroup.fillContextMenu(menu);
		cElementRefactorGroup.fillContextMenu(menu);
	}

	@Override
	public void setContext(ActionContext context) {
		undoRedoGroup.setContext(context);
		resourceRefactorGroup.setContext(convertToResources(context));
		cElementRefactorGroup.setContext(context);
	}

	@Override
	public void updateActionBars() {
		undoRedoGroup.updateActionBars();
		resourceRefactorGroup.updateActionBars();
		cElementRefactorGroup.updateActionBars();
	}

	/**
	 * @param context
	 * @return context with selection elements converted to IResources
	 */
	private ActionContext convertToResources(ActionContext context) {
		if (context != null) {
			// convert non-IResource to IResources
			ISelection selection = SelectionConverter.convertSelectionToResources(context.getSelection());
			return new ActionContext(selection);
		}
		return null;
	}

}

Back to the top