001: package org.drools.eclipse.editors;
002:
003: /*
004: * Copyright 2006 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import org.eclipse.gef.editparts.ZoomManager;
020: import org.eclipse.gef.ui.actions.ZoomComboContributionItem;
021: import org.eclipse.jface.action.IToolBarManager;
022: import org.eclipse.jface.action.Separator;
023: import org.eclipse.ui.IActionBars;
024: import org.eclipse.ui.IEditorPart;
025: import org.eclipse.ui.IWorkbenchPage;
026: import org.eclipse.ui.editors.text.TextEditorActionContributor;
027: import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
028: import org.eclipse.ui.texteditor.ITextEditor;
029:
030: /**
031: * ActionContributors for DRLRuleEditor2
032: *
033: * Currently implements contributors to zoom feature at rete viewer.
034: *
035: * @author Ahti Kitsik
036: *
037: */
038: public class DRLRuleEditorActionContributor extends
039: MultiPageEditorActionBarContributor {
040:
041: private TextEditorActionContributor contributor = new TextEditorActionContributor();
042:
043: private ZoomComboContributionItem zitem;
044: private ZoomOutAction2 zoomOut;
045: private ZoomInAction2 zoomIn;
046:
047: /* (non-Javadoc)
048: * @see org.eclipse.ui.part.EditorActionBarContributor#init(org.eclipse.ui.IActionBars, org.eclipse.ui.IWorkbenchPage)
049: */
050: public void init(IActionBars bars, IWorkbenchPage page) {
051: contributor.init(bars);
052: super .init(bars, page);
053: }
054:
055: /* (non-Javadoc)
056: * @see org.eclipse.ui.part.MultiPageEditorActionBarContributor#setActivePage(org.eclipse.ui.IEditorPart)
057: */
058: public void setActivePage(IEditorPart activeEditor) {
059: IActionBars bars = getActionBars();
060: if (activeEditor instanceof ITextEditor) {
061: if (bars != null) {
062: contributor.setActiveEditor(activeEditor);
063: }
064: }
065: }
066:
067: /**
068: * In addition to @link org.eclipse.ui.part.MultiPageEditorActionBarContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
069: * it sets contribution items to DRLRuleEditor2 for later use when
070: * multipageditor tabs are switched.
071: *
072: */
073: public void setActiveEditor(IEditorPart part) {
074: super .setActiveEditor(part);
075: if (part instanceof DRLRuleEditor2) {
076: DRLRuleEditor2 p = (DRLRuleEditor2) part;
077: p.setZoomComboContributionItem(zitem);
078: p.setZoomInAction(zoomIn);
079: p.setZoomOutAction(zoomOut);
080: }
081: }
082:
083: /**
084: * Adds Zoom-related contributions.
085: *
086: * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(org.eclipse.jface.action.IToolBarManager)
087: */
088: public void contributeToToolBar(IToolBarManager toolBarManager) {
089: super .contributeToToolBar(toolBarManager);
090: toolBarManager.add(new Separator());
091: String[] zoomStrings = new String[] { ZoomManager.FIT_ALL,
092: ZoomManager.FIT_HEIGHT, ZoomManager.FIT_WIDTH };
093:
094: zitem = new ZoomComboContributionItem(getPage(), zoomStrings);
095: zitem.setZoomManager(null);
096: zitem.setVisible(false);
097:
098: zoomIn = new ZoomInAction2();
099: zoomIn.setEnabled(false);
100:
101: zoomOut = new ZoomOutAction2();
102: zoomOut.setEnabled(false);
103:
104: toolBarManager.add(zitem);
105: toolBarManager.add(zoomIn);
106: toolBarManager.add(zoomOut);
107:
108: }
109:
110: }
|