Eclipse Platform
Release 3.2

org.eclipse.team.ui.synchronize
Class ModelParticipantAction

java.lang.Object
  extended byorg.eclipse.core.commands.common.EventManager
      extended byorg.eclipse.jface.action.AbstractAction
          extended byorg.eclipse.jface.action.Action
              extended byorg.eclipse.ui.actions.BaseSelectionListenerAction
                  extended byorg.eclipse.team.ui.synchronize.ModelParticipantAction
All Implemented Interfaces:
IAction, ISelectionChangedListener

public abstract class ModelParticipantAction
extends BaseSelectionListenerAction

Model provider actions for use with a ModelSynchronizeParticipant.

Since:
3.2

Field Summary
 
Fields inherited from interface org.eclipse.jface.action.IAction
AS_CHECK_BOX, AS_DROP_DOWN_MENU, AS_PUSH_BUTTON, AS_RADIO_BUTTON, AS_UNSPECIFIED, CHECKED, DESCRIPTION, ENABLED, HANDLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT
 
Constructor Summary
ModelParticipantAction(String text, ISynchronizePageConfiguration configuration)
          Create the model participant action.
 
Method Summary
protected  ISaveableCompareModel getActiveModel()
          Return the currently active buffer.
protected  ISynchronizePageConfiguration getConfiguration()
          Return the page configuration.
protected  ISynchronizationContext getSynchronizationContext()
          Return the synchronization context associated with this action.
protected  ISaveableCompareModel getTargetModel()
          Return the buffer that is the target of this operation.
static void handleBufferChange(Shell shell, ISaveableCompareModel targetModel, ISaveableCompareModel activeModel, boolean allowCancel, IProgressMonitor monitor)
          Convenience method that prompts if the currently active model is dirty and either saves or reverts the model depending on the users input.
protected  void handleModelChange()
          Check to see if the target saveable mode; differs from the currently active model.
protected abstract  boolean isEnabledForSelection(IStructuredSelection selection)
          Return whether the action is enabled for the given selection
protected  boolean isVisible(IDiff node)
          Return whether the given node is visible in the page based on the mode in the configuration.
static boolean promptToSaveChanges(Shell shell, ISaveableCompareModel saveableModel, boolean allowCancel)
          Convenience method that prompts to save changes in the given dirty model.
 void selectionChanged(ISelection selection)
          Set the selection of this action to the given selection
protected  void setActiveModel(ISaveableCompareModel buffer)
          Set the active buffer.
 void updateEnablement()
          Method called when the action is about to be shown in a context menu.
protected  boolean updateSelection(IStructuredSelection selection)
          Updates this action in response to the given selection.
 
Methods inherited from class org.eclipse.ui.actions.BaseSelectionListenerAction
clearCache, getStructuredSelection, runWithEvent, selectionChanged, selectionChanged
 
Methods inherited from class org.eclipse.jface.action.Action
convertAccelerator, convertAccelerator, findKeyCode, findKeyString, findModifier, findModifierString, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, notifyResult, removeAcceleratorText, removeMnemonics, run, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText
 
Methods inherited from class org.eclipse.jface.action.AbstractAction
addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener
 
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.action.IAction
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

ModelParticipantAction

public ModelParticipantAction(String text,
                              ISynchronizePageConfiguration configuration)
Create the model participant action.

Parameters:
text - the label of the action or null
configuration - the configuration for the page that is surfacing the action
Method Detail

getConfiguration

protected ISynchronizePageConfiguration getConfiguration()
Return the page configuration.

Returns:
the page configuration

selectionChanged

public void selectionChanged(ISelection selection)
Set the selection of this action to the given selection

Parameters:
selection - the selection

updateSelection

protected boolean updateSelection(IStructuredSelection selection)
Description copied from class: BaseSelectionListenerAction
Updates this action in response to the given selection.

The BaseSelectionListenerAction implementation of this method returns true. Subclasses may extend to react to selection changes; however, if the super method returns false, the overriding method must also return false.

Overrides:
updateSelection in class BaseSelectionListenerAction
Parameters:
selection - the new selection
Returns:
true if the action should be enabled for this selection, and false otherwise

isEnabledForSelection

protected abstract boolean isEnabledForSelection(IStructuredSelection selection)
Return whether the action is enabled for the given selection

Parameters:
selection - the selection
Returns:
whether the action is enabled for the given selection

getSynchronizationContext

protected ISynchronizationContext getSynchronizationContext()
Return the synchronization context associated with this action.

Returns:
the synchronization context associated with this action

isVisible

protected boolean isVisible(IDiff node)
Return whether the given node is visible in the page based on the mode in the configuration.

Parameters:
node - a diff node
Returns:
whether the given node is visible in the page

handleModelChange

protected void handleModelChange()
                          throws InvocationTargetException,
                                 InterruptedException
Check to see if the target saveable mode; differs from the currently active model. If it does, prompt to save changes in the active model if it is dirty.

Throws:
InterruptedException
InvocationTargetException

handleBufferChange

public static void handleBufferChange(Shell shell,
                                      ISaveableCompareModel targetModel,
                                      ISaveableCompareModel activeModel,
                                      boolean allowCancel,
                                      IProgressMonitor monitor)
                               throws CoreException,
                                      InterruptedException
Convenience method that prompts if the currently active model is dirty and either saves or reverts the model depending on the users input.

Parameters:
shell - a parent shell
targetModel - the new model
activeModel - the current model
allowCancel - whether canceling the action is an option
monitor - a progress monitor
Throws:
CoreException
InterruptedException

promptToSaveChanges

public static boolean promptToSaveChanges(Shell shell,
                                          ISaveableCompareModel saveableModel,
                                          boolean allowCancel)
                                   throws InterruptedException
Convenience method that prompts to save changes in the given dirty model.

Parameters:
shell - a shell
saveableModel - a dirty saveable model
allowCancel - whether canceling the action is an option
Returns:
whether the user choose to save (true) or revert (false() the model
Throws:
InterruptedException - thrown if the user choose to cancel

getActiveModel

protected ISaveableCompareModel getActiveModel()
Return the currently active buffer. By default, the active buffer is obtained from the synchronization page configuration.

Returns:
the currently active buffer (or null if no buffer is active).

setActiveModel

protected void setActiveModel(ISaveableCompareModel buffer)
Set the active buffer. By default to active buffer is stored with the synchronize page configuration.

Parameters:
buffer - the buffer that is now active (or null if no buffer is active).

getTargetModel

protected ISaveableCompareModel getTargetModel()
Return the buffer that is the target of this operation. By default, null is returned.

Returns:
the buffer that is the target of this operation

updateEnablement

public void updateEnablement()
Method called when the action is about to be shown in a context menu. This method recalculates the enablement for the current selection and uses that to set the enablement.


Eclipse Platform
Release 3.2

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2006. All rights reserved.