/*******************************************************************************
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
*******************************************************************************/
package com.liferay.ide.portlet.ui.editor;
import com.liferay.ide.core.util.StringPool;
import com.liferay.ide.ui.editor.IDEFormEditorContributor;
import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
/**
* @author Greg Amerson
*/
public class PluginPackageEditorActionBarContributor extends IDEFormEditorContributor
{
protected IEditorPart activeEditorPart;
public PluginPackageEditorActionBarContributor()
{
super( StringPool.EMPTY );
}
@Override
public void setActivePage( IEditorPart part )
{
if( activeEditorPart == part )
return;
activeEditorPart = part;
IActionBars actionBars = getActionBars();
if( actionBars != null )
{
ITextEditor editor = ( part instanceof ITextEditor ) ? (ITextEditor) part : null;
actionBars.setGlobalActionHandler(
ActionFactory.DELETE.getId(), getAction( editor, ITextEditorActionConstants.DELETE ) );
actionBars.setGlobalActionHandler(
ActionFactory.UNDO.getId(), getAction( editor, ITextEditorActionConstants.UNDO ) );
actionBars.setGlobalActionHandler(
ActionFactory.REDO.getId(), getAction( editor, ITextEditorActionConstants.REDO ) );
actionBars.setGlobalActionHandler(
ActionFactory.CUT.getId(), getAction( editor, ITextEditorActionConstants.CUT ) );
actionBars.setGlobalActionHandler(
ActionFactory.COPY.getId(), getAction( editor, ITextEditorActionConstants.COPY ) );
actionBars.setGlobalActionHandler(
ActionFactory.PASTE.getId(), getAction( editor, ITextEditorActionConstants.PASTE ) );
actionBars.setGlobalActionHandler(
ActionFactory.SELECT_ALL.getId(), getAction( editor, ITextEditorActionConstants.SELECT_ALL ) );
actionBars.setGlobalActionHandler(
ActionFactory.FIND.getId(), getAction( editor, ITextEditorActionConstants.FIND ) );
actionBars.setGlobalActionHandler(
IDEActionFactory.BOOKMARK.getId(), getAction( editor, IDEActionFactory.BOOKMARK.getId() ) );
actionBars.updateActionBars();
}
}
/**
* Returns the action registed with the given text editor.
*
* @return IAction or null if editor is null.
*/
protected IAction getAction( ITextEditor editor, String actionID )
{
return( editor == null ? null : editor.getAction( actionID ) );
}
}