Class 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
- 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
-
Field Summary
Fields inherited from interface org.eclipse.ui.IWorkbenchPart
PROP_TITLE -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new abstract view for translation services.AbstractServiceView(String preferencePageId) Creates a new abstract view for translation services. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddListenerToActiveText(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 booleancheckInputText(String text) Validates the input text to translate.protected voidclear()Clears this view.voidcreatePartControl(org.eclipse.swt.widgets.Composite parent) protected abstract org.eclipse.core.runtime.jobs.JobCreates a job that does a translation work.protected voidcreateTranslationText(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.CompositeReturns the main composite that contains all components.protected voidHides errors if they are shown.protected abstract voidinitMainControl(org.eclipse.swt.widgets.Composite top) Creates a main control.protected voidinitMenu(org.eclipse.jface.action.IMenuManager menuManager) Initializes a menu actions on the given menu manager.protected abstract voidinitToolBar(org.eclipse.jface.action.IToolBarManager tbm) Initializes items for the given toolbar menu.protected booleanChecks if the error visible.protected voidremoveListenerFromActiveText(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.voidsetActiveText(String text) Sets active text for translating to translate.<T extends IApplicable>
voidsetApplicableObject(T applicable) Sets the object that provides applying the translation results.voidsetFocus()protected voidShows an errors occur while translating.voidStarts translating.voidStops 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, visibleMethods inherited from class org.eclipse.ui.part.ViewPart
checkSite, getViewSite, init, init, saveState, setContentDescription, setInitializationData, setPartNameMethods 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, showBusyMethods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObjectMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapterMethods inherited from interface org.eclipse.ui.IWorkbenchPart
addPropertyListener, getSite, getTitle, getTitleImage, getTitleToolTip, removePropertyListener
-
Constructor Details
-
AbstractServiceView
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
Sets the object that provides applying the translation results.- Parameters:
query- an applicable object
-
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
Sets active text for translating to translate.- Parameters:
text- a text for translating
-
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:
createPartControlin interfaceorg.eclipse.ui.IWorkbenchPart- Overrides:
createPartControlin classManagedViewPart
-
setFocus
public void setFocus()- Specified by:
setFocusin interfaceorg.eclipse.ui.IWorkbenchPart- Specified by:
setFocusin classorg.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 callscreateTranslationJob()to create a new job to run it. It does nothing ifcreateTranslationJob()method returnsOptional.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
Shows an errors occur while translating.- Parameters:
msg- a brief information about errordetail- a detail information about errorexc- 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:
trueif 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 forlistener- 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 forlistener- the listener which should no longer be notified- See Also:
-
checkInputText
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
-