use of org.eclipse.wb.internal.core.nls.model.AbstractSource 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.nls.model.AbstractSource in project windowbuilder by eclipse.
the class GenericPropertyImpl method process_NLSSupport_specialFunctionality.
private boolean process_NLSSupport_specialFunctionality(final Object value) throws Exception {
if (value == UNKNOWN_VALUE) {
return false;
}
if (!NlsSupport.isStringProperty(this)) {
return false;
}
final NlsSupport support = NlsSupport.get(m_javaInfo);
// check if key name is used
if (value instanceof String) {
String stringValue = (String) value;
String keyPrefix = m_javaInfo.getDescription().getToolkit().getPreferences().getString(IPreferenceConstants.P_NLS_KEY_AS_VALUE_PREFIX);
if (!StringUtils.isEmpty(keyPrefix) && stringValue.startsWith(keyPrefix)) {
final String key = stringValue.substring(keyPrefix.length());
final AbstractSource source = support.getKeySource(key);
if (source != null) {
ExecutionUtils.run(m_javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
source.useKey(m_this, key);
}
});
return true;
}
}
}
// check for externalized String property
{
final Expression expression = getExpression();
if (expression != null) {
if (support.isExternalized(expression)) {
ExecutionUtils.run(m_javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
String string = value == UNKNOWN_VALUE ? null : (String) value;
support.setValue(expression, string);
}
});
return true;
}
}
}
// no NLS
return false;
}
use of org.eclipse.wb.internal.core.nls.model.AbstractSource in project windowbuilder by eclipse.
the class ModernEclipseSource method getPossibleSources.
/**
* Return "possible" sources that exist in given package.
*
* "Possible" source is source that exists in current package, but is not used in current unit. We
* show "possible" sources only if there are no "real" sources.
*/
public static List<AbstractSource> getPossibleSources(JavaInfo root, IPackageFragment pkg) throws Exception {
List<AbstractSource> sources = Lists.newArrayList();
// check that there is "NLS" type
IType typeNLS = root.getEditor().getJavaProject().findType("org.eclipse.osgi.util.NLS");
if (typeNLS != null) {
IJavaElement[] packageElements = pkg.getChildren();
for (int i = 0; i < packageElements.length; i++) {
ICompilationUnit unit = (ICompilationUnit) packageElements[i];
IType type = unit.findPrimaryType();
if (type != null) {
// check that type is is successor of NLS
if (CodeUtils.isSuccessorOf(type, typeNLS)) {
try {
String accessorClassName = type.getFullyQualifiedName();
AbstractSource source = new ModernEclipseSource(root, accessorClassName, null);
sources.add(source);
} catch (Throwable e) {
DesignerPlugin.log(e);
}
}
}
}
}
return sources;
}
use of org.eclipse.wb.internal.core.nls.model.AbstractSource in project windowbuilder by eclipse.
the class DirectSource method getPossibleSources.
/**
* Return "possible" sources that exist in given package.
*
* "Possible" source is source that exists in current package, but is not used in current unit. We
* show "possible" sources only if there are no "real" sources.
*/
public static List<AbstractSource> getPossibleSources(JavaInfo root, IPackageFragment pkg) throws Exception {
List<AbstractSource> sources = Lists.newArrayList();
//
Object[] nonJavaResources = pkg.getNonJavaResources();
for (int i = 0; i < nonJavaResources.length; i++) {
Object o = nonJavaResources[i];
if (o instanceof IFile) {
IFile file = (IFile) o;
String fileName = file.getName();
// we need .properties files
if (!fileName.endsWith(".properties")) {
continue;
}
// we need only main (default) bundles
if (fileName.indexOf('_') != -1) {
continue;
}
// check first line for required comment
InputStream is = file.getContents(true);
String firstLine = IOUtils2.readFirstLine(is);
if (firstLine == null || !firstLine.startsWith("#" + BUNDLE_COMMENT)) {
continue;
}
// OK, this is probably correct source
try {
String bundleName = pkg.getElementName() + "." + StringUtils.substring(fileName, 0, -".properties".length());
AbstractSource source = new DirectSource(root, bundleName);
sources.add(source);
} catch (Throwable e) {
DesignerPlugin.log(e);
}
}
}
//
return sources;
}
use of org.eclipse.wb.internal.core.nls.model.AbstractSource in project windowbuilder by eclipse.
the class NlsSupport method getValue.
/**
* Supports conversion of {@link Expression} into NLS value during parsing, i.e. when no root
* {@link JavaInfo} is known.
*
* @return the {@link String} value or <code>null</code> if given {@link Expression} does not
* represent any known NLS pattern.
*/
public static String getValue(JavaInfo component, Expression expression) throws Exception {
for (SourceDescription sourceDescription : getSourceDescriptions(component)) {
try {
List<AbstractSource> sources = Lists.newArrayList();
AbstractSource source = sourceDescription.getSource(component, null, expression, sources);
if (source != null) {
setSource(expression, source);
return source.getValue(expression);
}
} catch (Throwable e) {
}
}
return null;
}
Aggregations