use of com.intellij.uiDesigner.lw.StringDescriptor in project intellij-community by JetBrains.
the class StringEditorDialog method getDescriptor.
/**
* @return edited descriptor. If initial descriptor was <code>null</code>
* and user didn't change anything then this method returns <code>null</code>.
*/
@Nullable
StringDescriptor getDescriptor() {
if (myForm.myRbString.isSelected()) {
// plain value
final String value = myForm.myTfValue.getText();
if (myValue == null && value.length() == 0) {
return null;
} else {
final StringDescriptor stringDescriptor = StringDescriptor.create(value);
stringDescriptor.setNoI18n(myForm.myNoI18nCheckbox.isSelected());
return stringDescriptor;
}
} else {
// bundled value
final String bundleName = myForm.myTfBundleName.getText();
final String key = myForm.myTfKey.getText();
return new StringDescriptor(bundleName, key);
}
}
use of com.intellij.uiDesigner.lw.StringDescriptor in project intellij-community by JetBrains.
the class StringPropertyCodeGenerator method generateCustomSetValue.
public boolean generateCustomSetValue(final LwComponent lwComponent, final InstrumentationClassFinder.PseudoClass componentClass, final LwIntrospectedProperty property, final GeneratorAdapter generator, final int componentLocal, final String formClassName) throws IOException, ClassNotFoundException {
final InstrumentationClassFinder.PseudoClass abstractButtonClass = componentClass.getFinder().loadClass(AbstractButton.class.getName());
final InstrumentationClassFinder.PseudoClass jLabelClass = componentClass.getFinder().loadClass(JLabel.class.getName());
if ("text".equals(property.getName()) && (abstractButtonClass.isAssignableFrom(componentClass) || jLabelClass.isAssignableFrom(componentClass))) {
final StringDescriptor propertyValue = (StringDescriptor) lwComponent.getPropertyValue(property);
if (propertyValue.getValue() != null) {
final SupportCode.TextWithMnemonic textWithMnemonic = SupportCode.parseText(propertyValue.getValue());
if (textWithMnemonic.myMnemonicIndex >= 0) {
generator.loadLocal(componentLocal);
generator.push(textWithMnemonic.myText);
generator.invokeVirtual(Type.getType(componentClass.getDescriptor()), new Method(property.getWriteMethodName(), Type.VOID_TYPE, new Type[] { Type.getType(String.class) }));
String setMnemonicMethodName;
if (abstractButtonClass.isAssignableFrom(componentClass)) {
setMnemonicMethodName = "setMnemonic";
} else {
setMnemonicMethodName = "setDisplayedMnemonic";
}
generator.loadLocal(componentLocal);
generator.push(textWithMnemonic.getMnemonicChar());
generator.invokeVirtual(Type.getType(componentClass.getDescriptor()), new Method(setMnemonicMethodName, Type.VOID_TYPE, new Type[] { Type.CHAR_TYPE }));
if (myHaveSetDisplayedMnemonicIndex) {
generator.loadLocal(componentLocal);
generator.push(textWithMnemonic.myMnemonicIndex);
generator.invokeVirtual(Type.getType(componentClass.getDescriptor()), new Method("setDisplayedMnemonicIndex", Type.VOID_TYPE, new Type[] { Type.INT_TYPE }));
}
return true;
}
} else {
Method method;
if (abstractButtonClass.isAssignableFrom(componentClass)) {
myClassesRequiringLoadButtonText.add(formClassName);
method = myLoadButtonTextMethod;
} else {
myClassesRequiringLoadLabelText.add(formClassName);
method = myLoadLabelTextMethod;
}
generator.loadThis();
generator.loadLocal(componentLocal);
generator.push(propertyValue.getBundleName());
generator.invokeStatic(myResourceBundleType, myGetBundleMethod);
generator.push(propertyValue.getKey());
generator.invokeVirtual(myResourceBundleType, myGetStringMethod);
generator.invokeVirtual(Type.getType("L" + formClassName + ";"), method);
return true;
}
}
return false;
}
use of com.intellij.uiDesigner.lw.StringDescriptor in project intellij-community by JetBrains.
the class I18nizeFormQuickFix method run.
public void run() {
final StringDescriptor descriptor = getStringDescriptorValue();
final Project project = myEditor.getProject();
PsiFile psiFile = myEditor.getPsiFile();
if (!JavaI18nizeQuickFixDialog.isAvailable(myEditor.getPsiFile())) {
return;
}
String initialValue = StringUtil.escapeStringCharacters(descriptor.getValue());
final JavaI18nizeQuickFixDialog dialog = new JavaI18nizeQuickFixDialog(project, psiFile, null, initialValue, null, false, false) {
protected String getDimensionServiceKey() {
return "#com.intellij.codeInsight.i18n.I18nizeQuickFixDialog_Form";
}
};
if (!dialog.showAndGet()) {
return;
}
if (!myEditor.ensureEditable()) {
return;
}
final Collection<PropertiesFile> propertiesFiles = dialog.getAllPropertiesFiles();
PropertiesFile aPropertiesFile = null;
for (PropertiesFile file : propertiesFiles) {
if (!FileModificationService.getInstance().prepareFileForWrite(file.getContainingFile()))
return;
if (aPropertiesFile == null) {
aPropertiesFile = file;
}
}
CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> {
try {
JavaI18nUtil.createProperty(project, propertiesFiles, dialog.getKey(), dialog.getValue());
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}), CodeInsightBundle.message("quickfix.i18n.command.name"), project);
// saving files is necessary to ensure correct reload of properties files by UI Designer
for (PropertiesFile file : propertiesFiles) {
FileDocumentManager.getInstance().saveDocument(PsiDocumentManager.getInstance(project).getDocument(file.getContainingFile()));
}
if (aPropertiesFile != null) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
String packageName = fileIndex.getPackageNameByDirectory(aPropertiesFile.getVirtualFile().getParent());
if (packageName != null) {
String bundleName;
if (packageName.length() > 0) {
bundleName = packageName + "." + aPropertiesFile.getResourceBundle().getBaseName();
} else {
bundleName = aPropertiesFile.getResourceBundle().getBaseName();
}
bundleName = bundleName.replace('.', '/');
try {
setStringDescriptorValue(new StringDescriptor(bundleName, dialog.getKey()));
} catch (Exception e) {
LOG.error(e);
}
myEditor.refreshAndSave(true);
}
}
}
use of com.intellij.uiDesigner.lw.StringDescriptor in project intellij-community by JetBrains.
the class Palette method writeInitialValuesElement.
/**
* Helper method
*/
private static void writeInitialValuesElement(@NotNull final Element itemElement, @NotNull final HashMap<String, StringDescriptor> name2value) {
LOG.assertTrue(ELEMENT_ITEM.equals(itemElement.getName()));
if (name2value.size() == 0) {
// do not append 'initial-values' subtag
return;
}
final Element initialValuesElement = new Element(ELEMENT_INITIAL_VALUES);
itemElement.addContent(initialValuesElement);
for (final Map.Entry<String, StringDescriptor> entry : name2value.entrySet()) {
final Element propertyElement = new Element(ELEMENT_PROPERTY);
initialValuesElement.addContent(propertyElement);
propertyElement.setAttribute(ATTRIBUTE_NAME, entry.getKey());
propertyElement.setAttribute(ATTRIBUTE_VALUE, entry.getValue().getValue());
}
}
use of com.intellij.uiDesigner.lw.StringDescriptor in project intellij-community by JetBrains.
the class IntroStringProperty method stringDescriptorFromValue.
private StringDescriptor stringDescriptorFromValue(final RadComponent component, final JComponent delegee) {
final StringDescriptor result;
if (SwingProperties.TEXT.equals(getName()) && (delegee instanceof JLabel)) {
final JLabel label = (JLabel) delegee;
result = StringDescriptor.create(mergeTextAndMnemonic(label.getText(), label.getDisplayedMnemonic(), label.getDisplayedMnemonicIndex()));
} else if (SwingProperties.TEXT.equals(getName()) && (delegee instanceof AbstractButton)) {
final AbstractButton button = (AbstractButton) delegee;
result = StringDescriptor.create(mergeTextAndMnemonic(button.getText(), button.getMnemonic(), button.getDisplayedMnemonicIndex()));
} else {
if (component != null) {
result = StringDescriptor.create((String) invokeGetter(component));
} else {
try {
result = StringDescriptor.create((String) myReadMethod.invoke(delegee, EMPTY_OBJECT_ARRAY));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
if (result != null) {
// in this branch, the StringDescriptor is always a plain string, so resolve() is not necessary
result.setResolvedValue(result.getValue());
}
return result;
}
Aggregations