org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/navigator/RenameMoveActionProvider.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Wed, 21 Jul 2010 11:26:43 -0700
changeset 454 38d6944cff88
parent 141 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/navigator/RenameMoveActionProvider.java@f711e4ac391d
permissions -rw-r--r--
Bug 3352 - Replace our Navigator View with the JSDT one
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
454
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
     1
/**
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
     2
 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
     3
 * All rights reserved.
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
     4
 * This component and the accompanying materials are made available
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
     6
 * which accompanies this distribution, and is available
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
     8
 *
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
     9
 * Initial Contributors:
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    10
 * Symbian Foundation - initial contribution.
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    11
 * Contributors:
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    12
 * Description:
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    13
 * Overview:
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    14
 * Details:
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    15
 * Platforms/Drives/Compatibility:
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    16
 * Assumptions/Requirement/Pre-requisites:
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    17
 * Failures and causes:
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    18
 */
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    19
package org.symbian.tools.mtw.ui.navigator;
141
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
import java.util.Collection;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import java.util.HashSet;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
import org.eclipse.jface.action.IAction;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
import org.eclipse.jface.action.IMenuManager;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
import org.eclipse.jface.action.Separator;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
import org.eclipse.jface.viewers.ISelection;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
import org.eclipse.jface.viewers.ISelectionProvider;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
import org.eclipse.ui.IActionBars;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
import org.eclipse.ui.IViewPart;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
import org.eclipse.ui.IWorkbenchPartSite;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
import org.eclipse.ui.actions.ActionContext;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
import org.eclipse.ui.actions.ActionFactory;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
import org.eclipse.ui.navigator.CommonActionProvider;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
import org.eclipse.wst.jsdt.ui.IContextMenuConstants;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
import org.eclipse.wst.jsdt.ui.actions.IJavaEditorActionDefinitionIds;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
import org.eclipse.wst.jsdt.ui.actions.JdtActionConstants;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
import org.eclipse.wst.jsdt.ui.actions.MoveAction;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
import org.eclipse.wst.jsdt.ui.actions.RenameAction;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
import org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    44
public class RenameMoveActionProvider extends CommonActionProvider {
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    45
 	private SelectionDispatchAction fMoveAction;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    46
	private SelectionDispatchAction fRenameAction;
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
	
454
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    48
	private final Collection<IAction> fActions = new HashSet<IAction>();
141
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
	public void fillActionBars(IActionBars actionBars) {
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
		if (fActions.size() > 0) {
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    52
			actionBars.setGlobalActionHandler(JdtActionConstants.RENAME, fRenameAction);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    53
			actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), fRenameAction);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    54
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    55
			actionBars.setGlobalActionHandler(JdtActionConstants.MOVE, fMoveAction);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    56
			actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), fMoveAction);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    57
		}
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    58
	}
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    59
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    60
	public void fillContextMenu(IMenuManager menu) {
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    61
		menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, new Separator());
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    62
		for (IAction action : fActions) {
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    63
			menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, action);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    64
		}
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
	}
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    67
	public void init(ICommonActionExtensionSite site) {
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
		ICommonViewerWorkbenchSite workbenchSite= null;
454
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    69
		if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) {
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    70
            workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite();
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    71
        }
141
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    72
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    73
		// we only initialize the refactor group when in a view part 
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    74
		// (required for the constructor)
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    75
		if (workbenchSite != null) {
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    76
			if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    77
				IViewPart viewPart= (IViewPart) workbenchSite.getPart();
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    78
				IWorkbenchPartSite s = viewPart.getSite();
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    79
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    80
				fRenameAction= new RenameAction(s);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    81
				initUpdatingAction(fRenameAction, workbenchSite.getSelectionProvider(), workbenchSite.getSelectionProvider().getSelection(), IJavaEditorActionDefinitionIds.RENAME_ELEMENT);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    82
				fMoveAction= new MoveAction(s);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    83
				initUpdatingAction(fMoveAction, workbenchSite.getSelectionProvider(), workbenchSite.getSelectionProvider().getSelection(), IJavaEditorActionDefinitionIds.RENAME_ELEMENT);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    84
			}
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    85
		}
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    86
	}
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    87
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    88
	private void initUpdatingAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection, String actionDefinitionId){
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    89
		action.setActionDefinitionId(actionDefinitionId);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    90
		action.update(selection);
454
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    91
		if (provider != null) {
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    92
            provider.addSelectionChangedListener(action);
38d6944cff88 Bug 3352 - Replace our Navigator View with the JSDT one
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 141
diff changeset
    93
        }
141
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    94
		fActions.add(action);
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    95
	}
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    96
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    97
	
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    98
	public void setContext(ActionContext context) {
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    99
		// Do nothing
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   100
	}
f711e4ac391d Fixed Bug 1867 - Replace "refactor" with "rename" and "move"
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   101
}