Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.elexis.util
Class SWTHelper

java.lang.Object
  extended by ch.elexis.util.SWTHelper

public class SWTHelper
extends java.lang.Object

statische Hilfsfunktionen für SWT-Objekte


Nested Class Summary
static interface SWTHelper.IControlProvider
           
static class SWTHelper.SimpleDialog
           
 
Constructor Summary
SWTHelper()
           
 
Method Summary
static void addSeparator(Composite parent)
          Convenience method to add a separator bar to the composite.
static void alert(java.lang.String title, java.lang.String message)
          Eine Alertbox anzeigen (synchron)
static boolean askYesNo(java.lang.String title, java.lang.String message)
          Eine mit Ja oder Nein zu beantwortende Frage im UI-Thread zeigen
static java.lang.Boolean askYesNoCancel(java.lang.String title, java.lang.String message)
          Eine mit Ja, Nein oder Abbrechen zu beantwortende Frage im UI-Thread zeigen
static boolean blameEmptyString(java.lang.String test, java.lang.String name)
          Check whether the String is empty and give an error message if so
static void center(Shell child)
          Ein Objekt auf dem Bildschirm zentrieren.
static void center(Shell parent, Composite child)
          Ein Objekt innerhalb des parents zentrieren
static void center(Shell parent, Shell child)
          Ein Objekt innerhalb des parents zentrieren
static java.awt.Font createAWTFontFromSWTFont(Font swtFont)
           
static Label createHyperlink(Composite parent, java.lang.String text, IHyperlinkListener lis)
          Return a Label that acts as a hyperlink
static LabeledInputField createLabeledField(Composite parent, java.lang.String label, LabeledInputField.Typ typ)
           
static TableWrapLayout createTableWrapLayout(int numColumns, boolean makeColumnsEqualWidth)
          Constructor wrapper for TableWrapLayout, so that parameters are identical to GridLayout(numColumns, makeColumnsEqualWidth)
