private static PropertyEditor findThePropertyEditor(Class clazz) { PropertyEditor pe; if (Object.class.equals(clazz)) { pe = null; } else { pe = PropertyEditorManager.findEditor(clazz); if (pe == null) { Class sclazz = clazz.getSuperclass(); if (sclazz != null) { pe = findPropertyEditor(sclazz); } } } classesWithPE.put(clazz, pe != null); return pe; }
private void fontButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontButtonActionPerformed PropertyEditor pe = PropertyEditorManager.findEditor(Font.class); if (pe != null) { pe.setValue(termOptions.getFont()); DialogDescriptor dd = new DialogDescriptor(pe.getCustomEditor(), FontChooser_title()); String defaultFontString = FontChooser_defaultFont_label(); dd.setOptions(new Object[]{DialogDescriptor.OK_OPTION, defaultFontString, DialogDescriptor.CANCEL_OPTION}); //NOI18N DialogDisplayer.getDefault().createDialog(dd).setVisible(true); if (dd.getValue() == DialogDescriptor.OK_OPTION) { Font f = (Font) pe.getValue(); termOptions.setFont(f); applyTermOptions(); } else if (dd.getValue() == defaultFontString) { Font controlFont = UIManager.getFont("controlFont"); //NOI18N int fontSize = (controlFont == null) ? 12 : controlFont.getSize(); termOptions.setFont(new Font("monospaced", Font.PLAIN, fontSize)); //NOI18N } } }
public void testPackageUnregistering() { MockLookup.setInstances(new NodesRegistrationSupport.PEPackageRegistration("test1.pkg")); NodeOp.registerPropertyEditors(); MockLookup.setInstances(new NodesRegistrationSupport.PEPackageRegistration("test2.pkg")); String[] editorSearchPath = PropertyEditorManager.getEditorSearchPath(); int count = 0; for (int i = 0; i < editorSearchPath.length; i++) { assertNotSame("test1.pkg", editorSearchPath[i]); if ("test2.pkg".equals(editorSearchPath[i])) { count++; } } assertEquals(1, count); }
private void btnSelectFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectFontActionPerformed PropertyEditor pe = PropertyEditorManager.findEditor(Font.class); if (pe != null) { pe.setValue(outputOptions.getFont()); DialogDescriptor dd = new DialogDescriptor(pe.getCustomEditor(), NbBundle.getMessage(Controller.class, "LBL_Font_Chooser_Title")); //NOI18N String defaultFont = NbBundle.getMessage(Controller.class, "BTN_Defaul_Font"); //NOI18N dd.setOptions(new Object[]{DialogDescriptor.OK_OPTION, defaultFont, DialogDescriptor.CANCEL_OPTION}); //NOI18N DialogDisplayer.getDefault().createDialog(dd).setVisible(true); if (dd.getValue() == DialogDescriptor.OK_OPTION) { Font f = (Font) pe.getValue(); outputOptions.setFont(f); } else if (dd.getValue() == defaultFont) { outputOptions.setFont(null); } updateFontField(); } }
public static Property getProperty(Field field, Object object) { // access also protected and private fields field.setAccessible(true); // Properties are only primitive types marked by Prop annotation if (field.isAnnotationPresent(JProp.class)) { // We require that class of the field to be loaded, because we often specify // the PropertyEditor there in static block. forceInitialization(field.getType()); //TODO this condition should be used on client when deciding whether to show an editor for it if (PropertyEditorManager.findEditor(field.getType()) != null) { // add the property return new JavaProperty(object, field); } } return null; }
/** * @param requiredType * @param propertyPath * @return */ public PropertyEditor findCustomEditor ( final Class<?> requiredType, final String propertyPath ) { // first try to find exact match String key = requiredType.getCanonicalName () + ":" + propertyPath; PropertyEditor pe = this.propertyEditors.get ( key ); // 2nd: try to find for class only if ( pe == null ) { key = requiredType.getCanonicalName () + ":"; pe = this.propertyEditors.get ( key ); } // 3rd: try to get internal if ( pe == null ) { pe = PropertyEditorManager.findEditor ( requiredType ); } return pe; }
public static Object getValueFromPropertyEditorManager( Class<?> attrClass, String attrName, String attrValue) throws JasperException { try { PropertyEditor propEditor = PropertyEditorManager.findEditor(attrClass); if (propEditor != null) { propEditor.setAsText(attrValue); return propEditor.getValue(); } else { throw new IllegalArgumentException( Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered")); } } catch (IllegalArgumentException ex) { throw new JasperException( Localizer.getMessage("jsp.error.beans.property.conversion", attrValue, attrClass.getName(), attrName, ex.getMessage())); } }
public static Object getValueFromPropertyEditorManager( Class attrClass, String attrName, String attrValue) throws JasperException { try { PropertyEditor propEditor = PropertyEditorManager.findEditor(attrClass); if (propEditor != null) { propEditor.setAsText(attrValue); return propEditor.getValue(); } else { throw new IllegalArgumentException( Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered")); } } catch (IllegalArgumentException ex) { throw new JasperException( Localizer.getMessage("jsp.error.beans.property.conversion", attrValue, attrClass.getName(), attrName, ex.getMessage())); } }
public static Font show(Font initialFont) { PropertyEditor pe = PropertyEditorManager.findEditor(Font.class); if (pe == null) { throw new RuntimeException("Could not find font editor component."); } pe.setValue(initialFont); DialogDescriptor dd = new DialogDescriptor( pe.getCustomEditor(), "Choose Font"); DialogDisplayer.getDefault().createDialog(dd).setVisible(true); if (dd.getValue() == DialogDescriptor.OK_OPTION) { Font f = (Font)pe.getValue(); return f; } return initialFont; }
public void run() { try { Thread.sleep(this.time); // increase the chance of the deadlock if (this.sync) { synchronized (Test6963811.class) { PropertyEditorManager.findEditor(Super.class); } } else { PropertyEditorManager.findEditor(Sub.class); } } catch (Exception exception) { exception.printStackTrace(); } }
public static Object getValueFromPropertyEditorManager(Class<?> attrClass, String attrName, String attrValue) throws JasperException { try { PropertyEditor propEditor = PropertyEditorManager.findEditor(attrClass); if (propEditor != null) { propEditor.setAsText(attrValue); return propEditor.getValue(); } else { throw new IllegalArgumentException( Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered")); } } catch (IllegalArgumentException ex) { throw new JasperException(Localizer.getMessage("jsp.error.beans.property.conversion", attrValue, attrClass.getName(), attrName, ex.getMessage())); } }
/** * Retrieve an editor object for a given class. * This method seems unable to retrieve a primitive editor for obscure reasons. * So better use the one based on PropertyDescriptor if possible. */ public static PropertyEditor findEditor(Class<?> cls) { PropertyEditor editor = PropertyEditorManager.findEditor(cls); // Try to unwrap primitives if (editor == null && Primitives.isWrapperType(cls)) { editor = PropertyEditorManager.findEditor(Primitives.unwrap(cls)); } if ((editor == null) && useDefaultGOE) { if (cls.isArray()) { Class<?> unwrapped = Primitives.isWrapperType(cls.getComponentType()) ? Primitives.unwrap(cls.getComponentType()) : cls; if (unwrapped.isPrimitive()) { editor = new ArrayEditor(); } else { editor = new ObjectArrayEditor<>(unwrapped.getComponentType()); } } else if (cls.isEnum()) { editor = new EnumEditor(); } else { editor = new GenericObjectEditor(); ((GenericObjectEditor)editor).setClassType(cls); } } return editor; }
/** * Load values from the LocaleOption */ void load() { final LocaleOption localeOption = LocaleOption.getDefault(); final String[] datePatternsList = localeOption.getDatePatternList(); this.datePatternsPE = PropertyEditorManager.findEditor(String[].class); this.datePatternsPE.setValue( datePatternsList ); final String[] messagePatternsList = localeOption.getMessagePatternList(); this.messagePatternsPE = PropertyEditorManager.findEditor(String[].class); this.messagePatternsPE.setValue( messagePatternsList ); final String[] numberPatternsList = localeOption.getNumberPatternList(); this.numberPatternsPE = PropertyEditorManager.findEditor(String[].class); this.numberPatternsPE.setValue( numberPatternsList ); //--- this.datePatternsTextField.setText( this.datePatternsPE.getAsText() ); this.messagePatternsTextField.setText( this.messagePatternsPE.getAsText() ); this.numberPatternsTextField.setText( this.numberPatternsPE.getAsText() ); this.dateParseFormattedTextField.setValue( localeOption.getMessageArgDatePattern() ); this.numberParseFormattedTextField.setValue( localeOption.getMessageArgNumberPattern() ); }
private static Object convert(Object value, Class<?> type) { if( type.isArray() ) { if( value.getClass().isArray() ) { int length = Array.getLength(value); Class<?> componentType = type.getComponentType(); Object rc = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Object o = Array.get(value, i); Array.set(rc, i, convert(o, componentType)); } return rc; } } PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor != null) { editor.setAsText(value.toString()); return editor.getValue(); } return null; }
public static void registerEditor(String name, String value) { Class<?> baseCls; Class<?> cls; try { // array class? if (name.endsWith("[]")) { baseCls = Class.forName(name.substring(0, name.indexOf("[]"))); cls = Array.newInstance(baseCls, 1).getClass(); } else { cls = Class.forName(name); } // register PropertyEditorManager.registerEditor(cls, Class.forName(value)); } catch (Exception e) { Logger.log(weka.core.logging.Logger.Level.WARNING, "Problem registering " + name + "/" + value + ": " + e); } }
private static Object convert(TypeConverter typeConverter, Class<?> type, Object value) throws URISyntaxException, NoTypeConversionAvailableException { if (typeConverter != null) { return typeConverter.mandatoryConvertTo(type, value); } if (type == URI.class) { return new URI(value.toString()); } PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor != null) { // property editor is not thread safe, so we need to lock Object answer; synchronized (LOCK) { editor.setAsText(value.toString()); answer = editor.getValue(); } return answer; } return null; }
/** * Get a property editor given a property type. * * @param propertyType The property type to look up an editor for. * @param path The property path, if applicable. * @return property editor */ public static PropertyEditor getPropertyEditor(Class<?> propertyType) { PropertyEditorRegistry registry = getPropertyEditorRegistry(); PropertyEditor editor = null; if (registry != null) { editor = registry.findCustomEditor(propertyType, null); } else { DataDictionaryService dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService(); Map<Class<?>, String> editorMap = dataDictionaryService.getPropertyEditorMap(); String editorPrototypeName = editorMap == null ? null : editorMap.get(propertyType); if (editorPrototypeName != null) { editor = (PropertyEditor) dataDictionaryService.getDataDictionary().getDictionaryPrototype(editorPrototypeName); } } if (editor == null && propertyType != null) { // Fall back to default beans lookup editor = PropertyEditorManager.findEditor(propertyType); } return editor; }
private void buttonFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFontActionPerformed final PropertyEditor editor = PropertyEditorManager.findEditor(Font.class); if (editor == null) { LOGGER.error("Can't find any font editor"); NbUtils.msgError(null, "Can't find editor! Unexpected state! Contact developer!"); return; } editor.setValue(this.config.getFont()); final DialogDescriptor descriptor = new DialogDescriptor( editor.getCustomEditor(), "Mind map font" ); DialogDisplayer.getDefault().createDialog(descriptor).setVisible(true); if (descriptor.getValue() == DialogDescriptor.OK_OPTION) { this.config.setFont((Font) editor.getValue()); updateFontButton(this.config); if (changeNotificationAllowed) { this.controller.changed(); } } }
public static void registerEditor(String name, String value) { Class baseCls; Class cls; try { // array class? if (name.endsWith("[]")) { baseCls = Class.forName(name.substring(0, name.indexOf("[]"))); cls = Array.newInstance(baseCls, 1).getClass(); } else { cls = Class.forName(name); } // register PropertyEditorManager.registerEditor(cls, Class.forName(value)); } catch (Exception e) { System.err.println("Problem registering " + name + "/" + value + ": " + e); } }
private static boolean isSettableType(Class clazz) { if (PropertyEditorManager.findEditor(clazz) != null) { return true; } if (clazz == URI.class) { return true; } if (clazz == File.class) { return true; } if (clazz == File[].class) { return true; } if (clazz == Boolean.class) { return true; } return false; }
@Override public Object convertOne(Class<?> type, InvokeContext ctx, Object from) { if (from != null && !(from instanceof String)) { return NOT_CONVERTABLE; } PropertyEditor pe = PropertyEditorManager.findEditor(type); if (pe == null) { return NOT_CONVERTABLE; } if (from == null) { return null; } else { try { pe.setAsText((String) from); return pe.getValue(); } catch (Exception e) { log.warn("Can't convert parameter to {}", type.getName(), e); return NOT_CONVERTABLE; } } }
public void testStringEditor_SetAsText_Null() { PropertyEditor editor = PropertyEditorManager.findEditor(String.class); editor.setAsText("null"); assertEquals("null", editor.getAsText()); assertEquals("\"null\"", editor.getJavaInitializationString()); assertEquals("null", editor.getValue()); editor.setAsText(""); assertEquals("", editor.getAsText()); assertEquals("\"\"", editor.getJavaInitializationString()); editor.setAsText(null); assertEquals("null", editor.getAsText()); assertEquals("\"null\"", editor.getJavaInitializationString()); assertNull(editor.getValue()); }
public void testFindEditorAccordingPath_2() throws Exception { // Regression Harmony-1205 String newPath[] = new String[origPath.length + 1]; newPath[origPath.length] = "org.apache.harmony.beans.tests.support"; for (int i = 0; i < origPath.length; i++) { newPath[i] = origPath[i]; } PropertyEditorManager.setEditorSearchPath(newPath); PropertyEditor editor = PropertyEditorManager.findEditor(Class .forName("java.lang.String")); assertEquals(org.apache.harmony.beans.editors.StringEditor.class, editor.getClass()); }