📄 propertysheetpageex.java
字号:
/*******************************************************************************
* $Header: /cvsroot/EOS6/work_dir/niegy/com.primeton.studio.gef.ui/src/com/primeton/studio/gef/ui/properties/PropertySheetPageEx.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-10-26
*******************************************************************************/
package com.primeton.studio.gef.ui.properties;
import java.util.EventObject;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.commands.CommandStackListener;
import org.eclipse.help.IContext;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.HelpEvent;
import org.eclipse.swt.events.HelpListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.ISaveablePart;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.help.IContextComputer;
import org.eclipse.ui.help.IWorkbenchHelpSystem;
import org.eclipse.ui.internal.views.ViewsPlugin;
import org.eclipse.ui.internal.views.properties.PropertiesMessages;
import org.eclipse.ui.part.CellEditorActionHandler;
import org.eclipse.ui.part.Page;
import org.eclipse.ui.views.properties.IPropertySheetEntry;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.IPropertySourceProvider;
import org.eclipse.ui.views.properties.PropertySheetEntry;
/**
* TODO此处填写 class 信息
*
* @author niegy (mailto:niegy@primeton.com)
*/
/*
* 修改历史
* $Log: PropertySheetPageEx.java,v $
* Revision 1.1 2006/11/17 03:15:13 niegy
* create
*
*/
public class PropertySheetPageEx extends Page implements IPropertySheetPage, IAdaptable {
/**
* Help context id
* (value <code>"org.eclipse.ui.property_sheet_page_help_context"</code>).
*/
public static final String HELP_CONTEXT_PROPERTY_SHEET_PAGE = "org.eclipse.ui.property_sheet_page_help_context"; //$NON-NLS-1$
private PropertySheetViewerEx viewer;
private PropertySheetSorterEx sorter;
private IPropertySheetEntry rootEntry;
private IPropertySourceProvider provider;
private DefaultsAction defaultsAction;
private FilterAction filterAction;
private CategoriesAction categoriesAction;
private CopyPropertyAction copyAction;
private ICellEditorActivationListener cellEditorActivationListener;
private CellEditorActionHandler cellEditorActionHandler;
private Clipboard clipboard;
private IWorkbenchPart sourcePart;
/**
*
*/
private MenuManager menuMgr;
private IMenuManager menuManager;
private IToolBarManager toolBarManager;
private RedoAction redoAction;
private UndoAction undoAction;
private IPropertyMenuManager propertyMenuManager;
private CommandStack commandStack;
/**
* Part listener which cleans up this page when the source part is closed.
* This is hooked only when there is a source part.
*
* @since 3.2
*/
private class PartListener implements IPartListener {
public void partActivated(IWorkbenchPart part) {
}
public void partBroughtToTop(IWorkbenchPart part) {
}
public void partClosed(IWorkbenchPart part) {
if (sourcePart == part) {
sourcePart = null;
if (viewer != null && !viewer.getControl().isDisposed()) {
viewer.setInput(new Object[0]);
}
}
}
public void partDeactivated(IWorkbenchPart part) {
}
public void partOpened(IWorkbenchPart part) {
}
}
private PartListener partListener = new PartListener();
/**
* Creates a new property sheet page.
*/
public PropertySheetPageEx() {
super();
}
/* (non-Javadoc)
* Method declared on <code>IPage</code>.
*/
public void createControl(Composite parent) {
// create a new viewer
viewer = new PropertySheetViewerEx(parent);
viewer.setSorter(sorter);
// set the model for the viewer
if (rootEntry == null) {
// create a new root
PropertySheetEntryEx root = new PropertySheetEntryEx();
if (provider != null) {
// set the property source provider
root.setPropertySourceProvider(provider);
}
rootEntry = root;
}
viewer.setRootEntry(rootEntry);
viewer.addActivationListener(getCellEditorActivationListener());
// add a listener to track when the entry selection changes
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
handleEntrySelection(event.getSelection());
}
});
initDragAndDrop();
makeActions();
// Create the popup menu for the page.
if(propertyMenuManager != null)
propertyMenuManager.makeActions(viewer);
menuMgr = new MenuManager("#PopupMenu");
menuMgr.add(copyAction);
menuMgr.add(new Separator());
menuMgr.add(defaultsAction);
if(propertyMenuManager != null)
propertyMenuManager.configPopMenu(menuMgr);
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
////////////////////////////////////////////////
// Set help on the viewer
viewer.getControl().addHelpListener(new HelpListener() {
/*
* @see HelpListener#helpRequested(HelpEvent)
*/
public void helpRequested(HelpEvent e) {
// Get the context for the selected item
IStructuredSelection selection = (IStructuredSelection) viewer
.getSelection();
if (!selection.isEmpty()) {
IPropertySheetEntry entry = (IPropertySheetEntry) selection
.getFirstElement();
Object helpContextId = entry.getHelpContextIds();
if (helpContextId != null) {
if (helpContextId instanceof String) {
getSite().getWorkbenchWindow().getWorkbench()
.getHelpSystem().displayHelp(
(String) helpContextId);
return;
}
// Since 2.0 the only valid type for helpContextIds
// is a String (a single id).
// However for backward compatibility we have to handle
// and array of contexts (Strings and/or IContexts)
// or a context computer.
Object[] contexts = null;
if (helpContextId instanceof IContextComputer) {
// get local contexts
contexts = ((IContextComputer) helpContextId)
.getLocalContexts(e);
} else {
contexts = (Object[]) helpContextId;
}
IWorkbenchHelpSystem help = getSite().getWorkbenchWindow().getWorkbench().getHelpSystem();
// Ignore all but the first element in the array
if (contexts[0] instanceof IContext) {
help.displayHelp((IContext) contexts[0]);
} else {
help.displayHelp((String) contexts[0]);
}
return;
}
}
// No help for the selection so show page help
getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().displayHelp(HELP_CONTEXT_PROPERTY_SHEET_PAGE);
}
});
}
/**
* The <code>PropertySheetPage</code> implementation of this <code>IPage</code> method
* disposes of this page's entries.
*/
public void dispose() {
super.dispose();
if (sourcePart != null) {
sourcePart.getSite().getPage().removePartListener(partListener);
}
if (rootEntry != null) {
rootEntry.dispose();
rootEntry = null;
}
if (clipboard != null) {
clipboard.dispose();
clipboard = null;
}
}
/**
* The <code>PropertySheetPage</code> implementation of this <code>IAdaptable</code> method
* handles the <code>ISaveablePart</code> adapter by delegating to the source part.
*
* @since 3.2
*/
public Object getAdapter(Class adapter) {
if (ISaveablePart.class.equals(adapter)) {
return getSaveablePart();
}
return null;
}
/**
* Returns an <code>ISaveablePart</code> that delegates to the source part
* for the current page if it implements <code>ISaveablePart</code>, or
* <code>null</code> otherwise.
*
* @return an <code>ISaveablePart</code> or <code>null</code>
* @since 3.2
*/
protected ISaveablePart getSaveablePart() {
if (sourcePart instanceof ISaveablePart) {
return (ISaveablePart) sourcePart;
}
return null;
}
/**
* Returns the cell editor activation listener for this page
* @return ICellEditorActivationListener the cell editor activation listener for this page
*/
private ICellEditorActivationListener getCellEditorActivationListener() {
if (cellEditorActivationListener == null) {
cellEditorActivationListener = new ICellEditorActivationListener() {
public void cellEditorActivated(CellEditor cellEditor) {
disableUndoRedoAction();
if (cellEditorActionHandler != null) {
cellEditorActionHandler.addCellEditor(cellEditor);
}
}
public void cellEditorDeactivated(CellEditor cellEditor) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -