public abstract class ContentMergeViewer extends ContentViewer implements IPropertyChangeNotifier, IFlushable, org.eclipse.compare.internal.IFlushable2
ContentMergeViewer
ContentMergeViewer
accesses its
model by means of a content provider which must implement the
IMergeViewerContentProvider
interface.
Clients may wish to use the standard concrete subclass TextMergeViewer
,
or define their own subclass.
IMergeViewerContentProvider
,
TextMergeViewer
WIDGET_DATA_KEY
Modifier | Constructor and Description |
---|---|
protected |
ContentMergeViewer(int style,
ResourceBundle bundle,
CompareConfiguration cc)
Creates a new content merge viewer and initializes with a resource bundle and a
configuration.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(IPropertyChangeListener listener)
Adds a listener for property changes to this notifier.
|
protected Control |
buildControl(Composite parent)
Builds the SWT controls for the three areas of a compare/merge viewer.
|
protected abstract void |
copy(boolean leftToRight)
Copies the content of one side to the other side.
|
protected Control |
createCenterControl(Composite parent)
Create the control that divides the left and right sides of the merge viewer.
|
protected abstract void |
createControls(Composite composite)
Creates the SWT controls for the ancestor, left, and right
content areas of this compare viewer.
|
protected void |
createToolItems(ToolBarManager toolBarManager)
Contributes items to the given
ToolBarManager . |
protected boolean |
doSave(Object newInput,
Object oldInput)
This method is called from the
Viewer method inputChanged
to save any unsaved changes of the old input. |
void |
flush(IProgressMonitor monitor)
Flush any modifications made in the viewer into the compare input.
|
protected void |
flushContent(Object input,
IProgressMonitor monitor)
Flush the modified content back to input elements via the content provider.
|
void |
flushLeft(IProgressMonitor monitor) |
void |
flushRight(IProgressMonitor monitor) |
protected Control |
getCenterControl()
Return the center control that divides the left and right sides of the merge viewer.
|
protected int |
getCenterWidth()
Return the desired width of the center control.
|
protected CompareConfiguration |
getCompareConfiguration()
Returns the compare configuration of this viewer,
or
null if this viewer does not yet have a configuration. |
protected abstract byte[] |
getContents(boolean left)
Returns the byte contents of the left or right side.
|
Control |
getControl()
Returns the primary control associated with this viewer.
|
protected ResourceBundle |
getResourceBundle()
Returns the resource bundle of this viewer.
|
ISelection |
getSelection()
The
ContentMergeViewer implementation of this
Viewer method returns the empty selection. |
String |
getTitle()
Returns the viewer's name.
|
protected IToolBarManager |
getToolBarManager(Composite parent)
Returns the toolbar manager for this viewer.
|
protected void |
handleCompareInputChange()
Handle a change to the given input reported from an
ICompareInputChangeListener . |
protected void |
handleDispose(DisposeEvent event)
Called on the viewer disposal.
|
protected void |
handlePropertyChangeEvent(PropertyChangeEvent event)
Callback that is invoked when a property in the compare configuration
(
getCompareConfiguration() changes. |
protected abstract void |
handleResizeAncestor(int x,
int y,
int width,
int height)
Lays out the ancestor area of the compare viewer.
|
protected abstract void |
handleResizeLeftRight(int x,
int y,
int leftWidth,
int centerWidth,
int rightWidth,
int height)
Lays out the left and right areas of the compare viewer.
|
protected boolean |
handleSetFocus()
Callback that is invoked when the control of this merge viewer is given focus.
|
protected void |
inputChanged(Object input,
Object oldInput)
Internal hook method called when the input to this viewer is
initially set or subsequently changed.
|
boolean |
internalIsLeftDirty() |
boolean |
internalIsRightDirty() |
protected boolean |
isAncestorVisible()
Return whether the ancestor pane is visible or not.
|
protected boolean |
isLeftDirty()
Return the dirty state of the left side of this viewer.
|
protected boolean |
isRightDirty()
Return the dirty state of the right side of this viewer.
|
protected boolean |
isThreeWay()
Return whether the input is a three-way comparison.
|
void |
refresh()
Refreshes this viewer completely with information freshly obtained from this
viewer's model.
|
void |
removePropertyChangeListener(IPropertyChangeListener listener)
Removes the given content change listener from this notifier.
|
void |
save(IProgressMonitor monitor)
Deprecated.
|
void |
setConfirmSave(boolean enable)
Controls whether
doSave(Object, Object) asks for confirmation before saving
the old input with saveContent(Object) . |
void |
setContentProvider(IContentProvider contentProvider)
The
ContentMergeViewer implementation of this
ContentViewer method
checks to ensure that the content provider is an IMergeViewerContentProvider . |
protected void |
setLeftDirty(boolean dirty)
Sets the dirty state of the left side of this viewer.
|
protected void |
setRightDirty(boolean dirty)
Sets the dirty state of the right side of this viewer.
|
void |
setSelection(ISelection selection,
boolean reveal)
The
ContentMergeViewer implementation of this
Viewer method does nothing. |
protected abstract void |
updateContent(Object ancestor,
Object left,
Object right)
Initializes the controls of the three content areas with the given input objects.
|
protected void |
updateHeader()
Updates the headers of the three areas
by querying the content provider for a name and image for
the three sides of the input object.
|
protected void |
updateToolItems()
Updates the enabled state of the toolbar items.
|
getContentProvider, getInput, getLabelProvider, handleLabelProviderChanged, hookControl, labelProviderChanged, setInput, setLabelProvider
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelection
protected ContentMergeViewer(int style, ResourceBundle bundle, CompareConfiguration cc)
style
- SWT style bitsbundle
- the resource bundlecc
- the configuration objectpublic String getTitle()
protected abstract void createControls(Composite composite)
updateContent
.composite
- the container for the three areasprotected abstract void handleResizeAncestor(int x, int y, int width, int height)
x
- the horizontal position of the ancestor area within its containery
- the vertical position of the ancestor area within its containerwidth
- the width of the ancestor areaheight
- the height of the ancestor areaprotected abstract void handleResizeLeftRight(int x, int y, int leftWidth, int centerWidth, int rightWidth, int height)
x
- the horizontal position of the left area within its containery
- the vertical position of the left and right area within its containerleftWidth
- the width of the left areacenterWidth
- the width of the gap between the left and right areasrightWidth
- the width of the right areaheight
- the height of the left and right areasprotected void createToolItems(ToolBarManager toolBarManager)
ToolBarManager
.
It is called when this viewer is installed in its container and if the container
has a ToolBarManager
.
The ContentMergeViewer
implementation of this method does nothing.
Subclasses may reimplement.toolBarManager
- the toolbar manager to contribute toprotected abstract void updateContent(Object ancestor, Object left, Object right)
ancestor
- the input for the ancestor arealeft
- the input for the left arearight
- the input for the right areaprotected abstract void copy(boolean leftToRight)
leftToRight
- if true
, the left side is copied to the right side;
if false
, the right side is copied to the left sideprotected abstract byte[] getContents(boolean left)
null
can be returned.left
- if true
, the byte contents of the left area is returned;
if false
, the byte contents of the right areanull
protected ResourceBundle getResourceBundle()
protected CompareConfiguration getCompareConfiguration()
null
if this viewer does not yet have a configuration.null
if nonepublic void setContentProvider(IContentProvider contentProvider)
ContentMergeViewer
implementation of this
ContentViewer
method
checks to ensure that the content provider is an IMergeViewerContentProvider
.setContentProvider
in class ContentViewer
contentProvider
- the content provider to set. Must implement IMergeViewerContentProvider.ContentViewer.getContentProvider()
public ISelection getSelection()
ContentMergeViewer
implementation of this
Viewer
method returns the empty selection. Subclasses may override.getSelection
in interface ISelectionProvider
getSelection
in class Viewer
public void setSelection(ISelection selection, boolean reveal)
ContentMergeViewer
implementation of this
Viewer
method does nothing. Subclasses may reimplement.setSelection
in class Viewer
selection
- the new selectionreveal
- true
if the selection is to be made
visible, and false
otherwiseViewer.setSelection(org.eclipse.jface.viewers.ISelection, boolean)
protected void handlePropertyChangeEvent(PropertyChangeEvent event)
getCompareConfiguration()
changes.event
- the property change eventprotected boolean isThreeWay()
protected final void inputChanged(Object input, Object oldInput)
The ContentMergeViewer
implementation of this Viewer
method tries to save the old input by calling doSave(...)
and
then calls internalRefresh(...)
.
inputChanged
in class Viewer
input
- the new input of this viewer, or null
if there is no new inputoldInput
- the old input element, or null
if there was previously no inputprotected boolean doSave(Object newInput, Object oldInput)
Viewer
method inputChanged
to save any unsaved changes of the old input.
The ContentMergeViewer
implementation of this
method calls saveContent(...)
. If confirmation has been turned on
with setConfirmSave(true)
, a confirmation alert is posted before saving.
newInput
- the new input of this viewer, or null
if there is no new inputoldInput
- the old input element, or null
if there was previously no inputtrue
if saving was successful, or if the user didn't want to save (by pressing 'NO' in the confirmation dialog).public void setConfirmSave(boolean enable)
doSave(Object, Object)
asks for confirmation before saving
the old input with saveContent(Object)
.enable
- a value of true
enables confirmationpublic void refresh()
Viewer
protected final Control buildControl(Composite parent)
Calls the hooks createControls
and createToolItems
to let subclasses build the specific content areas and to add items to
an enclosing toolbar.
This method must only be called in the constructor of subclasses.
parent
- the parent controlprotected IToolBarManager getToolBarManager(Composite parent)
parent
- a Composite
or null
IToolBarManager
protected boolean handleSetFocus()
true
if a particular widget was given focus
and false otherwise. By default, false
is returned. Subclasses may override.protected int getCenterWidth()
handleResizeLeftRight(int, int, int, int, int, int)
,
handleResizeAncestor(int, int, int, int)
protected boolean isAncestorVisible()
protected Control createCenterControl(Composite parent)
parent
- the parent compositeprotected Control getCenterControl()
createCenterControl(Composite)
.createCenterControl(Composite)
public Control getControl()
Viewer
getControl
in class Viewer
protected void handleDispose(DisposeEvent event)
handleDispose
in class ContentViewer
event
- a dispose eventContentViewer.handleDispose(org.eclipse.swt.events.DisposeEvent)
protected void updateToolItems()
This method is called whenever the state of the items needs updating.
Subclasses may extend this method, although this is generally not required.
protected void updateHeader()
This method is called whenever the header must be updated.
Subclasses may extend this method, although this is generally not required.
public void addPropertyChangeListener(IPropertyChangeListener listener)
IPropertyChangeNotifier
addPropertyChangeListener
in interface IPropertyChangeNotifier
listener
- a property change listenerpublic void removePropertyChangeListener(IPropertyChangeListener listener)
IPropertyChangeNotifier
removePropertyChangeListener
in interface IPropertyChangeNotifier
listener
- a property change listenerprotected void setLeftDirty(boolean dirty)
PropertyChangeEvent
with the
property name CompareEditorInput.DIRTY_STATE
.dirty
- the state of the left side dirty flagprotected void setRightDirty(boolean dirty)
PropertyChangeEvent
with the
property name CompareEditorInput.DIRTY_STATE
.dirty
- the state of the right side dirty flagpublic void save(IProgressMonitor monitor) throws CoreException
IFlushable.flush(IProgressMonitor)
.ISavable
interface
Save the viewers's content.
Note: this method is for internal use only. Clients should not call this method.monitor
- a progress monitorCoreException
public final void flush(IProgressMonitor monitor)
flushContent(Object, IProgressMonitor)
with the compare input
of the viewer as the first parameter.flush
in interface IFlushable
monitor
- a progress monitorIFlushable.flush(org.eclipse.core.runtime.IProgressMonitor)
protected void flushContent(Object input, IProgressMonitor monitor)
input
- the compare inputmonitor
- a progress monitor or null
if the method
was call from a place where a progress monitor was not available.public void flushLeft(IProgressMonitor monitor)
flushLeft
in interface org.eclipse.compare.internal.IFlushable2
monitor
- public void flushRight(IProgressMonitor monitor)
flushRight
in interface org.eclipse.compare.internal.IFlushable2
monitor
- protected boolean isRightDirty()
public boolean internalIsRightDirty()
protected boolean isLeftDirty()
public boolean internalIsLeftDirty()
protected void handleCompareInputChange()
ICompareInputChangeListener
.
This class registers a listener with its input and reports any change events through
this method. By default, this method prompts for any unsaved changes and then refreshes
the viewer. Subclasses may override.
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.