use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class GeographicalNamePage method createSpellingGroup.
private void createSpellingGroup(Composite parent, PropertyFunctionDefinition function) {
// define Spelling Group composite
Group configurationGroup = new Group(parent, SWT.NONE);
configurationGroup.setText(SPELLING_GROUP_TEXT);
configurationGroup.setLayout(GridLayoutFactory.fillDefaults().create());
GridData configurationAreaGD = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
configurationAreaGD.grabExcessHorizontalSpace = true;
configurationAreaGD.grabExcessVerticalSpace = true;
configurationGroup.setLayoutData(configurationAreaGD);
configurationGroup.setSize(configurationGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT));
configurationGroup.setFont(parent.getFont());
final Composite configurationComposite = new Composite(configurationGroup, SWT.NONE);
GridData configurationLayoutData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
configurationLayoutData.grabExcessHorizontalSpace = true;
configurationComposite.setLayoutData(configurationLayoutData);
GridLayout spellingLayout = new GridLayout();
spellingLayout.numColumns = 2;
spellingLayout.makeColumnsEqualWidth = false;
spellingLayout.marginWidth = 0;
spellingLayout.marginHeight = 0;
spellingLayout.horizontalSpacing = 8;
configurationComposite.setLayout(spellingLayout);
// or get the known information about the cell to be edited
if (getSpellings() == null || getSpellings().size() == 0) {
spellings = new ArrayList<SpellingType>();
ListMultimap<String, ? extends Entity> source = getWizard().getUnfinishedCell().getSource();
if (source != null) {
for (Entity item : source.values()) {
int i = 0;
Definition<?> entity = item.getDefinition().getDefinition();
if (entity instanceof PropertyDefinition) {
SpellingType sp = new SpellingType((PropertyDefinition) entity);
// set the same script value if you had a value before
if (scripts != null && i < scripts.size()) {
sp.setScript(scripts.get(i));
} else {
// else set the default value
sp.setScript(ISO_CODE_ENG);
}
// before
if (trans != null && i < trans.size()) {
sp.setTransliteration(trans.get(i));
} else {
// else set the default value
sp.setTransliteration("");
}
spellings.add(sp);
}
i++;
}
}
} else {
// after initialization of the spellings
ArrayList<PropertyDefinition> temp = new ArrayList<PropertyDefinition>();
ArrayList<SpellingType> templist = getSpellings();
// we have to create a new spellings list because a live
// modification of the combo box input would occur an error
spellings = new ArrayList<SpellingType>();
for (int i = 0; i < templist.size(); i++) {
temp.add(templist.get(i).getProperty());
if (scripts != null && trans != null && i < scripts.size() && scripts.get(i) != null && i < trans.size() && trans.get(i) != null) {
templist.get(i).setScript(scripts.get(i));
templist.get(i).setTransliteration(trans.get(i));
}
}
for (Entity item : getWizard().getUnfinishedCell().getSource().values()) {
Definition<?> entity = item.getDefinition().getDefinition();
if (entity instanceof PropertyDefinition) {
PropertyDefinition propDef = (PropertyDefinition) entity;
for (SpellingType st : templist) {
// transliteration) to the new spellings list
if (propDef.equals(st.getProperty())) {
spellings.add(st);
}
}
// with default values
if (!temp.contains(propDef)) {
SpellingType sp = new SpellingType(propDef);
sp.setScript(ISO_CODE_ENG);
sp.setTransliteration("");
spellings.add(sp);
}
}
}
}
// Text
final Label nameSpellingTextLabel = new Label(configurationComposite, SWT.NONE);
nameSpellingTextLabel.setText(SPELLING_TEXT_LABEL_TEXT);
this.nameSpellingText = new ComboViewer(configurationComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
this.nameSpellingText.getControl().setLayoutData(configurationLayoutData);
this.nameSpellingText.setContentProvider(ArrayContentProvider.getInstance());
this.nameSpellingText.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof SpellingType) {
return ((SpellingType) element).getProperty().getName().getLocalPart();
}
return super.getText(element);
}
});
this.nameSpellingText.setInput(spellings);
// default set selection to the first element on the list
if (!spellings.isEmpty()) {
this.activeSpelling = spellings.iterator().next();
this.nameSpellingText.setSelection(new StructuredSelection(activeSpelling));
}
// set active spelling
nameSpellingText.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (!event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection) {
SpellingType selected = (SpellingType) ((IStructuredSelection) event.getSelection()).getFirstElement();
String script = ISO_CODE_ENG;
// $NON-NLS-1$
String transliteration = "";
activeSpelling = selected;
if (activeSpelling.getScript() != null && // $NON-NLS-1$
!activeSpelling.getScript().equals(""))
script = activeSpelling.getScript();
if (activeSpelling.getTransliteration() != null && // $NON-NLS-1$
!activeSpelling.getTransliteration().equals(""))
transliteration = activeSpelling.getTransliteration();
nameSpellingScript.setText(script);
nameSpellingTransliteration.setText(transliteration);
}
}
});
// Script
final Label nameSpellingScriptLabel = new Label(configurationComposite, SWT.NONE);
nameSpellingScriptLabel.setText(SCRIPT_LABEL_TEXT);
configureParameterLabel(nameSpellingScriptLabel, PROPERTY_SCRIPT, function);
this.nameSpellingScript = new Text(configurationComposite, SWT.BORDER | SWT.SINGLE);
this.nameSpellingScript.setLayoutData(configurationLayoutData);
this.nameSpellingScript.setEnabled(true);
this.nameSpellingScript.setTabs(0);
// $NON-NLS-1$
String script = "eng";
// read script from the active spelling
if (activeSpelling != null && activeSpelling.getScript() != null)
script = activeSpelling.getScript();
// set default value for script
this.nameSpellingScript.setText(script);
this.nameSpellingScript.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
activeSpelling.setScript(nameSpellingScript.getText());
}
});
// Transliteration
final Label nameSpellingTransliterationLabel = new Label(configurationComposite, SWT.NONE);
nameSpellingTransliterationLabel.setText(TRANSLITERATION_LABEL_TEXT);
configureParameterLabel(nameSpellingTransliterationLabel, PROPERTY_TRANSLITERATION, function);
this.nameSpellingTransliteration = new Text(configurationComposite, SWT.BORDER | SWT.SINGLE);
this.nameSpellingTransliteration.setLayoutData(configurationLayoutData);
this.nameSpellingTransliteration.setEnabled(true);
this.nameSpellingTransliteration.setTabs(0);
// read script from the active spelling
// $NON-NLS-1$
String transliteration = "";
if (activeSpelling != null && activeSpelling.getTransliteration() != null)
transliteration = activeSpelling.getTransliteration();
// set default value for transliteration
this.nameSpellingTransliteration.setText(transliteration);
this.nameSpellingTransliteration.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
activeSpelling.setTransliteration(nameSpellingTransliteration.getText());
}
});
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class SequentialIDParameterPage method createContent.
/**
* @see HaleWizardPage#createContent(Composite)
*/
@Override
protected void createContent(Composite page) {
page.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).spacing(10, 8).create());
Label label;
GridDataFactory labelLayout = GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER);
GridDataFactory controlLayout = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
// select sequence type
if (getParametersToHandle().containsKey(PARAM_SEQUENCE)) {
label = new Label(page, SWT.NONE);
label.setText("Sequence");
labelLayout.applyTo(label);
sequence = new ComboViewer(page);
sequence.setContentProvider(EnumContentProvider.getInstance());
sequence.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Sequence) {
switch((Sequence) element) {
case overall:
return "Over all sequential IDs";
case type:
return "Per target instance type";
}
}
return super.getText(element);
}
});
sequence.setInput(Sequence.class);
controlLayout.applyTo(sequence.getControl());
Sequence initialValue = Sequence.valueOf(getOptionalInitialValue(PARAM_SEQUENCE, new ParameterValue(Sequence.type.name())).as(String.class));
sequence.setSelection(new StructuredSelection(initialValue));
sequence.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateStatus();
}
});
}
// specify prefix
if (getParametersToHandle().containsKey(PARAM_PREFIX)) {
label = new Label(page, SWT.NONE);
label.setText("Prefix");
labelLayout.applyTo(label);
prefix = new Text(page, SWT.SINGLE | SWT.BORDER);
controlLayout.applyTo(prefix);
prefix.setText(getOptionalInitialValue(PARAM_PREFIX, new ParameterValue("")).as(String.class));
prefix.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateStatus();
}
});
ContentProposalAdapter adapter = new ContentProposalAdapter(prefix, new TextContentAdapter(), contentProposalProvider, ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
adapter.setAutoActivationDelay(0);
final ControlDecoration infoDeco = new ControlDecoration(prefix, SWT.TOP | SWT.LEFT);
infoDeco.setDescriptionText("Type Ctrl+Space for project variable content assistance");
infoDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
infoDeco.setMarginWidth(2);
}
// specify suffix
if (getParametersToHandle().containsKey(PARAM_SUFFIX)) {
label = new Label(page, SWT.NONE);
label.setText("Suffix");
labelLayout.applyTo(label);
suffix = new Text(page, SWT.SINGLE | SWT.BORDER);
controlLayout.applyTo(suffix);
suffix.setText(getOptionalInitialValue(PARAM_SUFFIX, new ParameterValue("")).as(String.class));
suffix.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateStatus();
}
});
ContentProposalAdapter adapter = new ContentProposalAdapter(suffix, new TextContentAdapter(), contentProposalProvider, ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
adapter.setAutoActivationDelay(0);
final ControlDecoration infoDeco = new ControlDecoration(suffix, SWT.TOP | SWT.LEFT);
infoDeco.setDescriptionText("Type Ctrl+Space for project variable content assistance");
infoDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
infoDeco.setShowOnlyOnFocus(true);
}
// show example
if (sequence != null && prefix != null && suffix != null) {
label = new Label(page, SWT.NONE);
label.setText("Example");
labelLayout.applyTo(label);
example = new Label(page, SWT.NONE);
example.setFont(JFaceResources.getTextFont());
controlLayout.applyTo(example);
// error decoration
exampleDecoration = new ControlDecoration(example, SWT.LEFT | SWT.TOP, page);
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
exampleDecoration.setImage(fieldDecoration.getImage());
exampleDecoration.hide();
}
updateStatus();
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class PresetsSource method createControls.
/**
* @see ImportSource#createControls(Composite)
*/
@Override
public void createControls(Composite parent) {
GridLayoutFactory parentLayout = GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false);
parentLayout.applyTo(parent);
GridDataFactory labelData = //
GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER);
GridDataFactory controlData = //
GridDataFactory.swtDefaults().align(SWT.FILL, //
SWT.CENTER).grab(true, false);
// preset label
Label label = new Label(parent, SWT.NONE);
label.setText("Select preset:");
labelData.applyTo(label);
// preset selector
selector = new SchemaPresetSelector(parent);
selector.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (description != null) {
SchemaPreset schema = selector.getSelectedObject();
if (schema != null && schema.getDescription() != null) {
description.setText(schema.getDescription());
} else {
description.setText("");
}
}
updateState(true);
}
});
controlData.applyTo(selector.getControl());
// skipper
Composite empty = new Composite(parent, SWT.NONE);
GridDataFactory.swtDefaults().hint(1, 1).applyTo(empty);
// description label
description = new Label(parent, SWT.WRAP);
GridDataFactory.fillDefaults().grab(true, true).applyTo(description);
// preset label
label = new Label(parent, SWT.NONE);
label.setText("Import as");
labelData.applyTo(label);
// create provider combo
ComboViewer providers = createProviders(parent);
controlData.applyTo(providers.getControl());
// prevent selector appearing very small
parent.pack();
// initial state update
updateState(true);
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class JDBCSource method createControls.
@Override
public void createControls(Composite page) {
page.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
GridDataFactory labelData = GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER);
GridDataFactory compData = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
// driver
Label labelDriver = new Label(page, SWT.NONE);
labelDriver.setText("Driver");
labelData.applyTo(labelDriver);
driver = JDBCComponents.createDriverSelector(page);
compData.applyTo(driver.getControl());
// driver selection listener
driver.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateState(false);
}
});
// host
Label labelHost = new Label(page, SWT.NONE);
labelHost.setText("Host(:Port)");
labelData.applyTo(labelHost);
host = new Text(page, SWT.BORDER | SWT.SINGLE);
compData.applyTo(host);
host.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateState(false);
}
});
// database
Label labelDatabase = new Label(page, SWT.NONE);
labelDatabase.setText("Database");
labelData.applyTo(labelDatabase);
database = new Text(page, SWT.BORDER | SWT.SINGLE);
compData.applyTo(database);
database.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateState(false);
}
});
// preset label
Label providerLabel = new Label(page, SWT.NONE);
providerLabel.setText("Import as");
labelData.applyTo(providerLabel);
// create provider combo
ComboViewer providers = createProviders(page);
compData.applyTo(providers.getControl());
// content type is set through source registration
// initial state update
updateState(true);
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class JDBCTarget method createControls.
@Override
public void createControls(Composite page) {
page.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
GridDataFactory labelData = GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER);
GridDataFactory compData = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
// driver
Label labelDriver = new Label(page, SWT.NONE);
labelDriver.setText("Driver");
labelData.applyTo(labelDriver);
driver = JDBCComponents.createDriverSelector(page);
compData.applyTo(driver.getControl());
// driver selection listener
driver.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateState();
}
});
// host
Label labelHost = new Label(page, SWT.NONE);
labelHost.setText("Host(:Port)");
labelData.applyTo(labelHost);
host = new Text(page, SWT.BORDER | SWT.SINGLE);
compData.applyTo(host);
host.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateState();
}
});
// database
Label labelDatabase = new Label(page, SWT.NONE);
labelDatabase.setText("Database");
labelData.applyTo(labelDatabase);
database = new Text(page, SWT.BORDER | SWT.SINGLE);
compData.applyTo(database);
database.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateState();
}
});
// initial state update
updateState();
}
Aggregations