|
|||||||||
| Home >> All >> org >> eclipse >> [ compare overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.eclipse.compare
Class CompareEditorInput

java.lang.Objectorg.eclipse.compare.CompareEditorInput
- All Implemented Interfaces:
- org.eclipse.core.runtime.IAdaptable, org.eclipse.ui.IEditorInput, IPropertyChangeNotifier, org.eclipse.jface.operation.IRunnableWithProgress
- public abstract class CompareEditorInput
- extends java.lang.Object
- implements org.eclipse.ui.IEditorInput, IPropertyChangeNotifier, org.eclipse.jface.operation.IRunnableWithProgress
- extends java.lang.Object
A compare operation which can present its results in a special editor. Running the compare operation and presentating the results in a compare editor are combined in one class because it allows a client to keep the implementation all in one place while separating it from the innards of a specific UI implementation of compare/merge.
A CompareEditorInput defines methods for the following sequence steps:
- running a lengthy compare operation under progress monitor control,
- creating a UI for displaying the model and initializing the some widgets with the compare result,
- tracking the dirty state of the model in case of merge,
- saving the model.
openCompareEditor method takes an ICompareEditorInput
and starts sequencing through the above steps. If the compare result is not empty a new compare editor
is opened and takes over the sequence until eventually closed.
The prepareInput method should contain the
code of the compare operation. It is executed under control of a progress monitor
and can be canceled. If the result of the compare is not empty, that is if there are differences
that needs to be presented, the ICompareEditorInput should hold onto them and return them with
the getCompareResult method.
If the value returned from getCompareResult is not null
a compare editor is opened on the ICompareEditorInput with title and title image initialized by the
corresponding methods of the ICompareEditorInput.
Creation of the editor's SWT controls is delegated to the createContents method.
Here the SWT controls must be created and initialized with the result of the compare operation.
If merging is allowed, the modification state of the compared constituents must be tracked and the dirty
state returned from method isSaveNeeded. The value true triggers a subsequent call
to save where the modified resources can be saved.
The most important part of this implementation is the setup of the compare/merge UI. The UI uses a simple browser metaphor to present compare results. The top half of the layout shows the structural compare results (e.g. added, deleted, and changed files), the bottom half the content compare results (e.g. textual differences between two files). A selection in the top pane is fed to the bottom pane. If a content viewer is registered for the type of the selected object, this viewer is installed in the pane. In addition if a structure viewer is registered for the selection type the top pane is split horizontally to make room for another pane and the structure viewer is installed in it. When comparing Java files this second structure viewer would show the structural differences within a Java file, e.g. added, deleted or changed methods and fields.
Subclasses provide custom setups, e.g. for a Catchup/Release operation
by passing a subclass of CompareConfiguration and by implementing the prepareInput method.
If a subclass cannot use the DiffTreeViewer which is installed by default in the
top left pane, method createDiffViewer can be overridden.
| Constructor Summary | |
CompareEditorInput(CompareConfiguration configuration)
Creates a CompareEditorInput which is initialized with the given
compare configuration. |
|
| Method Summary | |
void |
addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
Adds a listener for property changes to this notifier. |
void |
contributeToToolBar(org.eclipse.jface.action.ToolBarManager toolBarManager)
Adds standard actions to the given ToolBarManager. |
org.eclipse.swt.widgets.Control |
createContents(org.eclipse.swt.widgets.Composite parent)
Create the SWT controls that are used to display the result of the compare operation. |
org.eclipse.jface.viewers.Viewer |
createDiffViewer(org.eclipse.swt.widgets.Composite parent)
Factory method for creating a differences viewer for the top left pane. |
org.eclipse.swt.widgets.Control |
createOutlineContents(org.eclipse.swt.widgets.Composite parent,
int direction)
|
boolean |
exists()
Returns false to indicate that this input
should not appear in the "File Most Recently Used" menu. |
private void |
feed1(org.eclipse.jface.viewers.ISelection selection)
|
private void |
feed2(org.eclipse.jface.viewers.ISelection selection)
|
private void |
feed3(org.eclipse.jface.viewers.ISelection selection)
|
private void |
feedDefault1(org.eclipse.jface.viewers.ISelection selection)
|
org.eclipse.jface.viewers.Viewer |
findContentViewer(org.eclipse.jface.viewers.Viewer oldViewer,
org.eclipse.compare.structuremergeviewer.ICompareInput input,
org.eclipse.swt.widgets.Composite parent)
Implements the dynamic viewer switching for content viewers. |
org.eclipse.jface.viewers.Viewer |
findStructureViewer(org.eclipse.jface.viewers.Viewer oldViewer,
org.eclipse.compare.structuremergeviewer.ICompareInput input,
org.eclipse.swt.widgets.Composite parent)
Implements the dynamic viewer switching for structure viewers. |
private static void |
flushViewer(CompareViewerSwitchingPane pane,
org.eclipse.core.runtime.IProgressMonitor pm)
|
java.lang.Object |
getAdapter(java.lang.Class adapter)
Returns an object which is an instance of the given class associated with this object. |
CompareConfiguration |
getCompareConfiguration()
Returns the configuration object for the viewers within the compare editor. |
java.lang.Object |
getCompareResult()
Returns the compare result computed by the most recent call to the run method. |
private static java.lang.Object |
getElement(org.eclipse.jface.viewers.ISelection selection)
Returns the first element of the given selection if the selection is a IStructuredSelection with exactly one element. |
org.eclipse.jface.resource.ImageDescriptor |
getImageDescriptor()
Returns the image descriptor for this input. |
java.lang.String |
getMessage()
|
java.lang.String |
getName()
Returns the name of this editor input for display purposes. |
org.eclipse.ui.IPersistableElement |
getPersistable()
Returns null since this editor cannot be persisted. |
java.lang.String |
getTitle()
Returns the title which will be used in the compare editor's title bar. |
org.eclipse.swt.graphics.Image |
getTitleImage()
Returns the title image which will be used in the compare editor's title bar. |
java.lang.String |
getToolTipText()
Returns the tool tip text for this editor input. |
boolean |
isSaveNeeded()
Returns true if there are unsaved changes. |
protected abstract java.lang.Object |
prepareInput(org.eclipse.core.runtime.IProgressMonitor monitor)
Runs the compare operation and returns the compare result. |
void |
removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
Removes the given content change listener from this notifier. |
void |
run(org.eclipse.core.runtime.IProgressMonitor monitor)
Runs the compare operation and stores the compare result. |
void |
save(org.eclipse.core.runtime.IProgressMonitor pm)
Deprecated. Override method saveChanges instead. |
void |
saveChanges(org.eclipse.core.runtime.IProgressMonitor pm)
Save any unsaved changes. |
void |
setDirty(boolean dirty)
Sets the dirty state of this input to the given value and sends out a PropertyChangeEvent if the new value differs from the old value. |
private void |
setDirty(java.lang.Object source,
boolean dirty)
|
void |
setFocus()
Asks this input to take focus within its container (editor). |
protected void |
setMessage(java.lang.String message)
|
void |
setTitle(java.lang.String title)
Sets the title which will be used when presenting the compare result. |
private boolean |
structureCompareOnSingleClick()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
DIRTY_STATE
public static final java.lang.String DIRTY_STATE
- The name of the "dirty" property (value
"DIRTY_STATE").- See Also:
- Constant Field Values
COMPARE_EDITOR_IMAGE_NAME
private static final java.lang.String COMPARE_EDITOR_IMAGE_NAME
- See Also:
- Constant Field Values
fgTitleImage
private static org.eclipse.swt.graphics.Image fgTitleImage
fComposite
private Splitter fComposite
fCompareConfiguration
private CompareConfiguration fCompareConfiguration
fStructureInputPane
private CompareViewerSwitchingPane fStructureInputPane
fStructurePane1
private CompareViewerSwitchingPane fStructurePane1
fStructurePane2
private CompareViewerSwitchingPane fStructurePane2
fContentInputPane
private CompareViewerSwitchingPane fContentInputPane
fFocusPane
private CompareViewerSwitchingPane fFocusPane
fMessage
private java.lang.String fMessage
fInput
private java.lang.Object fInput
fTitle
private java.lang.String fTitle
fListenerList
private org.eclipse.jface.util.ListenerList fListenerList
fNavigator
private org.eclipse.compare.internal.CompareNavigator fNavigator
fDirty
private boolean fDirty
fDirtyViewers
private java.util.ArrayList fDirtyViewers
fDirtyStateListener
private org.eclipse.jface.util.IPropertyChangeListener fDirtyStateListener
fIgnoreWhitespace
private org.eclipse.compare.internal.IgnoreWhiteSpaceAction fIgnoreWhitespace
fShowPseudoConflicts
private org.eclipse.compare.internal.ShowPseudoConflicts fShowPseudoConflicts
fStructureCompareOnSingleClick
boolean fStructureCompareOnSingleClick
fUseOutlineView
boolean fUseOutlineView
| Constructor Detail |
CompareEditorInput
public CompareEditorInput(CompareConfiguration configuration)
- Creates a
CompareEditorInputwhich is initialized with the given compare configuration. The compare configuration is passed to subsequently created viewers.
| Method Detail |
structureCompareOnSingleClick
private boolean structureCompareOnSingleClick()
getAdapter
public java.lang.Object getAdapter(java.lang.Class adapter)
- Description copied from interface:
org.eclipse.core.runtime.IAdaptable - Returns an object which is an instance of the given class
associated with this object. Returns
nullif no such object can be found.- Specified by:
getAdapterin interfaceorg.eclipse.core.runtime.IAdaptable
getImageDescriptor
public org.eclipse.jface.resource.ImageDescriptor getImageDescriptor()
- Description copied from interface:
org.eclipse.ui.IEditorInput - Returns the image descriptor for this input.
- Specified by:
getImageDescriptorin interfaceorg.eclipse.ui.IEditorInput
getToolTipText
public java.lang.String getToolTipText()
- Description copied from interface:
org.eclipse.ui.IEditorInput - Returns the tool tip text for this editor input. This text
is used to differentiate between two input with the same name.
For instance, MyClass.java in folder X and MyClass.java in folder Y.
The format of the text varies between input types.
- Specified by:
getToolTipTextin interfaceorg.eclipse.ui.IEditorInput
getName
public java.lang.String getName()
- Description copied from interface:
org.eclipse.ui.IEditorInput - Returns the name of this editor input for display purposes.
For instance, when the input is from a file, the return value would ordinarily be just the file name.
- Specified by:
getNamein interfaceorg.eclipse.ui.IEditorInput
getPersistable
public org.eclipse.ui.IPersistableElement getPersistable()
- Returns
nullsince this editor cannot be persisted.- Specified by:
getPersistablein interfaceorg.eclipse.ui.IEditorInput
exists
public boolean exists()
- Returns
falseto indicate that this input should not appear in the "File Most Recently Used" menu.- Specified by:
existsin interfaceorg.eclipse.ui.IEditorInput
setMessage
protected void setMessage(java.lang.String message)
getMessage
public java.lang.String getMessage()
getTitle
public java.lang.String getTitle()
- Returns the title which will be used in the compare editor's title bar.
It can be set with
setTitle.
setTitle
public void setTitle(java.lang.String title)
- Sets the title which will be used when presenting the compare result.
This method must be called before the editor is opened.
getTitleImage
public org.eclipse.swt.graphics.Image getTitleImage()
- Returns the title image which will be used in the compare editor's title bar.
Returns the title image which will be used when presenting the compare result.
This implementation returns a generic compare icon.
Subclasses can override.
getCompareConfiguration
public CompareConfiguration getCompareConfiguration()
- Returns the configuration object for the viewers within the compare editor.
Returns the configuration which was passed to the constructor.
contributeToToolBar
public void contributeToToolBar(org.eclipse.jface.action.ToolBarManager toolBarManager)
- Adds standard actions to the given
ToolBarManager.Subclasses may override to add their own actions.
run
public void run(org.eclipse.core.runtime.IProgressMonitor monitor) throws java.lang.InterruptedException, java.lang.reflect.InvocationTargetException
- Runs the compare operation and stores the compare result.
- Specified by:
runin interfaceorg.eclipse.jface.operation.IRunnableWithProgress
prepareInput
protected abstract java.lang.Object prepareInput(org.eclipse.core.runtime.IProgressMonitor monitor) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException
- Runs the compare operation and returns the compare result.
If
nullis returned no differences were found and no compare editor needs to be opened. Progress should be reported to the given progress monitor. A request to cancel the operation should be honored and acknowledged by throwingInterruptedException.Note: this method is typically called in a modal context thread which doesn't have a Display assigned. Implementors of this method shouldn't therefore allocated any SWT resources in this method.
getCompareResult
public java.lang.Object getCompareResult()
- Returns the compare result computed by the most recent call to the
runmethod. Returnsnullif no differences were found.
createContents
public org.eclipse.swt.widgets.Control createContents(org.eclipse.swt.widgets.Composite parent)
- Create the SWT controls that are used to display the result of the compare operation.
Creates the SWT Controls and sets up the wiring between the individual panes.
This implementation creates all four panes but makes only the necessary ones visible.
Finally it feeds the compare result into the top left structure viewer
and the content viewer.
Subclasses may override if they need to change the layout or wiring between panes.
createOutlineContents
public org.eclipse.swt.widgets.Control createOutlineContents(org.eclipse.swt.widgets.Composite parent, int direction)
- Since:
- 3.0
feed1
private void feed1(org.eclipse.jface.viewers.ISelection selection)
feedDefault1
private void feedDefault1(org.eclipse.jface.viewers.ISelection selection)
feed2
private void feed2(org.eclipse.jface.viewers.ISelection selection)
feed3
private void feed3(org.eclipse.jface.viewers.ISelection selection)
getElement
private static java.lang.Object getElement(org.eclipse.jface.viewers.ISelection selection)
- Returns the first element of the given selection if the selection
is a
IStructuredSelectionwith exactly one element. Returnsnullotherwise.
setFocus
public void setFocus()
- Asks this input to take focus within its container (editor).
Clients should not call this method but they may override if they implement a different layout with different visual components. Clients are free to call the inherited method.
createDiffViewer
public org.eclipse.jface.viewers.Viewer createDiffViewer(org.eclipse.swt.widgets.Composite parent)
- Factory method for creating a differences viewer for the top left pane.
It is called from
createContentsand returns aDiffTreeViewer.Subclasses may override if they need a different viewer.
findStructureViewer
public org.eclipse.jface.viewers.Viewer findStructureViewer(org.eclipse.jface.viewers.Viewer oldViewer, org.eclipse.compare.structuremergeviewer.ICompareInput input, org.eclipse.swt.widgets.Composite parent)
- Implements the dynamic viewer switching for structure viewers.
The method must return a compare viewer based on the old (or current) viewer
and a new input object. If the old viewer is suitable for showing the new input the old viewer
can be returned. Otherwise a new viewer must be created under the given parent composite or
nullcan be returned to indicate that no viewer could be found.This implementation forwards the request to
CompareUI.findStructureViewer.Subclasses may override to implement a different strategy.
findContentViewer
public org.eclipse.jface.viewers.Viewer findContentViewer(org.eclipse.jface.viewers.Viewer oldViewer, org.eclipse.compare.structuremergeviewer.ICompareInput input, org.eclipse.swt.widgets.Composite parent)
- Implements the dynamic viewer switching for content viewers.
The method must return a compare viewer based on the old (or current) viewer
and a new input object. If the old viewer is suitable for showing the new input the old viewer
can be returned. Otherwise a new viewer must be created under the given parent composite or
nullcan be returned to indicate that no viewer could be found.This implementation forwards the request to
CompareUI.findContentViewer.Subclasses may override to implement a different strategy.
isSaveNeeded
public boolean isSaveNeeded()
- Returns
trueif there are unsaved changes. The value returned is the value of theDIRTY_STATEproperty of this input object. Returnstrueif this input has unsaved changes, that is ifsetDirty(true)has been called. Subclasses don't have to override if the functionality provided bysetDirty is sufficient.
setDirty
public void setDirty(boolean dirty)
- Sets the dirty state of this input to the given
value and sends out a
PropertyChangeEventif the new value differs from the old value.
setDirty
private void setDirty(java.lang.Object source, boolean dirty)
addPropertyChangeListener
public void addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
- Description copied from interface:
IPropertyChangeNotifier - Adds a listener for property changes to this notifier.
Has no effect if an identical listener is already registered.
- Specified by:
addPropertyChangeListenerin interfaceIPropertyChangeNotifier
removePropertyChangeListener
public void removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
- Description copied from interface:
IPropertyChangeNotifier - Removes the given content change listener from this notifier.
Has no effect if the identical listener is not registered.
- Specified by:
removePropertyChangeListenerin interfaceIPropertyChangeNotifier
save
public void save(org.eclipse.core.runtime.IProgressMonitor pm)
- Deprecated. Override method saveChanges instead.
- Save any unsaved changes. Empty implementation. Subclasses must override to save any changes.
- Save any unsaved changes. Empty implementation. Subclasses must override to save any changes.
saveChanges
public void saveChanges(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException
- Save any unsaved changes.
Subclasses must override to save any changes.
This implementation tries to flush changes in all viewers by
calling
ISavable.saveon them.- Since:
- 2.0
flushViewer
private static void flushViewer(CompareViewerSwitchingPane pane, org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException
|
|||||||||
| Home >> All >> org >> eclipse >> [ compare overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.eclipse.compare.CompareEditorInput