private static void checkUpdateBindingFromText(final RadComponent component, final StringDescriptor value, final SupportCode.TextWithMnemonic textWithMnemonic) { if (component.isLoadingProperties()) { return; } // only generate binding from text if default locale is active (IDEADEV-9427) if (value.getValue() == null) { RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component); Locale locale = root.getStringDescriptorLocale(); if (locale != null && locale.getDisplayName().length() > 0) { return; } } BindingProperty.checkCreateBindingFromText(component, textWithMnemonic.myText); if (component.getDelegee() instanceof JLabel) { for(IProperty prop: component.getModifiedProperties()) { if (prop.getName().equals(SwingProperties.LABEL_FOR) && prop instanceof IntroComponentProperty) { ((IntroComponentProperty) prop).updateLabelForBinding(component); } } } }
@Nullable public static SupportCode.TextWithMnemonic getTextWithMnemonic(final Module module, final IComponent component) { if (module.isDisposed()) return null; IProperty prop = FormInspectionUtil.findProperty(component, SwingProperties.TEXT); if (prop != null) { Object propValue = prop.getPropertyValue(component); if (propValue instanceof StringDescriptor) { StringDescriptor descriptor = (StringDescriptor)propValue; String value; if (component instanceof RadComponent) { value = StringDescriptorManager.getInstance(module).resolve((RadComponent) component, descriptor); } else { value = StringDescriptorManager.getInstance(module).resolve(descriptor, null); } SupportCode.TextWithMnemonic twm = SupportCode.parseText(value); if (twm.myMnemonicIndex >= 0 && (FormInspectionUtil.isComponentClass(module, component, JLabel.class) || FormInspectionUtil.isComponentClass(module, component, AbstractButton.class))) { return twm; } } } return null; }
protected void checkComponentProperties(Module module, IComponent component, FormErrorCollector collector) { String value = FormInspectionUtil.getText(module, component); if (value == null) { return; } IProperty textProperty = FormInspectionUtil.findProperty(component, SwingProperties.TEXT); SupportCode.TextWithMnemonic twm = SupportCode.parseText(value); if (twm.myMnemonicIndex < 0 && twm.myText.length() > 0) { if (FormInspectionUtil.isComponentClass(module, component, AbstractButton.class)) { collector.addError(getID(), component, textProperty, UIDesignerBundle.message("inspection.missing.mnemonics.message", value), new MyEditorQuickFixProvider()); } else if (FormInspectionUtil.isComponentClass(module, component, JLabel.class)) { IProperty labelForProperty = FormInspectionUtil.findProperty(component, SwingProperties.LABEL_FOR); if (labelForProperty != null && !StringUtil.isEmpty((String) labelForProperty.getPropertyValue(component))) { collector.addError(getID(), component, textProperty, UIDesignerBundle.message("inspection.missing.mnemonics.message", value), new MyEditorQuickFixProvider()); } } } }
private void generateSetMnemonic(final String variable, final SupportCode.TextWithMnemonic textWithMnemonic, final Module module, @NonNls final String setMethodName, final Class controlClass) { startMethodCall(variable, setMethodName); pushVar("'" + textWithMnemonic.getMnemonicChar() + "'"); endMethod(); if(haveSetDisplayedMnemonic(controlClass, module)) { // generated code needs to be compatible with jdk 1.3 startMethodCall(variable, "setDisplayedMnemonicIndex"); push(textWithMnemonic.myMnemonicIndex); endMethod(); } }
private static MnemonicKey buildMnemonicKey(final SupportCode.TextWithMnemonic twm, final IComponent component) { List<Integer> exclusiveContainerStack = new ArrayList<Integer>(); IContainer parent = component.getParentContainer(); IComponent child = component; while(parent != null) { if (parent.areChildrenExclusive()) { exclusiveContainerStack.add(0, parent.indexOfComponent(child)); } child = parent; parent = parent.getParentContainer(); } return new MnemonicKey(twm.getMnemonicChar(), exclusiveContainerStack); }
public void run() { IProperty textProperty = FormInspectionUtil.findProperty(myComponent, SwingProperties.TEXT); StringDescriptor descriptor = (StringDescriptor) textProperty.getPropertyValue(myComponent); String value = StringDescriptorManager.getInstance(myComponent.getModule()).resolve(myComponent, descriptor); String[] variants = fillMnemonicVariants(SupportCode.parseText(value).myText); String result = Messages.showEditableChooseDialog(UIDesignerBundle.message("inspection.missing.mnemonics.quickfix.prompt"), UIDesignerBundle.message("inspection.missing.mnemonics.quickfix.title"), Messages.getQuestionIcon(), variants, variants [0], null); if (result != null) { if (!myEditor.ensureEditable()) { return; } FormInspectionUtil.updateStringPropertyValue(myEditor, myComponent, (IntroStringProperty)textProperty, descriptor, result); } }
private void generateSetMnemonic(final String variable, final SupportCode.TextWithMnemonic textWithMnemonic, final Module module, @NonNls final String setMethodName, final Class controlClass) { startMethodCall(variable, setMethodName); pushVar("'" + textWithMnemonic.getMnemonicChar() + "'"); endMethod(); if (haveSetDisplayedMnemonic(controlClass, module)) { // generated code needs to be compatible with jdk 1.3 startMethodCall(variable, "setDisplayedMnemonicIndex"); push(textWithMnemonic.myMnemonicIndex); endMethod(); } }
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; }
protected void setValueImpl(final RadComponent component, final StringDescriptor value) throws Exception { // 1. Put value into map if(value == null || (value.getBundleName() == null && !value.isNoI18n())) { getName2Descriptor(component).remove(getName()); } else{ getName2Descriptor(component).put(getName(), value); } // 2. Apply real string value to JComponent peer final JComponent delegee = component.getDelegee(); Locale locale = (Locale)component.getClientProperty(RadComponent.CLIENT_PROP_LOAD_TIME_LOCALE); if (locale == null) { RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component); if (root != null) { locale = root.getStringDescriptorLocale(); } } final String resolvedValue = (value != null && value.getValue() != null) ? value.getValue() : StringDescriptorManager.getInstance(component.getModule()).resolve(value, locale); if (value != null) { value.setResolvedValue(resolvedValue); } if(SwingProperties.TEXT.equals(getName())) { final SupportCode.TextWithMnemonic textWithMnemonic = SupportCode.parseText(resolvedValue); if (delegee instanceof JLabel) { final JLabel label = (JLabel)delegee; label.setText(textWithMnemonic.myText); if(textWithMnemonic.myMnemonicIndex != -1){ label.setDisplayedMnemonic(textWithMnemonic.getMnemonicChar()); label.setDisplayedMnemonicIndex(textWithMnemonic.myMnemonicIndex); } else{ label.setDisplayedMnemonic(0); } } else if (delegee instanceof AbstractButton) { final AbstractButton button = (AbstractButton)delegee; button.setText(textWithMnemonic.myText); if(textWithMnemonic.myMnemonicIndex != -1){ button.setMnemonic(textWithMnemonic.getMnemonicChar()); button.setDisplayedMnemonicIndex(textWithMnemonic.myMnemonicIndex); } else{ button.setMnemonic(0); } } else { invokeSetter(component, resolvedValue); } checkUpdateBindingFromText(component, value, textWithMnemonic); } else{ invokeSetter(component, resolvedValue); } }
protected void checkComponentProperties(Module module, IComponent component, FormErrorCollector collector) { SupportCode.TextWithMnemonic twm = getTextWithMnemonic(module, component); if (twm != null) { checkTextWithMnemonic(module, component, twm, collector); } }