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
|
/*******************************************************************************
* Copyright (c) 2001, 2004 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.wst.wsdl.ui.internal.actions;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.EditorActionBarContributor;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.wst.wsdl.ui.internal.WSDLEditor;
import org.eclipse.wst.wsdl.ui.internal.WSDLTextEditor;
public class WSDLActionBarContributor extends SourceEditorActionBarContributor
{
protected WSDLTextEditor textEditor;
/**
* Constructor for WSDLActionBarContributor.
*/
public WSDLActionBarContributor()
{
super();
}
public void setActivePage(IEditorPart activeEditor)
{
super.setActivePage(activeEditor);
// always enable undo/redo regardless of which page we're on. The undo/redo comes from the editor
//
updateAction(IWorkbenchActionConstants.UNDO, ITextEditorActionConstants.UNDO, true);
updateAction(IWorkbenchActionConstants.REDO, ITextEditorActionConstants.REDO, true);
// turn these off so that the actionhandler will handle it for us
//
//updateAction(IWorkbenchActionConstants.CUT, ITextEditorActionConstants.CUT, false);
//updateAction(IWorkbenchActionConstants.COPY, ITextEditorActionConstants.COPY, false);
//updateAction(IWorkbenchActionConstants.PASTE, ITextEditorActionConstants.PASTE, false);
getActionBars().updateActionBars();
}
protected void updateAction(String globalActionId, String textEditorActionId, boolean enable)
{
getActionBars().setGlobalActionHandler(globalActionId, enable ? getAction(textEditor, textEditorActionId) : null);
}
/**
* Returns the action registed with the given text editor.
* @return IAction or null if editor is null.
*/
protected IAction getAction(ITextEditor editor, String actionID)
{
try
{
return (editor == null ? null : editor.getAction(actionID));
}
catch (Exception e)
{
return null;
}
}
/**
* @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
*/
public void addToToolBar(IToolBarManager toolBarManager)
{
super.addToToolBar(toolBarManager);
toolBarManager.add(new GroupMarker("WSDLEditor"));
}
public void setActiveEditor(IEditorPart activeEditor)
{
super.setActiveEditor(activeEditor);
textEditor = null;
if (activeEditor instanceof WSDLEditor)
{
textEditor = ((WSDLEditor) activeEditor).getWSDLTextEditor();
}
updateAction(IWorkbenchActionConstants.UNDO, ITextEditorActionConstants.UNDO, true);
updateAction(IWorkbenchActionConstants.REDO, ITextEditorActionConstants.REDO, true);
}
}
|