📄 lgprotegeeditactioncontributor.java
字号:
/*
* Copyright: (c) 2004 Mayo Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must include
* the following acknowledgment:
* "This product includes software developed by Mayo Clinic Division of Biomedical
* Informatics Research (http://informatics.mayo.edu/)."
* Alternately, this acknowledgment may appear in the software itself, if and wherever
* such third-party acknowledgments normally appear.
*
* 4. The names "Mayo", "Mayo Clinic", "Mayo Foundation", "LexGrid", or "LexGrid Editor"
* must not be used to endorse or promote products derived from this software without
* prior written permission. For written permission, please contact the author
* or copyright holder.
*
* 5. Products derived from this software may not be called "LexGrid Editor", nor may
* "LexGrid" or "Mayo" appear in their name, without prior written permission of the
* author or copyright holder.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MAYO CLINIC OR OTHER
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lexgrid.ui.extension.protege;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.EditorActionBarContributor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
/**
* Contributes eclipse-based actions to Protege editors.
*
* @author <A HREF="mailto:johnson.thomas@mayo.edu">Thomas M Johnson</A>
*/
public class LgProtegeEditActionContributor extends EditorActionBarContributor {
protected LgProtegeEditor activeEditor = null;
protected IMenuManager viewMenu = null;
protected IToolBarManager toolbar = null;
protected Action detachTabAction = null;
public LgProtegeEditActionContributor() {
super();
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
*/
public void contributeToMenu(IMenuManager menuManager) {
super.contributeToMenu(menuManager);
// Note: The following attempts to help alleviate the fact that the 'Save' menu
// choice is not always kept synchronized with the editor state. Here we ensure
// that the action is enabled propertly on drop-down of the file menu. When an
// alternative/better method is discovered, this code should be removed.
IMenuManager fileMgr = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_FILE);
if (fileMgr != null)
fileMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
if (activeEditor != null) {
IContributionItem[] items = manager.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i] instanceof ActionContributionItem
&& ((ActionContributionItem) items[i]).getAction().getId().equals(ITextEditorActionConstants.SAVE))
{
(((ActionContributionItem) items[i]).getAction()).setEnabled(activeEditor.isDirty());
break;
}
}
}
}
});
// Contribute menu items to the 'View' drop-down ...
IMenuManager editMgr = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
try {
menuManager.remove(LgProtegeActionProviderIF.M_Viewer);
} catch (IllegalArgumentException e) {
// Ignore ... ID not found
}
if (viewMenu == null || viewMenu.isDirty() || viewMenu.isEmpty()) {
viewMenu = new MenuManager(LgProtegeI18n.getI18nString("_UI_Action_Viewer_menu_label"), LgProtegeActionProviderIF.M_Viewer);
viewMenu.add(new Separator(LgProtegeActionProviderIF.S_Viewer_start));
populateViewerMenu(viewMenu);
viewMenu.add(new Separator(LgProtegeActionProviderIF.S_Viewer_additions));
viewMenu.add(new Separator(LgProtegeActionProviderIF.S_Viewer_end));
}
menuManager.insertAfter(editMgr.getId(), viewMenu);
menuManager.updateAll(true);
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(org.eclipse.jface.action.IToolBarManager)
*/
public void contributeToToolBar(IToolBarManager toolBarManager) {
super.contributeToToolBar(toolBarManager);
toolbar = toolBarManager;
IContributionItem[] items = toolBarManager.getItems();
for (int i = 0; i < items.length; i++)
toolBarManager.remove(items[i]);
toolBarManager.add(new Separator(LgProtegeActionProviderIF.S_Viewer_start));
populateToolBar(toolBarManager);
toolBarManager.add(new Separator(LgProtegeActionProviderIF.S_Viewer_additions));
toolBarManager.add(new Separator(LgProtegeActionProviderIF.S_Viewer_end));
toolBarManager.update(true);
}
protected Action getDetachTabAction() {
if (detachTabAction == null) {
detachTabAction = new Action("Detach Current Tab") {
public void run() {
if (activeEditor != null)
activeEditor.detachCurrentProjectTab();
}
};
detachTabAction.setAccelerator(SWT.CTRL | 'T');
detachTabAction.setImageDescriptor(LgProtegeI18n.getImageDescriptor("action_detach.gif"));
detachTabAction.setToolTipText("Displays the current Protege project tab in a new window.");
}
return detachTabAction;
}
/**
* Invoked during toolbar creation to populate the main grouping
* for the viewer (prior to the "additions" section).
* @param toolbar
*/
protected void populateToolBar(IToolBarManager toolbar) {
toolbar.add(getDetachTabAction());
}
/**
* Invoked during menu creation to populate the main grouping
* of the viewer menu (prior to the "additions" section).
* @param viewerMenu
*/
protected void populateViewerMenu(IMenuManager viewerMenu) {
viewerMenu.add(getDetachTabAction());
}
/* (non-Javadoc)
* @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
*/
public void setActiveEditor(IEditorPart part) {
if ((activeEditor = (part instanceof LgProtegeEditor) ? (LgProtegeEditor) part : null)
!= null)
contributeToMenu(((IEditorSite) part.getSite()).getActionBars().getMenuManager());
super.setActiveEditor(part);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -