Class AbstractTranslationPreferencePage

java.lang.Object
org.eclipse.jface.dialogs.DialogPage
org.eclipse.jface.preference.PreferencePage
com.e1c.langtool.ui.external.AbstractTranslationPreferencePage
All Implemented Interfaces:
org.eclipse.jface.dialogs.IDialogPage, org.eclipse.jface.dialogs.IMessageProvider, org.eclipse.jface.preference.IPreferencePage, org.eclipse.ui.IWorkbenchPreferencePage
Direct Known Subclasses:
GoogleTranslatePreferencePage, MicrosoftTranslatorPreferencePage, YandexTranslatePreferencePage

public abstract class AbstractTranslationPreferencePage extends org.eclipse.jface.preference.PreferencePage implements org.eclipse.ui.IWorkbenchPreferencePage
An abstract class of a preference page for external translation services.

    This abstract realization of a preference page contains:
  • field to input a license key of translation service
  • button to clear a cache of translations
  • button to check a license key for validity
  • A subclasses should set a preference store in init(workbanch) method.

    See Also:
    • PreferencePage.setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)
    • IWorkbenchPreferencePage.init(org.eclipse.ui.IWorkbench)
    • Field Summary

      Fields
      Modifier and Type
      Field
      Description
      protected boolean
       

      Fields inherited from interface org.eclipse.jface.dialogs.IMessageProvider

      ERROR, INFORMATION, NONE, WARNING
    • Constructor Summary

      Constructors
      Constructor
      Description
      Constructs a new abstract preference page for external translation service.
    • Method Summary

      Modifier and Type
      Method
      Description
      protected abstract boolean
      Checks an access key for validity.
      protected void
      Clears the cache of translations.
      protected abstract void
      createAccessKeyGroup(org.eclipse.swt.widgets.Composite parent)
      Creates a group that contains components to work with access (API) key.
      protected void
      createCheckAccessKeyButton(org.eclipse.swt.widgets.Composite parent)
      Creates a button to check a validity of access key.
      protected void
      createClearCacheButton(org.eclipse.swt.widgets.Composite parent)
      Creates a button to clear translations cache.
      protected void
      createClearCacheGroup(org.eclipse.swt.widgets.Composite parent)
      Creates a group that contains components to clear translation cache.
      protected org.eclipse.swt.widgets.Control
      createContents(org.eclipse.swt.widgets.Composite parent)
       
      protected void
      createGetAccessKeyLink(org.eclipse.swt.widgets.Composite parent)
      Creates a link to get API key.
      protected abstract org.eclipse.swt.events.SelectionListener
      Creates a selection listener to handle clicks by link to get API key.
      protected org.eclipse.jface.preference.IPreferenceStore
       
      protected abstract String
      Returns inputed API key to check if it valid in checkAccessKey(String).
      protected abstract void
      Initialize values from preference storo to UI elements.
      protected void
       
      boolean
       
      protected abstract void
      Reload a view that associated with this preference page.
      protected abstract void
      Store values into preference store on apply or OK buttons.

      Methods inherited from class org.eclipse.jface.preference.PreferencePage

      applyData, applyDialogFont, computeSize, contributeButtons, createControl, createDescriptionLabel, createNoteComposite, doComputeSize, getApplyButton, getContainer, getDefaultsButton, getPreferenceStore, isValid, noDefaultAndApplyButton, noDefaultButton, okToLeave, performApply, performCancel, performHelp, setContainer, setErrorMessage, setMessage, setPreferenceStore, setSize, setTitle, setValid, toString, updateApplyButton

      Methods inherited from class org.eclipse.jface.dialogs.DialogPage

      convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, dispose, getControl, getDescription, getDialogFontName, getErrorMessage, getFont, getImage, getMessage, getMessageType, getShell, getTitle, getToolTipText, initializeDialogUnits, isControlCreated, setButtonLayoutData, setControl, setDescription, setImageDescriptor, setMessage, setVisible

      Methods inherited from class java.lang.Object

      clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

      Methods inherited from interface org.eclipse.jface.dialogs.IDialogPage

      createControl, dispose, getControl, getDescription, getErrorMessage, getImage, getMessage, getTitle, performHelp, setDescription, setImageDescriptor, setTitle, setVisible

      Methods inherited from interface org.eclipse.jface.preference.IPreferencePage

      computeSize, isValid, okToLeave, performCancel, setContainer, setSize

      Methods inherited from interface org.eclipse.ui.IWorkbenchPreferencePage

      init
    • Field Details

      • isApiKeyValueChanged

        protected boolean isApiKeyValueChanged
    • Constructor Details

      • AbstractTranslationPreferencePage

        public AbstractTranslationPreferencePage(ITranslationCacheManager translationCacheManager, String providerId)
        Constructs a new abstract preference page for external translation service.

        The given provider's id is necessary for clearing a cache of translations.

        Parameters:
        providerId - external translation service's provider id
    • Method Details

      • performOk

        public boolean performOk()
        Specified by:
        performOk in interface org.eclipse.jface.preference.IPreferencePage
        Overrides:
        performOk in class org.eclipse.jface.preference.PreferencePage
      • performDefaults

        protected void performDefaults()
        Overrides:
        performDefaults in class org.eclipse.jface.preference.PreferencePage
      • createContents

        protected org.eclipse.swt.widgets.Control createContents(org.eclipse.swt.widgets.Composite parent)
        Specified by:
        createContents in class org.eclipse.jface.preference.PreferencePage
      • createAccessKeyGroup

        protected abstract void createAccessKeyGroup(org.eclipse.swt.widgets.Composite parent)
        Creates a group that contains components to work with access (API) key.

        This method creates a group contains a text field to input access key for translation api and button to validate it.

        Parameters:
        parent - the composite to which this component will be added
        See Also:
      • createGetAccessKeyLink

        protected void createGetAccessKeyLink(org.eclipse.swt.widgets.Composite parent)
        Creates a link to get API key.

        This method creates a Link component with SelectionListener created by createLinkSelectionListener() factory method.

        Parameters:
        parent - the composite to which this component will be added
      • clearCache

        protected void clearCache()
        Clears the cache of translations.
      • createClearCacheButton

        protected void createClearCacheButton(org.eclipse.swt.widgets.Composite parent)
        Creates a button to clear translations cache.
        Parameters:
        parent - the composite to which this component will be added
      • createClearCacheGroup

        protected void createClearCacheGroup(org.eclipse.swt.widgets.Composite parent)
        Creates a group that contains components to clear translation cache.

        This method creates a group contains a simple label and button to clear cache.

        Parameters:
        parent - the composite to which this component will be added
        See Also:
      • createCheckAccessKeyButton

        protected void createCheckAccessKeyButton(org.eclipse.swt.widgets.Composite parent)
        Creates a button to check a validity of access key.
        Parameters:
        parent - the composite to which this component will be added
      • doGetPreferenceStore

        protected org.eclipse.jface.preference.IPreferenceStore doGetPreferenceStore()
        Overrides:
        doGetPreferenceStore in class org.eclipse.jface.preference.PreferencePage
      • getAccessKey

        protected abstract String getAccessKey()
        Returns inputed API key to check if it valid in checkAccessKey(String).
        Returns:
        an access (API) key
      • checkAccessKey

        protected abstract boolean checkAccessKey(String key)
        Checks an access key for validity.
        Parameters:
        key - an access key
        Returns:
        true if a given key is valid
        Throws:
        ServiceUnavailableException - if the translation service is unavailable or there was connection error
      • reloadView

        protected abstract void reloadView()
        Reload a view that associated with this preference page.
        See Also:
      • createLinkSelectionListener

        protected abstract org.eclipse.swt.events.SelectionListener createLinkSelectionListener()
        Creates a selection listener to handle clicks by link to get API key.
        See Also:
      • initializeValues

        protected abstract void initializeValues()
        Initialize values from preference storo to UI elements.
      • storeValues

        protected abstract void storeValues()
        Store values into preference store on apply or OK buttons.