use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.
the class StringPropertyDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
// value
{
m_valueText = new Text(area, SWT.BORDER | SWT.MULTI | SWT.WRAP);
GridDataFactory.create(m_valueText).grab().hintC(80, 8).fill();
// initial value
ExecutionUtils.runLog(new RunnableEx() {
@Override
public void run() throws Exception {
Object value = m_property.getValue();
if (value instanceof String) {
m_valueText.setText((String) value);
}
}
});
// handle Ctrl+Enter as OK
m_valueText.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.stateMask == SWT.CTRL && e.keyCode == SWT.CR) {
okPressed();
}
}
});
}
// localization
if (m_genericProperty != null) {
Group group = new Group(area, SWT.NONE);
GridDataFactory.create(group).fill();
GridLayoutFactory.create(group);
group.setText(ModelMessages.StringPropertyDialog_localizationGroup);
// flag of using existing NLS key
{
m_nlsButton = new Button(group, SWT.CHECK);
m_nlsButton.setText(ModelMessages.StringPropertyDialog_localizationUseExisting);
m_nlsButton.setEnabled(!m_editableSupport.getEditableSources().isEmpty());
// initial state
ExecutionUtils.runLog(new RunnableEx() {
@Override
public void run() throws Exception {
m_nlsButton.setSelection(m_support.isExternalized(m_genericProperty.getExpression()));
}
});
// add selection listener
m_nlsButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UiUtils.changeControlEnable(m_nlsComposite, m_nlsButton.getSelection());
updateSourceKey();
}
});
}
// NLS container
{
m_nlsComposite = new Composite(group, SWT.NONE);
GridDataFactory.create(m_nlsComposite).grab().fill();
GridLayoutFactory.create(m_nlsComposite).columns(3).noMargins();
// source
{
new Label(m_nlsComposite, SWT.NONE).setText(ModelMessages.StringPropertyDialog_localizationSourceLabel);
//
m_nlsSourceText = new Text(m_nlsComposite, SWT.BORDER | SWT.READ_ONLY);
GridDataFactory.create(m_nlsSourceText).grabH().fillH();
}
// browse for source/key
{
Button browseButton = new Button(m_nlsComposite, SWT.NONE);
GridDataFactory.create(browseButton).hintHU(50).spanV(2).fill();
browseButton.setText(ModelMessages.StringPropertyDialog_localizationBrowse);
// add selection listener
browseButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
StringPropertyKeyDialog keyDialog = new StringPropertyKeyDialog(getShell(), m_editableSupport, m_selectedEditSource, m_selectedKey, m_locale);
if (keyDialog.open() == OK) {
m_selectedEditSource = keyDialog.getSelectedSource();
m_selectedKey = keyDialog.getSelectedKey();
updateSourceKey();
}
}
});
}
// key
{
new Label(m_nlsComposite, SWT.NONE).setText(ModelMessages.StringPropertyDialog_localizationKeyLabel);
//
m_nlsKeyText = new Text(m_nlsComposite, SWT.BORDER | SWT.READ_ONLY);
GridDataFactory.create(m_nlsKeyText).grabH().fillH();
}
}
// update enable state for NLS container
UiUtils.changeControlEnable(m_nlsComposite, m_nlsButton.getSelection());
}
//
return area;
}
use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.
the class StringPropertyDialog method okPressed.
@Override
protected void okPressed() {
final String value = m_valueText.getText();
if (m_component != null) {
ExecutionUtils.run(m_component, new RunnableEx() {
@Override
public void run() throws Exception {
if (m_genericProperty != null) {
// replace with StringLiteral
if (!m_nlsButton.getSelection() && m_initialSource != null) {
m_initialSource.replace_toStringLiteral(m_genericProperty, value);
return;
}
// use different key in different source
if (m_nlsButton.getSelection()) {
AbstractSource selectedSource = m_support.getAttachedSource(m_editableSupport, m_selectedEditSource);
selectedSource.useKey(m_genericProperty, m_selectedKey);
if (isValueDifferentThanInSource()) {
m_property.setValue(value);
}
return;
}
}
m_property.setValue(value);
}
/**
* @return <code>true</code> if value in NLS source and in editor is not same, so user
* changed it and we should update NLS source.
*/
private boolean isValueDifferentThanInSource() {
String valueInSource = m_selectedEditSource.getValue(m_locale, m_selectedKey);
return !value.equals(valueInSource);
}
});
} else {
ExecutionUtils.runLog(new RunnableEx() {
@Override
public void run() throws Exception {
m_property.setValue(value);
}
});
}
// close dialog
super.okPressed();
}
use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.
the class MethodInvocationArgumentAccessor method setExpression.
@Override
public boolean setExpression(final JavaInfo javaInfo, final String source) throws Exception {
final List<String> defaultArguments = getMethodDescription(javaInfo).getDefaultArguments();
// modify expression
final MethodInvocation invocation = getMethodInvocation(javaInfo);
if (invocation != null) {
final AstEditor editor = javaInfo.getEditor();
final Expression oldArgumentExpression = getArgumentExpression(invocation);
final String argumentSource = source != null ? source : defaultArguments.get(m_index);
if (!isSameSource(editor, oldArgumentExpression, argumentSource)) {
ExecutionUtils.run(javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
editor.replaceExpression(oldArgumentExpression, argumentSource);
if (isDefaultArguments(javaInfo, invocation)) {
editor.removeEnclosingStatement(invocation);
}
}
});
}
} else if (source != null) {
ExecutionUtils.run(javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
String argumentsSource = getNewInvocationArguments();
javaInfo.addMethodInvocation(m_methodSignature, argumentsSource);
}
private String getNewInvocationArguments() {
List<String> arguments = Lists.newArrayList(defaultArguments);
arguments.set(m_index, source);
return StringUtils.join(arguments.iterator(), ", ");
}
});
}
// success
return true;
}
use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.
the class StringsAddPropertyEditor method setItems.
/**
* Sets new items into given {@link Property}.
*/
void setItems(Property _property, final String[] items) throws Exception {
final JavaInfo javaInfo = ((JavaProperty) _property).getJavaInfo();
ExecutionUtils.run(javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
setItems0(items, javaInfo);
}
});
}
use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.
the class InvocationChildAssociationAccessor method setExpression.
@Override
public boolean setExpression(JavaInfo javaInfo, String source) throws Exception {
// if given source is "null", use default source (but it also can be "null")
final String newSource;
if (source != null) {
newSource = source;
} else {
newSource = m_defaultSource;
}
// if we have source to replace current, do this
if (newSource != null) {
final AstEditor editor = javaInfo.getEditor();
final Expression oldExpression = getExpression(javaInfo);
if (!editor.getSource(oldExpression).equals(source)) {
ExecutionUtils.run(javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
editor.replaceExpression(oldExpression, newSource);
}
});
return true;
}
}
// no changes
return false;
}
Aggregations