15. UI Concepts
Parts of this chapter may be outdated. |
15.1. User Interface Concepts
15.1.1. Eclipse UI Concepts
The following list gives an overview of Eclipse specific UI concepts and which classes are used for implementation.
15.1.1.1. Label Provider
Also provides decorations for icons and text labels.
Example |
The representation of objects in the outline view or in search results. |
Eclipse API |
|
Xtext Specifics |
|
Best Practices |
Labels are often use-case specific, so a single label provider is not always useful Therefore, in Xtext are different label providers for different use cases. Use cases are defined and enumerated (see
|
15.1.1.2. Markers
Markers are objects that may be associated with Workbench resources. There are many uses of markers in the Workbench… Markers are shown in a marker view (Tasks, Problems or Bookmark view) or on the marker bar in the editor area.
Examples |
Tasks, Problems, Bookmarks, Breakpoints, Trace information |
Eclipse API |
|
Xtext |
(2.6) +
|
Best Practices |
In Xtend, markers are used to trace from original file to generated file. They are hidden (and not displayed), so in general markers can be used for non-UI-problems as well (but only available in Eclipse of course) clean up markers: no general solution, often managed by some (single) life-cycle aware class (e.g., Builder) |
15.1.1.3. Commands, Toolbar and Menus
Examples |
Organize Imports, |
Eclipse API |
use Commands + Handlers instead of Actions (or ActionDelegates etc.) |
Xtext Specifics |
uses commands and handlers |
Best Practice |
Use commands and handlers -
handler usually only delegates to real thing (that is, retrieve parameters from context and call the real thing)
|
Undo: use TextEdit and MultiTextEdit (composed)
otherwise very low level
15.1.1.4. Content Assist
Content assist allows you to provide context sensitive content completion upon user request. Popup windows (infopops) are used to propose possible text choices to complete a phrase. The user can select these choices for insertion in the text. Content assist also supports contextual infopops for providing the user with information that is related to the current position in the document.
Risk |
Always needs longer than anticipated. |
Examples |
complete name of function in function call, complete keywords |
Eclipse API |
|
Xtext Specifics |
|
Best Practices |
|
15.1.1.5. Quick Fixes
Users can select a problem marker and choose a Quick Fix from a popup containing the list of supplied fixes contributed for the marker.
Examples |
Add Import, Add Override Annotation |
Eclipse API |
Based on ICompletionProposal (powerful) +
|
Xtext Specifics |
Based on ISematicModification (seemingly powerful but in fact weak) and IModification (less weak, but still very weak compared to ICompletionProposal) – only creates DocumentChanges. + Declarativ API that links to issue codes via annotations on 'fix' methods in AbstractDeclarativeQuickfixProvider. |
Best Practices |
ICompletionProposal vs. DocumentChanges, ICompletionProposal is much more powerful. IModifications can also provide semantic changes, but not really recommended +
|
15.1.1.6. Quick Assist
"Quick assists perform local code transformations. They are invoked on a selection or a single cursor in the Java editor and use the same shortcut as quick fixes (Ctrl+1), but quick assist are usually hidden when an error is around. To show them even with errors present on the same line, press Ctrl+1 a second time." (Eclipse Help)
like a quickfix without a problem
Examples |
Add/remove inferred types |
Eclipse API |
Takes cursor position |
Xtext |
no Xtext support, e.g. no default implementation (XtextQuickAssistProcessor is a quick fix provider, has nothing to do with QuickAssist) but: XtextQuickAssistProcessor, override canAssist, override computeQuickAssistProposals |
15.1.1.7. Clean Up Actions
Examples |
Remove unused local vars, sort members |
Eclipse API |
None, JDT specific (see ICleanUp) |
Xtext Specifics |
None |
Best Practice |
Monkey sees - Monkey does (look at JDT), In the end a it’s a CompositeRefactoring, which is a CompletionProposal |
15.1.1.8. Save Actions
Similar to clean up actions but performed on save
Examples |
Format on save, Organize imports on save |
Eclipse API |
None, JDT specific (see IPostSaveListener) |
Xtext Specifics |
None |
Best Practice |
XtextDocumentProvider.doSaveDocument (maybe better solutions in the future ;-) ) |
15.1.1.9. Auto Edit
Auto edit is about closing braces that just have been typed, adding indentation after a line break the code snippet if (true)
so basically it should be unobtrusive typing aids.
By default, restore model structure when editing (guide the user to proper text formatting, help the parser). Should not be used for other purposes in order to not hinder the user’s flow of editing.
Examples |
( → ( <cursor> ) |
Eclipse API |
org.eclipse.jface.text.IAutoEditStrategy |
Xtext Specifics |
org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategy, some utility methods + implements VerifyKeyListener. May use the ISourceViewer via implements ISourceViewerAware |
Best Practices |
Keep it as it is. |
Fun example but not useful in practice cf. FantasticAutoEditStrategy
15.1.1.10. Template Proposals
More sophisticated edit utils that are invoked by means of content assist.
Examples |
sysout → System.out.println( |
Eclipse API |
Part of the completion proposal API, e.g. ICompletionProposal |
Xtext Specifics |
org.eclipse.xtext.ui.editor.contentassist.ITemplateProposalProvider, template contexts along the grammar rules by default, need to be stripped down to become usable. |
Best Practice |
ship some: create them manually in workbench, export them as XML, fix XML file (add IDs, in Xtext documentation), put XML file in folder |
15.1.1.11. Outline View / Quick Outline
Structural represenation of the file contents (usually with different filter and sorting strategies).
Examples |
Outline View (but not Navigator nor package explorer), Quick Outline (in Xtext: same provider) |
Eclipse API |
org.eclipse.ui.views.contentoutline.IContentOutlinePage |
Xtext Specifics |
Lazy tree creation, syncing via EObject ranges, thread save access to the EObject from nodes. Declarative API to create the tree contents. org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider
+
allow actions on outline nodes (e.g., goto referenced file in |
Best Practice |
|
Helpful tools for icons in outline view:
-
Eclipse view to show available Eclipse icons (that are of course licenced under EPL) with possibility to export them (documentation)
-
overview of Eclipse icons: http://eclipse-icons.i24.cc/
15.1.1.12. Navigator, Package Explorer, Project Explorer
three explorers
, Navigator latest
and most extensible one
Best Practices |
use Navigator only! (RTFM, nothing specific to Xtext yet) |
cf. http://projects.eclipse.org/projects/technology.handly read index and show it in the navigator
15.1.1.13. Hyperlinking and Navigation
Linking (propose multiple linking targets, e.g. goto declaration or goto implementation when CTRL (or other modifier) + Left Mouse Click on method when receiver type is interface - show all available implementations)
Examples |
Go to declaration, Go to implementation, Go to super |
Eclipse API |
org.eclipse.jface.text.hyperlink.IHyperlinkDetector |
Xtext Specifics |
org.eclipse.xtext.ui.editor.hyperlinking.DefaultHyperlinkDetector, navigation to EObject URI most interesting: SIGNIFICANT cf. org.eclipse.xtext.resource.ILocationInFileProviderExtension.RegionDescription |
Best Practice |
|
15.1.1.14. Syntax and Semantic Coloring
Coloring based on the lexical tokens or based on the semantic tokens (the parsed model). The parser may treat certain lexical keywords as valid identifiers in some contexts. Some of those should not appear as keywords. Semantic coloring is usually more expensive to compute thus run in the background and with some delay
Examples |
Numbers, String literals (lexical) Escape sequences in Strings, method calls, property read / write access (semantic) |
Eclipse API |
|
Xtext Specifics |
|
Best Practice |
|
15.1.1.15. Code Formatter
Examples |
Auto-Format Source Code, Auto-Format code inserted by code-rewrite |
Eclipse API |
|
Xtext Specifics |
Declarative Formatting API (to be deprecated) - associate formatting rules with grammar elements New formatting API (mixture of declarative and imperative) - here is the model, do what you want (space before, linebreak after, indentation increase / decrease), the engine will merge your advices and apply them to the document |
Best Practice |
wait for 2.8 (maybe in 2.7.x) |
15.1.1.16. Wizards
Wizards are used to guide the user through a sequenced set of tasks. Your plug-in can contribute wizards at predefined extension points in the workbench. It can also create and launch its own wizards.
Examples |
New N4JS Class |
Eclipse API
Xtext Specifics |
|
Best Practices |
|
15.1.1.17. Cheat Sheets
Composite cheat sheets provide guidance through complex problems by breaking the problem into a set of smaller tasks. Composite cheat sheets are registered using the the
org.eclipse.ui.cheatsheets.cheatSheetContent
extension point.
(In Scala IDE: Work Sheets), often combined with Code Snippets
Examples |
Create Hello World Application |
Eclipse API
Xtext Specifics |
None, probably the embedded editor could be used in a REPL (Read-Evaluate-Print-Loop) |
15.1.1.18. Context-sensitive Help
A focused set of help topics that is related to the current context can be shown to users on demand using context-sensitive help. This form of user assistance is delivered to users when a platform-specific trigger is activated (e.g. F1 key on Windows, Ctrl+F1 on GTK, Help key on Carbon). Until Eclipse 3.1, context-sensitive help was presented in infopop windows. Since 3.1, a new Help view is the preferred way to deliver context-sensitive information to the user.
Examples |
Help in Formular Editor, Help about syntax construct, API-Help |
Eclipse API
Xtext Specifics |
None |
15.1.1.19. Hovers
Hover allow to display additional information as soon as the cursor stays on a certain text region. Some hovers can be requested by shortcuts (e.g. F2) similar to sort of an online help.
Different kind of hovers may appear depending on the context, e.g. the error hover will have higher prio than the documentation hover. Different modifier keys may be assigned to request different hover kinds while hovering a region with the mouse. (didn’t a proper code pointer, though)
Examples |
Hover over method shows JSDoc, Signatures or inferred types, error / problem details |
Eclipse API |
|
Xtext Specifics |
|
Best Practice |
see XBase hover stuff |
15.1.1.20. Folding
Code folding allows to skip parts of the code that are mandatory semantically but usually do not provide added value for the reader, e.g. import sections
Examples |
Import section folding, folding of arbitrary methods or comments |
Eclipse API |
Not much there, most of that stuff is implemented specific to JDT or ODE. Projections usually only work per line, that is, a subsection of a line cannot be folded, e.g. it’s not possible to show
as
Line only limitation in SWT (a guess, didn’t work for Sebastian otherwise) |
Xtext Specifics |
|
Best Practice |
|
15.1.1.21. Customizable validation / severity
Some problems are more important to the user than others so they want to change the severity.
Examples |
Deprecation could be an error, warning or ignored (e.g. in test projects) |
Eclipse API |
None |
Xtext Specifics |
IssueSeverityProvider (since 2.6), Monkey sees monkey does: see subclasses of IssueSeverityProvider (we already do that) |
15.1.1.22. Proposals
Created by Content Assist, Quick Fixes, Quick Assist.
Basics
-
simplest case: proposals are strings to be inserted
-
or displayed string is different from inserted one (e.g. FQN vs. simple)
-
ConfigurableCompletionProposal created via factory methods in AbstractN4JSProposalProvider (*create*Pro)
-
PrefixMatcher (by default CamelCase aware) – for filtering, it usually is not necessary to use it when computing the proposal (only if it expensive to compute proposals) – that is, prefix can be ignored when computing a proposal because the prefix matcher will filter out invalid proposals anyway
-
pass a filter (Guava preodicate) to filter out (semantically invalid) proposals, cf. lookupCrossReference(..) – for the things where there are proposals created by default
-
priority defined by an int – for sorting. Cf. ContentProposalPriorities → define default priorities (constant values) in N4JS, do not add some random integers!
-
modes: bind RepeatedContentAssistProcessor and enable modeaware in ProposalProvider (e.g. for private members which require a quickfix)
-
what could be done in the background: hover, lazy (not prepared) proposals (cf. JDT), Xtext 2.7.; different situations are processed in parallel
Several changes (e.g. automatic import):
-
ConfigurableCompletionProposal.setTextApplier
-
TextApplier: can open dialogs etc., TextApplier is the callback
-
usual case: add text at cursor position and somewhere else:
-
get document in TextApplier
-
for performance, but also: do not use semantic changes in content assist, because model is broken (you will get funny things) – use model (AST) to get offset, but then insert line breaks etc. → maybe create utility class for retrieving current formattings which are then used in the text edit → maybe provide tools for retrieving certain locations (e.g. import section, field section, etc.)
-
do not create model (AST) fragments (which are then serialized), instead directly provide text
-
use TextEdit and MultiTextEdit
-
set TextViewer redraw to false and to true after the text edits were applied
-
have proper TESTS to ensure that file is not broken after the changes
-
-
LinkedEditing:
-
Linked-Editing mode in ConfigurableCompletionProposal with one editing group only (basically: move the cursor somewhere after editing it, see setSimpleLinkedMode)
-
do it manually: cf. LinkedPositionGroup (see call hierarchy of constructor) – used for quick fixes or refactorings rather for content assist
-
15.1.2. Non-Eclipse UI Concepts
The following entries are not necessarily implemented yet.
15.1.2.1. Overlays
An overlay is a small annotation similar to an hover, attached to a specific location in the editor and is moved with that location.
Examples |
Show inferred types |
15.1.2.2. Goto (Inferred) Type
Navigate to an inferred type (or other invisible
information)
15.1.2.3. Postfix Completion
(IntelliJ) Replace code AFTER an expression
15.2. User Interface Resources
15.2.1. Icons
In parts, the N4JS IDE re-uses some of the icons that come with the Eclipse Platform as well as the Eclipse JDT development environment. However, in some cases we also provide our own icons to illustrate N4JS-specific concepts.
15.2.1.1. Eclipse Platform Icons
When re-using the Eclipse Platform Icons, the icons are usually copied over to the icons/
folder of the org.eclipse.n4js.ui
bundle. In this folder, the README.adoc
file keeps book on the origin of all the collected icons (e.g. different Eclipse Projects).
15.2.1.2. N4JS Specific Icons
In some cases, the icons the Eclipse eco-system provides do not suffice to sensibly express N4JS concepts. In these cases we provide our own icons. When designing those we try to imitate the general Eclipse artstyle in order for our icons to integrate well with the overall appearance of Eclipse.
For the creation of new icons, the eclipse-svg-icons
repository (see https://github.com/Seung-Yoon/eclipse-svg-icons) has proven helpful. The repository contains raw SVG files which can be used to reproduce the bitmap icons that are contained in, for instance, the org.eclipse.platform.ui
or org.eclipse.jdt.ui
bundle. Based on that, common vector-graphics editing software may be used to further adapt color, form and style of existing icons (e.g. Inkscape https://inkscape.org/en/).
15.2.1.3. High Resolution Icons
With the Neon release, Eclipse SWT introduced explicit support for high-DPI monitors (see https://www.eclipse.org/eclipse/news/4.6/platform.php#swt-autoscale). In order to provide a good user experience, we want to provide high-DPI support for as many of our icons as possible. For that, it suffices to simply provide an alternative resource with higher resolution by appending the prefix @2x to its name (e.g. class.png
and class@2x.png
). Code-wise, no adjustments are required. In case of copied Eclipse Platform Icons, most of the time a corresponding 2x-version can be obtained from the original source. In case of N4JS Specific Icons, we export all icons in the resolutions 16x16 and 32x32. For that, it is of particular importance to make sure that the scaling is done in accordance with the native resolution (cf. pixel perfect scaling, also see https://en.wikipedia.org/wiki/Native_resolution).