📄 outlinepage.java
字号:
/*******************************************************************************
* $Header: /cvsroot/EOS6/work_dir/niegy/com.primeton.studio.gef.ui/src/com/primeton/studio/gef/ui/editor/OutlinePage.java,v 1.1 2006/11/17 03:15:13 niegy Exp $
* $Revision: 1.1 $
* $Date: 2006/11/17 03:15:13 $
*
*==============================================================================
*
* Copyright (c) 2001-2006 Primeton Technologies, Ltd.
* All rights reserved.
*
* Created on 2006-9-27
*******************************************************************************/
package com.primeton.studio.gef.ui.editor;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.Viewport;
import org.eclipse.draw2d.parts.ScrollableThumbnail;
import org.eclipse.draw2d.parts.Thumbnail;
import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.parts.ContentOutlinePage;
import org.eclipse.gef.ui.parts.TreeViewer;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.part.IPageSite;
import org.eclipse.ui.part.PageBook;
import com.primeton.studio.gef.ui.GefUiPluginImages;
/**
* TODO此处填写 class 信息
*
* @author niegy (mailto:niegy@primeton.com)
*/
/*
* 修改历史
* $Log: OutlinePage.java,v $
* Revision 1.1 2006/11/17 03:15:13 niegy
* create
*
*/
public class OutlinePage extends ContentOutlinePage implements IAdaptable {
private static final int ID_OUTLINE = 0;
private static final int ID_OVERVIEW = 1;
private PageBook pageBook;
private Control outline;
private Canvas overview;
private Thumbnail thumbnail;
private IAction showOutlineAction;
private IAction showOverviewAction;
private AbstractGraphicalEditor fEditor;
private EditPartFactory fEditPartFactory;
private ContextMenuProvider fContextMenuProvider;
private Object fModel;
public OutlinePage(AbstractGraphicalEditor editor,EditPartFactory editPartFactory,
ContextMenuProvider contextMenuProvider,Object model) {
super(new TreeViewer());
fEditor = editor;
fEditPartFactory = editPartFactory;
fContextMenuProvider = contextMenuProvider;
fModel = model;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class type) {
if (type == ZoomManager.class) {
return fEditor.getAdapter(type);
} else {
return null;
}
}
public void createControl(Composite parent) {
this.pageBook = new PageBook(parent, SWT.NONE);
this.outline = getViewer().createControl(pageBook);
this.overview = new Canvas(pageBook, SWT.NONE);
this.pageBook.showPage(outline);
configureOutlineViewer();
hookOutlineViewer();
initializeOutlineViewer();
}
protected void configureOutlineViewer() {
getViewer().setEditDomain(fEditor.getEditDomain());
getViewer().setEditPartFactory(fEditPartFactory);
getViewer().setContextMenu(fContextMenuProvider);
getSite().registerContextMenu(
"com.primeton.studio.gef.ui.outline.contextmenu", //$NON-NLS-1$
fContextMenuProvider, getSite().getSelectionProvider());
IToolBarManager tbm = getSite().getActionBars().getToolBarManager();
showOutlineAction = new Action() {
public void run() {
showPage(ID_OUTLINE);
}
};
showOutlineAction.setImageDescriptor(GefUiPluginImages.GEF_OUTLINE);
tbm.add(showOutlineAction);
showOverviewAction = new Action() {
public void run() {
showPage(ID_OVERVIEW);
}
};
showOverviewAction.setImageDescriptor(GefUiPluginImages.GEF_OVERVIEW);
tbm.add(showOverviewAction);
showPage(ID_OUTLINE);
}
protected void hookOutlineViewer() {
fEditor.getSelectionSynchronizer().addViewer(getViewer());
}
public void initializeOutlineViewer() {
getViewer().setContents(fModel);
}
protected void initializeOverview() {
LightweightSystem lightweightSystem = new LightweightSystem(
overview);
RootEditPart rootEditPart = fEditor.getRootEditPart();
if (rootEditPart instanceof ScalableFreeformRootEditPart) {
ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rootEditPart;
this.thumbnail = new ScrollableThumbnail((Viewport) root
.getFigure());
this.thumbnail.setBorder(new MarginBorder(3));
this.thumbnail.setSource(root
.getLayer(LayerConstants.PRINTABLE_LAYERS));
lightweightSystem.setContents(this.thumbnail);
}
}
protected void showPage(int id) {
if (id == ID_OUTLINE) {
showOutlineAction.setChecked(true);
showOverviewAction.setChecked(false);
pageBook.showPage(outline);
if (thumbnail != null)
thumbnail.setVisible(false);
} else if (id == ID_OVERVIEW) {
if (thumbnail == null)
initializeOverview();
showOutlineAction.setChecked(false);
showOverviewAction.setChecked(true);
pageBook.showPage(overview);
thumbnail.setVisible(true);
}
}
protected void unhookOutlineViewer() {
fEditor.getSelectionSynchronizer().removeViewer(getViewer());
}
public void dispose() {
unhookOutlineViewer();
if (this.thumbnail != null)
this.thumbnail.deactivate();
super.dispose();
}
public Control getControl() {
return this.pageBook;
}
public void init(IPageSite pageSite) {
super.init(pageSite);
ActionRegistry registry = fEditor.getActionRegistry();
IActionBars bars = pageSite.getActionBars();
String id = ActionFactory.UNDO.getId();
bars.setGlobalActionHandler(id, registry.getAction(id));
id = ActionFactory.REDO.getId();
bars.setGlobalActionHandler(id, registry.getAction(id));
id = ActionFactory.DELETE.getId();
bars.setGlobalActionHandler(id, registry.getAction(id));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -