Class ExternalTranslationView

java.lang.Object
org.eclipse.core.commands.common.EventManager
org.eclipse.ui.part.WorkbenchPart
org.eclipse.ui.part.ViewPart
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:
GoogleTranslateView, MicrosoftTranslatorView, MockedExternalTranslationView, TranslationAssistView, YandexTranslateView

public class ExternalTranslationView extends AbstractServiceView
The base realization of translation view for external translation services.

    This realization provides:
  • choosing a translation direction by dropdown lists
  • modifying a source text to translate using text field
  • showing a list of translation results in the table
  • opening a preference page with properties for a translation service
  • changing auto translatable and text processing modes by toggle buttons
  • showing detailed information about an errors
  • All methods of this class were made synchronized to avoid errors in multithreading.

    See Also:
    • Field Details

      • translationTableViewer

        protected TableViewer translationTableViewer
      • translationManager

        protected final IExternalTranslationManager translationManager
      • isLangsInitialized

        protected volatile boolean isLangsInitialized
    • Constructor Details

      • ExternalTranslationView

        public ExternalTranslationView(IExternalTranslationManager manager, String providerId, String preferencePageId)
        Constructs a new view for external translation service from the given translation manager, provider's id and id of a preference page for this service.
        Parameters:
        manager - the translation manager to translate queries
        providerId - the id of translation service's provider
        preferencePageId - the id of preference page for translation service
    • Method Details

      • setSourceLanguage

        public void setSourceLanguage(String locale)
        Selects the code of language to translate from.
        Parameters:
        locale - the source language code
      • setTargetLanguage

        public void setTargetLanguage(String locale)
        Selects the code of language to translate to.
        Parameters:
        locale - the target language code
      • getSourceLanguage

        public Optional<String> getSourceLanguage()
        Returns the code of language to translate from.
        Returns:
        the source language code or Optional#empty() if the source language isn't presented
      • getTargetLanguage

        public Optional<String> getTargetLanguage()
        Returns the code of language to translate to.
        Returns:
        the target language code or Optional#empty() if the target language isn't presented
      • createPartControl

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

        public void closed()
        Overrides:
        closed in class ManagedViewPart
      • dispose

        public void dispose()
        Specified by:
        dispose in interface org.eclipse.ui.IWorkbenchPart
        Overrides:
        dispose in class ManagedViewPart
      • isInitialized

        public boolean isInitialized()
        Returns true if the combo boxes for translation languages were properly initialized.

        It can return false if the API key is invalid and combo boxes couldn't be initialized.

        Returns:
        true if the combo boxes for translation languages were properly initialized
      • handleTextSelection

        protected void handleTextSelection(org.eclipse.jface.text.ITextSelection selection)
      • handleStructedSelection

        protected void handleStructedSelection(IStructuredSelection selection)
      • initMainControl

        protected void initMainControl(org.eclipse.swt.widgets.Composite top)
        Description copied from class: AbstractServiceView
        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).

        Specified by:
        initMainControl in class AbstractServiceView
        Parameters:
        top - a parent component for main control
      • getTranslationInput

        protected Object getTranslationInput()
      • getTranslationTableContentProvider

        protected IContentProvider getTranslationTableContentProvider()
      • getTranslationTableLabelProvider

        protected IBaseLabelProvider getTranslationTableLabelProvider()
      • initMenu

        protected void initMenu(org.eclipse.jface.action.IMenuManager menuManager)
        Description copied from class: AbstractServiceView
        Initializes a menu actions on the given menu manager.
        Overrides:
        initMenu in class AbstractServiceView
        Parameters:
        menuManager - a menu manager for that a menu items will be added
      • clear

        protected void clear()
        Description copied from class: AbstractServiceView
        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).

        Overrides:
        clear in class AbstractServiceView
      • createTranslationJob

        protected org.eclipse.core.runtime.jobs.Job createTranslationJob()
        Description copied from class: AbstractServiceView
        Creates a job that does a translation work.
        Specified by:
        createTranslationJob in class AbstractServiceView
        Returns:
        a new translation job or null if it's impossible to create a job
      • createJobFromQuery

        protected org.eclipse.core.runtime.jobs.Job createJobFromQuery(ISingleTranslationQuery query)
      • initToolBar

        protected void initToolBar(org.eclipse.jface.action.IToolBarManager tbm)
        Description copied from class: AbstractServiceView
        Initializes items for the given toolbar menu.
        Specified by:
        initToolBar in class AbstractServiceView
        Parameters:
        tbm - a toolbar manager for that items will be added
      • updateLanguages

        protected void updateLanguages()
        Update languages asynchronously.
      • createQueryFromState

        protected Optional<ISingleTranslationQuery> createQueryFromState()
      • handleTranslationException

        protected void handleTranslationException(TranslationServiceException exc)
      • getSupportedLanguages

        protected Map<String,String> getSupportedLanguages()
      • setActiveQuery

        protected void setActiveQuery(ISingleTranslationQuery query)