📄 propertysheetpageex.java
字号:
refreshUndoRedoAction();
if (cellEditorActionHandler != null) {
cellEditorActionHandler.removeCellEditor(cellEditor);
}
}
};
}
return cellEditorActivationListener;
}
/* (non-Javadoc)
* Method declared on IPage (and Page).
*/
public Control getControl() {
if (viewer == null) {
return null;
}
return viewer.getControl();
}
/**
* Handles a selection change in the entry table.
*
* @param selection the new selection
*/
public void handleEntrySelection(ISelection selection) {
if(propertyMenuManager != null)
propertyMenuManager.handleEntrySelection(menuMgr, toolBarManager, viewer, selection);
toolBarManager.update(true);
menuMgr.update(true);
if (defaultsAction != null) {
if (selection.isEmpty()) {
defaultsAction.setEnabled(false);
return;
}
// see if item is editable
boolean editable = viewer.getActiveCellEditor() != null;
defaultsAction.setEnabled(editable);
}
}
/**
* Adds drag and drop support.
*/
protected void initDragAndDrop() {
int operations = DND.DROP_COPY;
Transfer[] transferTypes = new Transfer[] { TextTransfer.getInstance() };
DragSourceListener listener = new DragSourceAdapter() {
public void dragSetData(DragSourceEvent event) {
performDragSetData(event);
}
public void dragFinished(DragSourceEvent event) {
//Nothing to do here
}
};
DragSource dragSource = new DragSource(
viewer.getControl(), operations);
dragSource.setTransfer(transferTypes);
dragSource.addDragListener(listener);
}
/**
* The user is attempting to drag. Add the appropriate
* data to the event.
* @param event The event sent from the drag and drop support.
*/
void performDragSetData(DragSourceEvent event) {
// Get the selected property
IStructuredSelection selection = (IStructuredSelection) viewer
.getSelection();
if (selection.isEmpty()) {
return;
}
// Assume single selection
IPropertySheetEntry entry = (IPropertySheetEntry) selection
.getFirstElement();
// Place text as the data
StringBuffer buffer = new StringBuffer();
buffer.append(entry.getDisplayName());
buffer.append("\t"); //$NON-NLS-1$
buffer.append(entry.getValueAsString());
event.data = buffer.toString();
}
/**
* Make action objects.
*/
private void makeActions() {
ISharedImages sharedImages = PlatformUI.getWorkbench()
.getSharedImages();
// Restore Default Value
defaultsAction = new DefaultsAction(viewer, "defaults"); //$NON-NLS-1$
defaultsAction.setText(PropertiesMessages.Defaults_text);
defaultsAction.setToolTipText(PropertiesMessages.Defaults_toolTip);
defaultsAction
.setImageDescriptor(ViewsPlugin.getViewImageDescriptor("elcl16/defaults_ps.gif")); //$NON-NLS-1$
defaultsAction
.setDisabledImageDescriptor(ViewsPlugin.getViewImageDescriptor("dlcl16/defaults_ps.gif")); //$NON-NLS-1$
defaultsAction.setEnabled(false);
// Show Advanced Properties
filterAction = new FilterAction(viewer, "filter"); //$NON-NLS-1$
filterAction.setText(PropertiesMessages.Filter_text);
filterAction.setToolTipText(PropertiesMessages.Filter_toolTip);
filterAction
.setImageDescriptor(ViewsPlugin.getViewImageDescriptor("elcl16/filter_ps.gif")); //$NON-NLS-1$
filterAction.setChecked(false);
// Show Categories
categoriesAction = new CategoriesAction(viewer, "categories"); //$NON-NLS-1$
categoriesAction.setText(PropertiesMessages.Categories_text);
categoriesAction.setToolTipText(PropertiesMessages.Categories_toolTip);
categoriesAction
.setImageDescriptor(ViewsPlugin.getViewImageDescriptor("elcl16/tree_mode.gif")); //$NON-NLS-1$
categoriesAction.setChecked(true);
// Copy
Shell shell = viewer.getControl().getShell();
clipboard = new Clipboard(shell.getDisplay());
copyAction = new CopyPropertyAction(viewer, "copy", clipboard); //$NON-NLS-1$
copyAction.setText(PropertiesMessages.CopyProperty_text);
copyAction.setImageDescriptor(sharedImages
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
}
/* (non-Javadoc)
* Method declared on IPage (and Page).
*/
public void makeContributions(IMenuManager menuManager,
IToolBarManager toolBarManager, IStatusLineManager statusLineManager) {
// add actions to the tool bar
toolBarManager.add(categoriesAction);
toolBarManager.add(filterAction);
toolBarManager.add(defaultsAction);
// add actions to the menu
menuManager.add(categoriesAction);
menuManager.add(filterAction);
this.menuManager = menuManager;
this.toolBarManager = toolBarManager;
if(propertyMenuManager != null)
propertyMenuManager.makeContributions(menuManager, toolBarManager);
// set status line manager into the viewer
viewer.setStatusLineManager(statusLineManager);
}
/**
* Updates the model for the viewer.
* <p>
* Note that this means ensuring that the model reflects the state
* of the current viewer input.
* </p>
*/
public void refresh() {
if (viewer == null) {
return;
}
// calling setInput on the viewer will cause the model to refresh
viewer.setInput(viewer.getInput());
}
/* (non-Javadoc)
* Method declared on ISelectionListener.
*/
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (viewer == null) {
return;
}
if (sourcePart != null) {
sourcePart.getSite().getPage().removePartListener(partListener);
sourcePart = null;
}
// change the viewer input since the workbench selection has changed.
if (selection instanceof IStructuredSelection) {
sourcePart = part;
viewer.setInput(((IStructuredSelection) selection).toArray());
}
if (sourcePart != null) {
sourcePart.getSite().getPage().addPartListener(partListener);
}
}
/**
* The <code>PropertySheetPage</code> implementation of this <code>IPage</code> method
* calls <code>makeContributions</code> for backwards compatibility with
* previous versions of <code>IPage</code>.
* <p>
* Subclasses may reimplement.
* </p>
*/
public void setActionBars(IActionBars actionBars) {
super.setActionBars(actionBars);
cellEditorActionHandler = new CellEditorActionHandler(actionBars);
cellEditorActionHandler.setCopyAction(copyAction);
redoAction = new RedoAction(commandStack);
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
undoAction = new UndoAction(commandStack);
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
undoAction.refresh();
redoAction.refresh();
commandStack.addCommandStackListener(new CommandStackListener() {
public void commandStackChanged(EventObject event)
{
refreshUndoRedoAction();
}
});
}
/**
* Sets focus to a part in the page.
*/
public void setFocus() {
viewer.getControl().setFocus();
}
/**
* Sets the given property source provider as
* the property source provider.
* <p>
* Calling this method is only valid if you are using
* this page's default root entry.
* </p>
* @param newProvider the property source provider
*/
public void setPropertySourceProvider(IPropertySourceProvider newProvider) {
provider = newProvider;
if (rootEntry instanceof PropertySheetEntry) {
((PropertySheetEntry) rootEntry)
.setPropertySourceProvider(provider);
// the following will trigger an update
viewer.setRootEntry(rootEntry);
}
}
/**
* Sets the given entry as the model for the page.
*
* @param entry the root entry
*/
public void setRootEntry(IPropertySheetEntry entry) {
rootEntry = entry;
if (viewer != null) {
// the following will trigger an update
viewer.setRootEntry(rootEntry);
}
}
/**
* Sets the sorter used for sorting categories and entries in the viewer
* of this page.
* <p>
* The default sorter sorts categories and entries alphabetically.
* </p>
* @param sorter the sorter to set (<code>null</code> will reset to the
* default sorter)
* @since 3.1
*/
protected void setSorter(PropertySheetSorterEx sorter) {
this.sorter = sorter;
if (viewer != null) {
viewer.setSorter(sorter);
// the following will trigger an update
if(null != viewer.getRootEntry()) {
viewer.setRootEntry(rootEntry);
}
}
}
void refreshUndoRedoAction()
{
undoAction.refresh();
redoAction.refresh();
}
void disableUndoRedoAction()
{
undoAction.setEnabled(false);
redoAction.setEnabled(false);
}
public void setPropertyMenuManager(IPropertyMenuManager propertyMenuMgr)
{
propertyMenuManager = propertyMenuMgr;
}
public IPropertyMenuManager getPropertyMenuManager()
{
return propertyMenuManager;
}
public void setCommandStack(CommandStack cmdStack)
{
commandStack = cmdStack;
}
public CommandStack getCommandStack()
{
return commandStack;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -