private IView<JComponent> createEnumerationPropertyView( IEnumerationPropertyDescriptor propertyDescriptor, IActionHandler actionHandler, Locale locale) { JComboBox viewComponent = createJComboBox(); if (!propertyDescriptor.isMandatory()) { viewComponent.addItem(null); } for (Object enumElement : propertyDescriptor.getEnumerationValues()) { viewComponent.addItem(enumElement); } viewComponent.setRenderer(new TranslatedEnumerationListCellRenderer( propertyDescriptor, locale)); adjustSizes(viewComponent, null, getEnumerationTemplateValue( propertyDescriptor, locale), Toolkit.getDefaultToolkit() .getScreenResolution() * 2 / 6); JComboBoxConnector connector = new JComboBoxConnector(propertyDescriptor .getName(), viewComponent); connector.setExceptionHandler(actionHandler); return constructView(viewComponent, null, connector); }
/** * {@inheritDoc} */ @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); label .setIcon(iconFactory.getIcon(propertyDescriptor .getIconImageURL(String.valueOf(value)), IIconFactory.TINY_ICON_SIZE)); if (value != null && propertyDescriptor.isTranslated()) { label.setText(translationProvider.getTranslation(computeEnumerationKey( propertyDescriptor.getEnumerationName(), value), locale)); } else { if (value == null) { label.setText(" "); } else { label.setText(String.valueOf(value)); } } return label; } }
/** * {@inheritDoc} */ @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); label.setIcon(getIconFactory().getIcon(propertyDescriptor.getIconImageURL(String.valueOf(value)), iconDimension)); if (value != null && propertyDescriptor.isTranslated()) { label.setText(propertyDescriptor.getI18nValue((String) value, translationProvider, locale)); } else { if (value == null) { label.setText(" "); } else { label.setText(String.valueOf(value)); } } return label; } }
private Map<String, String> computeTranslationMapping( IEnumerationPropertyDescriptor propertyDescriptor, Locale locale) { Map<String, String> translationMapping = new HashMap<String, String>(); for (String enumerationValue : propertyDescriptor.getEnumerationValues()) { translationMapping.put(enumerationValue, translationProvider .getTranslation(computeEnumerationKey(propertyDescriptor .getEnumerationName(), enumerationValue), locale)); } return translationMapping; }
private String getEnumerationTemplateValue( IEnumerationPropertyDescriptor descriptor, Locale locale) { int maxTranslationLength = -1; if (translationProvider != null && descriptor.isTranslated()) { for (Object enumerationValue : descriptor.getEnumerationValues()) { String translation = translationProvider.getTranslation( computeEnumerationKey(descriptor.getEnumerationName(), enumerationValue), locale); if (translation.length() > maxTranslationLength) { maxTranslationLength = translation.length(); } } } else { maxTranslationLength = descriptor.getMaxLength().intValue(); } if (maxTranslationLength == -1 || maxTranslationLength > maxCharacterLength) { maxTranslationLength = maxCharacterLength; } return getStringTemplateValue(new Integer(maxTranslationLength)); }
connector = getConnectorFactory().createFormattedValueConnector(propertyDescriptor.getName(), formatter); viewComponent = createRLink(propertyViewDescriptor, false); ((RLabel) viewComponent).setMaxLength( getFormatLength(formatter, getEnumerationTemplateValue(propertyDescriptor, actionHandler, locale))); } else { connector = getConnectorFactory().createValueConnector(propertyDescriptor.getName()); List<String> values = new ArrayList<>(); List<String> translations = new ArrayList<>(); List<String> enumerationValues = new ArrayList<>(propertyDescriptor.getEnumerationValues()); filterEnumerationValues(enumerationValues, propertyViewDescriptor); if (!propertyDescriptor.isMandatory()) { enumerationValues.add(0, ""); if (value != null && propertyDescriptor.isTranslated()) { if ("".equals(value)) { translations.add(" "); } else { translations.add(propertyDescriptor.getI18nValue(value, actionHandler, locale)); for (String value : enumerationValues) { icons.add( getIconFactory().getIcon(propertyDescriptor.getIconImageURL(value), getIconFactory().getTinyIconSize()));
.getModelDescriptor(); IReferencePropertyDescriptor<IDescriptor> enumRefPropertyDescriptor = propertyDescriptor .createLovReferenceDescriptor(); BasicReferencePropertyViewDescriptor enumRefPropertyViewDescriptor = new BasicReferencePropertyViewDescriptor(); enumRefPropertyViewDescriptor.setModelDescriptor(enumRefPropertyDescriptor); List<String> enumerationValues = new ArrayList<>(propertyDescriptor.getEnumerationValues()); filterEnumerationValues(enumerationValues, propertyViewDescriptor); if (!propertyDescriptor.isMandatory()) { enumerationValues.add(0, ""); DefaultDescriptor valueComponent = new DefaultDescriptor(); valueComponent.setName(enumerationValue); if (enumerationValue != null && propertyDescriptor.isTranslated()) { if ("".equals(enumerationValue)) { valueComponent.setDescription(" "); } else { valueComponent.setDescription(propertyDescriptor.getI18nValue(enumerationValue, actionHandler, locale));
JLabelConnector connector = new JLabelConnector(propertyDescriptor.getName(), viewComponent); connector.addValueChangeListener(new IValueChangeListener() { view = constructView(viewComponent, propertyViewDescriptor, connector); } else { if (propertyDescriptor.isLov()) { return createEnumerationReferencePropertyView(propertyViewDescriptor, actionHandler, locale); } else { List<String> enumerationValues = new ArrayList<>(propertyDescriptor.getEnumerationValues()); filterEnumerationValues(enumerationValues, propertyViewDescriptor); if (propertyViewDescriptor instanceof IEnumerationPropertyViewDescriptor && ((IEnumerationPropertyViewDescriptor) propertyViewDescriptor).isRadio()) { IRenderableCompositeValueConnector connector = getConnectorFactory().createCompositeValueConnector( ModelRefPropertyConnector.THIS_PROPERTY, propertyDescriptor.getName()); JPanel viewComponent = createJPanel(); GridLayout layout; for (String enumElement : enumerationValues) { JRadioButton subViewComponent = new JRadioButton(); subViewComponent.setText(propertyDescriptor.getI18nValue(enumElement, actionHandler, locale)); JRadioButtonConnector subConnector = new JRadioButtonConnector(propertyDescriptor.getName(), subViewComponent, enumElement); adjustSizes(propertyViewDescriptor, subViewComponent, null, } else { JComboBox<String> viewComponent = createJComboBox(propertyViewDescriptor); if (!propertyDescriptor.isMandatory()) { viewComponent.addItem(null);
/** * Constructs a new {@code EnumValueQueryStructure} instance. * * @param propertyDescriptor * the enumeration property descriptor to create the query structure * for. */ public EnumQueryStructure(IEnumerationPropertyDescriptor propertyDescriptor) { this.sourceDescriptor = propertyDescriptor; PropertyChangeListener toStringListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { firePropertyChange(EnumQueryStructureDescriptor.TO_STRING, null, getToString()); } }; this.enumerationValues = new LinkedHashSet<>(); if (!propertyDescriptor.isMandatory()) { EnumValueQueryStructure nullValueQueryStructure = new EnumValueQueryStructure(); nullValueQueryStructure.setValue(null); nullValueQueryStructure.addPropertyChangeListener(toStringListener); enumerationValues.add(nullValueQueryStructure); } for (String value : propertyDescriptor.getEnumerationValues()) { EnumValueQueryStructure enumValueQueryStructure = new EnumValueQueryStructure(); enumValueQueryStructure.setValue(value); enumValueQueryStructure.addPropertyChangeListener(toStringListener); enumerationValues.add(enumValueQueryStructure); } }
@Override public void valueChange(ValueChangeEvent evt) { viewComponent.setIcon(getIconFactory() .getIcon(propertyDescriptor.getIconImageURL(String.valueOf(evt.getNewValue())), getEnumerationIconDimension(propertyViewDescriptor))); } });
/** * {@inheritDoc} */ @Override protected void setValue(Object value) { if (value instanceof IValueConnector) { Object connectorValue = ((IValueConnector) value).getConnectorValue(); if (connectorValue != null && propertyDescriptor.isTranslated()) { super.setValue(propertyDescriptor.getI18nValue((String) connectorValue, translationProvider, locale)); } else { if (connectorValue == null) { super.setValue(""); } else { super.setValue(String.valueOf(connectorValue)); } } } else { if (value != null && propertyDescriptor.isTranslated()) { super.setValue(propertyDescriptor.getI18nValue((String) value, translationProvider, locale)); } else { if (value == null) { super.setValue(""); } else { super.setValue(String.valueOf(value)); } } } } }
if (value instanceof IValueConnector) { Object connectorValue = ((IValueConnector) value).getConnectorValue(); if (connectorValue != null && propertyDescriptor.isTranslated()) { super.setValue(translationProvider.getTranslation( computeEnumerationKey(propertyDescriptor.getEnumerationName(), connectorValue), locale)); } else { if (value != null && propertyDescriptor.isTranslated()) { super.setValue(translationProvider.getTranslation( computeEnumerationKey(propertyDescriptor.getEnumerationName(), value), locale)); } else {
/** * Computes the toString(). * * @return the toString(). */ public String getToString() { Set<EnumValueQueryStructure> selectedEnumerationValues = getSelectedEnumerationValues(); if (selectedEnumerationValues.isEmpty()) { return ""; } if (selectedEnumerationValues.size() > 3) { return "***"; } String sep = ", "; StringBuilder buf = new StringBuilder(); for (Iterator<EnumValueQueryStructure> ite = selectedEnumerationValues .iterator(); ite.hasNext();) { EnumValueQueryStructure enumValue = ite.next(); if (getTranslationProvider() != null && getLocale() != null) { buf.append(sourceDescriptor.getI18nValue(enumValue.getValue(), getTranslationProvider(), getLocale())); } else { buf.append(enumValue.getValue()); } if (ite.hasNext()) { buf.append(sep); } } return buf.toString(); }
private String getEnumerationTemplateValue( IEnumerationPropertyDescriptor descriptor, Locale locale) { int maxTranslationLength = -1; if (translationProvider != null && descriptor.isTranslated()) { for (Object enumerationValue : descriptor.getEnumerationValues()) { String translation = translationProvider.getTranslation( computeEnumerationKey(descriptor.getEnumerationName(), enumerationValue), locale); if (translation.length() > maxTranslationLength) { maxTranslationLength = translation.length(); } } } else { maxTranslationLength = descriptor.getMaxLength().intValue(); } if (maxTranslationLength == -1 || maxTranslationLength > maxCharacterLength) { maxTranslationLength = maxCharacterLength; } return getStringTemplateValue(new Integer(maxTranslationLength)); }
/** * {@inheritDoc} */ @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setIcon(iconFactory.getIcon(propertyDescriptor.getIconImageURL(String .valueOf(value)), IIconFactory.TINY_ICON_SIZE)); return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); }
private void translateValues() { if (getTranslationProvider() != null && getLocale() != null) { for (EnumValueQueryStructure valueQueryStructure : getEnumerationValues()) { valueQueryStructure.setI18nValue(getSourceDescriptor().getI18nValue(valueQueryStructure.getValue(), getTranslationProvider(), getLocale())); } } }
/** * {@inheritDoc} */ @Override public IRendererComponent getComboBoxCellRendererComponent( ULCComboBox comboBox, Object value, boolean isSelected, int index) { if (propertyDescriptor.isTranslated()) { setDataType(translationDataTypeFactory.getTranslationDataType( propertyDescriptor.getEnumerationName(), locale, computeTranslationMapping(propertyDescriptor, locale))); } setIcon(iconFactory.getIcon(propertyDescriptor.getIconImageURL(String .valueOf(value)), IIconFactory.TINY_ICON_SIZE)); return super.getComboBoxCellRendererComponent(comboBox, value, isSelected, index); } }
private IView<SComponent> createEnumerationPropertyView( IEnumerationPropertyDescriptor propertyDescriptor, IActionHandler actionHandler, Locale locale) { SComboBox viewComponent = createSComboBox(); if (!propertyDescriptor.isMandatory()) { viewComponent.addItem(null); } for (Object enumElement : propertyDescriptor.getEnumerationValues()) { viewComponent.addItem(enumElement); } viewComponent.setRenderer(new TranslatedEnumerationListCellRenderer( propertyDescriptor, locale)); adjustSizes(viewComponent, null, getEnumerationTemplateValue( propertyDescriptor, locale), 48); SComboBoxConnector connector = new SComboBoxConnector(propertyDescriptor .getName(), viewComponent); connector.setExceptionHandler(actionHandler); return constructView(viewComponent, null, connector); }
private String getEnumerationTemplateValue( IEnumerationPropertyDescriptor descriptor, Locale locale) { int maxTranslationLength = -1; if (translationProvider != null && descriptor.isTranslated()) { for (Object enumerationValue : descriptor.getEnumerationValues()) { String translation = translationProvider.getTranslation( computeEnumerationKey(descriptor.getEnumerationName(), enumerationValue), locale); if (translation.length() > maxTranslationLength) { maxTranslationLength = translation.length(); } } } else { maxTranslationLength = descriptor.getMaxLength().intValue(); } if (maxTranslationLength == -1 || maxTranslationLength > maxCharacterLength) { maxTranslationLength = maxCharacterLength; } return getStringTemplateValue(new Integer(maxTranslationLength)); }
/** * {@inheritDoc} */ @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setIcon(getIconFactory().getIcon(propertyDescriptor.getIconImageURL(String.valueOf(value)), iconDimension)); return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); }