/* * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jkiss.dbeaver.ui.editors.entity; import org.eclipse.jface.action.IMenuManager; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchCommandConstants; import org.eclipse.ui.part.MultiPageEditorActionBarContributor; import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; import org.jkiss.dbeaver.ui.ISearchContextProvider; import org.jkiss.dbeaver.ui.actions.common.ContextSearchAction; /** * Entity Editor contributor */ public class EntityEditorContributor extends MultiPageEditorActionBarContributor { private EntityEditor curEditor; private IEditorPart curPage; @Override public void setActiveEditor(IEditorPart part) { super.setActiveEditor(part); if (part instanceof EntityEditor) { curEditor = (EntityEditor) part; } } @Override public void setActivePage(IEditorPart activeEditor) { /*if (curPage != activeEditor) */{ curPage = activeEditor; registerSearchActions(activeEditor); } } @Override public void contributeToMenu(IMenuManager menuManager) { super.contributeToMenu(menuManager); } public static void registerSearchActions(IEditorPart activeEditor) { if (activeEditor == null) { return; } IActionBars actionBars = activeEditor.getEditorSite().getActionBars(); if (activeEditor instanceof ISearchContextProvider) { ISearchContextProvider provider = (ISearchContextProvider)activeEditor; if (provider.isSearchPossible()) { ContextSearchAction findAction = new ContextSearchAction(provider, ISearchContextProvider.SearchType.NONE); findAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE); actionBars.setGlobalActionHandler(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE, findAction); ContextSearchAction findNextAction = new ContextSearchAction(provider, ISearchContextProvider.SearchType.NEXT); findNextAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_NEXT); actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.FIND_NEXT, findNextAction); ContextSearchAction findPrevAction = new ContextSearchAction(provider, ISearchContextProvider.SearchType.PREVIOUS); findPrevAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_PREVIOUS); actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.FIND_PREVIOUS, findPrevAction); } } else { actionBars.setGlobalActionHandler(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE, null); actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.FIND_NEXT, null); actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.FIND_PREVIOUS, null); } actionBars.updateActionBars(); } }