static Text createText(Composite parent, int lines, int flags)
          Create a multiline text widget with a specified height in lines (calculated with the Text's default font)
static Text createText(FormToolkit tk, Composite parent, int lines, int flags)
           
static GridData fillGrid(Composite parent, int cols)
           
static Color getContrast(Color col)
          Return a color that contrasts optimally to the given color
static GridData getFillGridData()
          Shortcut for getFillGridData(1,true,1,true);
static GridData getFillGridData(int hSpan, boolean hFill, int vSpan, boolean vFill)
          Ein GridData-Objekt erzeugen, das den horizontalen und/oder vertikalen Freiraum ausfüllt.
static TableWrapData getFillTableWrapData(int hSpan, boolean hFill, int vSpan, boolean vFill)
          Ein TableWrapDAta-Objekt erzeugen, das den horizontalen und/oder vertikalen Freiraum ausfüllt.
static Point getStringBounds(Composite c, java.lang.String s)
           
static void reloadViewPart(java.lang.String viewID)
          This method "reloads" a view, by closing and opening it.
static GridData setGridDataHeight(Control control, int lines, boolean fillHorizontal)
          Set a GridData to the given Control that sets the specified height in lines calculated with the control's current font.
static void setSelectOnFocus(Text text)
          Adds a FocusListener to text so that the text is selected as soon as the control gets the focus.
static void showError(java.lang.String title, java.lang.String message)
          Eine Standard-Fehlermeldung asynchron im UI-Thread zeigen
static void showError(java.lang.String logHeader, java.lang.String title, java.lang.String message)
          Eine Standard-Fehlermeldung asynchron zeigen und loggen
static void showInfo(java.lang.String title, java.lang.String message)
          Eine Standard-Infomeldung asynchron zeigen
static int size(Rectangle r)
           
static void writeCentered(GC gc, java.lang.String text, Rectangle bounds)
          Einen Text zentriert in ein Rechteck schreiben
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SWTHelper

public SWTHelper()
Method Detail

center

public static void center(Shell parent,
                          Composite child)
Ein Objekt innerhalb des parents zentrieren


center

public static void center(Shell parent,
                          Shell child)
Ein Objekt innerhalb des parents zentrieren


center

public static void center(Shell child)
Ein Objekt auf dem Bildschirm zentrieren. Robust. Sollte nie eine Exception werfen. Ändert im Zweifelsfall nichts an der Position.


writeCentered

public static void writeCentered(GC gc,
                                 java.lang.String text,
                                 Rectangle bounds)
Einen Text zentriert in ein Rechteck schreiben


alert

public static void alert(java.lang.String title,
                         java.lang.String message)
Eine Alertbox anzeigen (synchron)


showError

public static void showError(java.lang.String title,
                             java.lang.String message)
Eine Standard-Fehlermeldung asynchron im UI-Thread zeigen

Parameters:
title - Titel
message - Nachricht

showError

public static void showError(java.lang.String logHeader,
                             java.lang.String title,
                             java.lang.String message)
Eine Standard-Fehlermeldung asynchron zeigen und loggen

Parameters:
title - Titel
message - Nachricht

showInfo

public static void showInfo(java.lang.String title,
                            java.lang.String message)
Eine Standard-Infomeldung asynchron zeigen

Parameters:
title - Titel
message - Nachricht

askYesNo

public static boolean askYesNo(java.lang.String title,
                               java.lang.String message)
Eine mit Ja oder Nein zu beantwortende Frage im UI-Thread zeigen

Parameters:
title - Titel
message - Nachricht
Returns:
true: User hat Ja geklickt

askYesNoCancel

public static java.lang.Boolean askYesNoCancel(java.lang.String title,
                                               java.lang.String message)
Eine mit Ja, Nein oder Abbrechen zu beantwortende Frage im UI-Thread zeigen

Parameters:
title - Titel
message - Nachricht
Returns:
true: User hat Ja geklickt

getFillGridData

public static GridData getFillGridData()
Shortcut for getFillGridData(1,true,1,true);

Returns:

getFillGridData

public static GridData getFillGridData(int hSpan,
                                       boolean hFill,
                                       int vSpan,
                                       boolean vFill)
Ein GridData-Objekt erzeugen, das den horizontalen und/oder vertikalen Freiraum ausfüllt.

Parameters:
horizontal - true, wenn horizontal gefüllt werden soll
vertical - true, wenn vertikal gefüllt werden soll.
Returns:
ein neu erzeugtes, direkt verwendbares GridData-Objekt

fillGrid

public static GridData fillGrid(Composite parent,
                                int cols)

setGridDataHeight

public static GridData setGridDataHeight(Control control,
                                         int lines,
                                         boolean fillHorizontal)
Set a GridData to the given Control that sets the specified height in lines calculated with the control's current font.

Parameters:
control - the control
lines - reuqested height of the control in lines
fillHorizontal - true if the control should require all horizontal space
Returns:
the GridData (that is already set to the control)

createTableWrapLayout

public static TableWrapLayout createTableWrapLayout(int numColumns,
                                                    boolean makeColumnsEqualWidth)
Constructor wrapper for TableWrapLayout, so that parameters are identical to GridLayout(numColumns, makeColumnsEqualWidth)


getFillTableWrapData

public static TableWrapData getFillTableWrapData(int hSpan,
                                                 boolean hFill,
                                                 int vSpan,
                                                 boolean vFill)
Ein TableWrapDAta-Objekt erzeugen, das den horizontalen und/oder vertikalen Freiraum ausfüllt.

Parameters:
horizontal - true, wenn horizontal gefüllt werden soll
vertical - true, wenn vertikal gefüllt werden soll.
Returns:
ein neu erzeugtes, direkt verwendbares GridData-Objekt

getContrast

public static Color getContrast(Color col)
Return a color that contrasts optimally to the given color

Parameters:
col - an SWT Color
Returns:
black if col was rather bright, white if col was rather dark.

createHyperlink

public static Label createHyperlink(Composite parent,
                                    java.lang.String text,
                                    IHyperlinkListener lis)
Return a Label that acts as a hyperlink

Parameters:
parent - parent control
text - text to display
lis - hyperlink listener that is called on Mouse click
Returns:
a Label

createText

public static Text createText(Composite parent,
                              int lines,
                              int flags)
Create a multiline text widget with a specified height in lines (calculated with the Text's default font)

Parameters:
parent - parent composite
lines - requested height of the text field
flags - creation flags (SWT.MULTI and SWT.WRAP are added automatocally)
Returns:
a Text control

createText

public static Text createText(FormToolkit tk,
                              Composite parent,
                              int lines,
                              int flags)

createLabeledField

public static LabeledInputField createLabeledField(Composite parent,
                                                   java.lang.String label,
                                                   LabeledInputField.Typ typ)

blameEmptyString

public static boolean blameEmptyString(java.lang.String test,
                                       java.lang.String name)
Check whether the String is empty and give an error message if so

Parameters:
test - the String to test
name - the name for the String
Returns:
false if it was empty

setSelectOnFocus

public static void setSelectOnFocus(Text text)
Adds a FocusListener to text so that the text is selected as soon as the control gets the focus. The selection is cleared when the focus is lost.

Parameters:
text - the Text control to add a focus listener to

createAWTFontFromSWTFont

public static java.awt.Font createAWTFontFromSWTFont(Font swtFont)

size

public static int size(Rectangle r)

getStringBounds

public static Point getStringBounds(Composite c,
                                    java.lang.String s)

addSeparator

public static void addSeparator(Composite parent)
Convenience method to add a separator bar to the composite.

The parent composite must have a GridLayout. The separator bar will span all columns of the parent grid layout.

Code from: http://www.softwarerevolution.com/blueprints/ The Software Revolution Inc. by Thomas Holland under GPLv3

Parameters:
parent - Composite

reloadViewPart

public static void reloadViewPart(java.lang.String viewID)
This method "reloads" a view, by closing and opening it. It is the programmatical equivalent to closing a view and then select Open/View/and the view ID. This method should NOT be used, as it identifies an architectural problem. The UI itself should support the respective update.

Parameters:
viewID -

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis