Class AbstractServiceView

java.lang.Object
org.eclipse.core.commands.common.EventManager
org.eclipse.ui.part.WorkbenchPart
org.eclipse.ui.part.ViewPart
com.e1c.langtool.ui.common.ManagedViewPart
com.e1c.langtool.ui.common.tools.AbstractServiceView
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, org.eclipse.core.runtime.IExecutableExtension, org.eclipse.ui.IPersistable, org.eclipse.ui.IViewPart, org.eclipse.ui.IWorkbenchPart, org.eclipse.ui.IWorkbenchPart2, org.eclipse.ui.IWorkbenchPart3, org.eclipse.ui.part.IWorkbenchPartOrientation
Direct Known Subclasses:
ExternalTranslationView, ProjectTranslationView

public abstract class AbstractServiceView extends ManagedViewPart
Abstract realization of view for translation services.

    This class provides the basic functionality that includes:
  • starting translating by running a job
  • showing errors occur while translating
  • setting and getting of an active translation query
All public methods that are overridden by this class are synchronized to provide thread-safety.

  • Field Summary

    Fields inherited from interface org.eclipse.ui.IWorkbenchPart

    PROP_TITLE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new abstract view for translation services.
    AbstractServiceView(String preferencePageId)
    Creates a new abstract view for translation services.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addListenerToActiveText(int eventType, org.eclipse.swt.widgets.Listener listener)
    Adds the listener to the collection of active text listeners who will be notified when an event of the given type occurs.
    protected boolean
    Validates the input text to translate.
    protected void
    Clears this view.
    void
    createPartControl(org.eclipse.swt.widgets.Composite parent)
     
    protected abstract org.eclipse.core.runtime.jobs.Job
    Creates a job that does a translation work.
    protected void
    createTranslationText(org.eclipse.swt.widgets.Composite top)
    Creates the text field on the given top composite for inputing or modifying text to translate.
    Returns the active text for translating or null if there is not active text.
    Returns the object that provides applying the translation results.
    org.eclipse.swt.widgets.Composite
    Returns the main composite that contains all components.
    protected void
    Hides errors if they are shown.
    protected abstract void
    initMainControl(org.eclipse.swt.widgets.Composite top)
    Creates a main control.
    protected void
    initMenu(org.eclipse.jface.action.IMenuManager menuManager)
    Initializes a menu actions on the given menu manager.
    protected abstract void
    initToolBar(org.eclipse.jface.action.IToolBarManager tbm)
    Initializes items for the given toolbar menu.
    protected boolean
    Checks if the error visible.
    protected void
    removeListenerFromActiveText(int eventType, org.eclipse.swt.widgets.Listener listener)
    Removes the listener from the collection of active text listeners who will be notified when an event of the given type occurs.
    void
    Sets active text for translating to translate.
    <T extends IApplicable>
    void
    setApplicableObject(T applicable)
    Sets the object that provides applying the translation results.
    void
     
    protected void
    showError(String msg, String detail, Throwable exc)
    Shows an errors occur while translating.
    void
    Starts translating.
    void
    Stops the active translation process if it's present.

    Methods inherited from class com.e1c.langtool.ui.common.ManagedViewPart

    activated, broughtToTop, closed, deactivated, dispose, hidden, opened, visible

    Methods inherited from class org.eclipse.ui.part.ViewPart

    checkSite, getViewSite, init, init, saveState, setContentDescription, setInitializationData, setPartName

    Methods inherited from class org.eclipse.ui.part.WorkbenchPart

    addPartPropertyListener, addPropertyListener, firePartPropertyChanged, firePropertyChange, getAdapter, getConfigurationElement, getContentDescription, getDefaultImage, getOrientation, getPartName, getPartProperties, getPartProperty, getSite, getTitle, getTitleImage, getTitleToolTip, removePartPropertyListener, removePropertyListener, setPartProperty, setSite, setTitle, setTitleImage, setTitleToolTip, showBusy

    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.core.runtime.IAdaptable

    getAdapter

    Methods inherited from interface org.eclipse.ui.IWorkbenchPart

    addPropertyListener, getSite, getTitle, getTitleImage, getTitleToolTip, removePropertyListener
  • Constructor Details

    • AbstractServiceView

      public AbstractServiceView(String preferencePageId)
      Creates a new abstract view for translation services.
      Parameters:
      preferencePageId - the id of related preference page that can be opened by menu
    • AbstractServiceView

      public AbstractServiceView()
      Creates a new abstract view for translation services.

      This constructor creates a view that allows opening a preference page from menu. By default it opens a main preference page.

  • Method Details

    • getTopComposite

      public org.eclipse.swt.widgets.Composite getTopComposite()
      Returns the main composite that contains all components.
      Returns:
      the main composite
    • setApplicableObject

      public <T extends IApplicable> void setApplicableObject(T applicable)
      Sets the object that provides applying the translation results.
      Parameters:
      query - an applicable object
    • getApplicalbleObject

      public Optional<IApplicable> getApplicalbleObject()
      Returns the object that provides applying the translation results.
      Returns:
      the applicable object or Optional#empty() if there isn't active applicable object
    • setActiveText

      public void setActiveText(String text)
      Sets active text for translating to translate.
      Parameters:
      text - a text for translating
    • getActiveText

      public String getActiveText()
      Returns the active text for translating or null if there is not active text.
      Returns:
      the active text for translating
    • createPartControl

      public void createPartControl(org.eclipse.swt.widgets.Composite parent)
      Specified by:
      createPartControl in interface org.eclipse.ui.IWorkbenchPart
      Overrides:
      createPartControl in class ManagedViewPart
    • setFocus

      public void setFocus()
      Specified by:
      setFocus in interface org.eclipse.ui.IWorkbenchPart
      Specified by:
      setFocus in class org.eclipse.ui.part.WorkbenchPart
    • startTranslating

      public void startTranslating()
      Starts translating.

      Before start translation process this method calls stopTranslating() to stop the active translation process if it is present. After that it calls createTranslationJob() to create a new job to run it. It does nothing if createTranslationJob() method returns Optional.empty().

    • stopTranslating

      public void stopTranslating()
      Stops the active translation process if it's present.
    • initMenu

      protected void initMenu(org.eclipse.jface.action.IMenuManager menuManager)
      Initializes a menu actions on the given menu manager.
      Parameters:
      menuManager - a menu manager for that a menu items will be added
    • initToolBar

      protected abstract void initToolBar(org.eclipse.jface.action.IToolBarManager tbm)
      Initializes items for the given toolbar menu.
      Parameters:
      tbm - a toolbar manager for that items will be added
    • initMainControl

      protected abstract void initMainControl(org.eclipse.swt.widgets.Composite top)
      Creates a main control.

      In most cases this control is used for showing translation results. This component is located between the text component (for active text) in the top and error component in the bottom (for showing information about errors).

      Parameters:
      top - a parent component for main control
    • createTranslationJob

      protected abstract org.eclipse.core.runtime.jobs.Job createTranslationJob()
      Creates a job that does a translation work.
      Returns:
      a new translation job or null if it's impossible to create a job
    • clear

      protected void clear()
      Clears this view.

      It detaches the active applicable object (sets value for object as Optional.empty()) from this view, sets active text as empty and hides all errors from error component. Also this method should be used for clearing controls that contains not static data (like text fields or tables).

    • showError

      protected void showError(String msg, String detail, Throwable exc)
      Shows an errors occur while translating.
      Parameters:
      msg - a brief information about error
      detail - a detail information about error
      exc - a throwable instance or null
    • hideError

      protected void hideError()
      Hides errors if they are shown.
    • isErrorVisible

      protected boolean isErrorVisible()
      Checks if the error visible.
      Returns:
      true if the error visible
    • createTranslationText

      protected void createTranslationText(org.eclipse.swt.widgets.Composite top)
      Creates the text field on the given top composite for inputing or modifying text to translate.

      Also the realization of a text field that is used in this method shows an error tooltip when trying to translate a blank text

      Parameters:
      top - the top composite of this view
    • addListenerToActiveText

      protected void addListenerToActiveText(int eventType, org.eclipse.swt.widgets.Listener listener)
      Adds the listener to the collection of active text listeners who will be notified when an event of the given type occurs.
      Parameters:
      eventType - the type of event to listen for
      listener - the listener which should be notified when the event occurs
      See Also:
    • removeListenerFromActiveText

      protected void removeListenerFromActiveText(int eventType, org.eclipse.swt.widgets.Listener listener)
      Removes the listener from the collection of active text listeners who will be notified when an event of the given type occurs.
      Parameters:
      eventType - the type of event to listen for
      listener - the listener which should no longer be notified
      See Also:
    • checkInputText

      protected boolean checkInputText(String text)
      Validates the input text to translate.

      This realization checks the given text for emptiness. This method is used in startTranslating() method, so a translating process will not start if the given text is not valid.

      Parameters:
      text - the text to translate
      Returns:
      false if the given text contains only whitespace characters