Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 36869 Details for
Bug 132984
parsing of classesd if more than one class in one file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
File with parsing errors
TemplatePropertiesController.java (text/plain), 23.45 KB, created by
Klaus Dicks
on 2006-03-24 02:51:00 EST
(
hide
)
Description:
File with parsing errors
Filename:
MIME Type:
Creator:
Klaus Dicks
Created:
2006-03-24 02:51:00 EST
Size:
23.45 KB
patch
obsolete
>package de.shd.basis.ui.drucken_neu.formular; > >import de.shd.basis.ri.util.SimpleStringKey; >import de.shd.basis.ri.util.object.ExtObject; >import de.shd.basis.ri.util.text.ExtString; >import de.shd.basis.ui.controls.MultiValueUIControl; >import de.shd.basis.ui.controls.SHDColorChooser; >import de.shd.basis.ui.controls.SHDLabel; >import de.shd.basis.ui.controls.SHDRadioButton; >import de.shd.basis.ui.controls.SingleValueUIControl; >import de.shd.basis.ui.controls.UIControl; >import de.shd.basis.ui.controls.ValueChangeEvent; >import de.shd.basis.ui.controls.ValueChangeListener; >import de.shd.basis.ui.controls.table.TableCellComponent; > >import java.awt.Component; >import java.beans.PropertyChangeEvent; >import java.beans.PropertyChangeListener; >import java.util.ArrayList; >import java.util.HashMap; >import java.util.Iterator; >import java.util.List; >import java.util.Map; >import javax.swing.JComponent; >import javax.swing.JPanel; >import javax.swing.event.ChangeEvent; > >import com.jgoodies.forms.builder.PanelBuilder; >import com.jgoodies.forms.layout.FormLayout; > >public class TemplatePropertiesController implements FormularEditorSubController >{ > private FormularEditorModel m_formularEditorModel; > private TemplatePropertiesPanel m_templatePropertiesPanel = new TemplatePropertiesPanel(); > > private Map m_cache = new HashMap(); > private int m_oldIndex=-1; > private String m_oldTitle=""; > > > public TemplatePropertiesController(FormularEditorModel formularEditorModel) > { > m_formularEditorModel = formularEditorModel; > initListeners(); > } > > private void initListeners() > { > m_formularEditorModel.addPropertyChangeListener( > FormularEditorModel.PROP_VERSION_VALUE, new PropertyChangeListener() > { > public void propertyChange(PropertyChangeEvent evt) > { > m_templatePropertiesPanel.getTable().removeObjectListe(); > m_templatePropertiesPanel.getTabbedPane().removeAll(); > } > } > ); > > m_formularEditorModel.addPropertyChangeListener( > FormularEditorModel.PROP_SELECTED_KEY, new PropertyChangeListener() > { > public void propertyChange(PropertyChangeEvent evt) > { > final String[] keys = (String[]) evt.getNewValue(); > > if (keys.length > 1) > { > List modelElelemnts = new ArrayList(); > for (int i = 0; i < keys.length; i++) > { > String key = keys[i]; > ModelElement template = m_formularEditorModel.getTemplate(key); > > > addListenerToSelectedItem(template); > > modelElelemnts.add(template); > } > reloadPropertyForModelElement((ModelElement[]) modelElelemnts.toArray(new ModelElement[modelElelemnts.size()]), keys, null); > > } > else if (keys.length == 1) > { > final ModelElement template = m_formularEditorModel.getTemplate(keys[0]); > addListenerToSelectedItem(template); > > reloadPropertyForModelElement(new ModelElement[]{template}, keys, null); > } > else > { > m_templatePropertiesPanel.getTable().removeObjectListe(); > if (m_templatePropertiesPanel.getTabbedPane().getTabCount()>0) > holdSelection(); > > m_templatePropertiesPanel.getTabbedPane().removeAll(); > } > } > > private void reloadPropertyForModelElement(final ModelElement[] templates, final String[] keys, String propKey) > { > List gemeinsameProperties = new ArrayList(); > Map propertyKeysConter = new HashMap(); > for (int i = 0; i < templates.length; i++) > { > > final ModelElement template = templates[i]; > String[] propertiesAsKey = template.getPropertyKeys(); > for (int j = 0; j < propertiesAsKey.length; j++) > { > String s = propertiesAsKey[j]; > if (propKey == null || propKey.equals(s)) > { > Integer counter = (Integer) propertyKeysConter.get(s); > if (counter == null) > { > counter = new Integer(0); > } > propertyKeysConter.put(s, new Integer(counter.intValue() + 1)); > } > } > } > > for (Iterator iterator = propertyKeysConter.entrySet().iterator(); iterator.hasNext();) > { > Map.Entry entry = (Map.Entry) iterator.next(); > if (((Integer) entry.getValue()).intValue() == templates.length) > { > gemeinsameProperties.add(entry.getKey()); > } > } > > ArrayList boListe = new ArrayList(); > List keyList = new ArrayList(); > for (Iterator iterator = gemeinsameProperties.iterator(); iterator.hasNext();) > { > String property = (String) iterator.next(); > //if (1==1) > if (m_cache.containsKey(property) == false) > { > FormularProperty availableProperty = FormularProperty.getPropertyByKey( > property, m_formularEditorModel, templates[0], new ReloadCallback() > { > public void reload(String propKey) > { > reloadPropertyForModelElement(templates, keys, propKey); > } > } > ); > m_cache.put(property,availableProperty); > } > > FormularProperty availableProperty =(FormularProperty) m_cache.get(property); > > if (keys.length == 1 || availableProperty.isMultiSelectionEnabled()) > { > PropertyTableEntry o = new PropertyTableEntry(availableProperty.getSection(), keys, availableProperty); > keyList.add(o); > boListe.add(o); > for (int k = 0; k < availableProperty.getSubProperties().length; k++) > { > if (keys.length == 1 || availableProperty.getSubProperties()[k].isMultiSelectionEnabled()) > { > boListe.add(new PropertyTableEntry(availableProperty, k, keys, property)); > } > } > } > > } > > > m_templatePropertiesPanel.getTable().getTable().editingStopped(new ChangeEvent(this)); > m_templatePropertiesPanel.getTable().setObjectListe(boListe); > > if (m_templatePropertiesPanel.getTabbedPane().getTabCount()>0) > holdSelection(); > > > int insertAt = -1; > if (propKey == null) > { > m_templatePropertiesPanel.getTabbedPane().removeAll(); > } > else > { > Component[] components = m_templatePropertiesPanel.getTabbedPane().getComponents(); > for (int i = 0; i < components.length; i++) > { > JComponent component = (JComponent) components[i]; > Object clientProperty = component.getClientProperty("mainKey"); > if (propKey.equals(clientProperty)) > { > m_templatePropertiesPanel.getTabbedPane().remove(component); > insertAt = i; > } > } > > } > for (Iterator iterator1 = keyList.iterator(); iterator1.hasNext();) > { > PropertyTableEntry tableEntry = (PropertyTableEntry) iterator1.next(); > FormularProperty.DetailCallBack detailListComponent = tableEntry.getDetailListComponent(); > detailListComponent.setSelectedElements(templates, m_formularEditorModel); > JComponent control = detailListComponent.getDetailListComponent(); > > control.putClientProperty("mainKey", tableEntry.m_formularProperty.getKey()); > if (propKey != null && insertAt!=-1) > { > m_templatePropertiesPanel.getTabbedPane().insertTab( > tableEntry.m_formularProperty.getSection(), null, control, "", insertAt > ); > } > else > { > m_templatePropertiesPanel.getTabbedPane().addTab( > tableEntry.m_formularProperty.getSection(), control > ); > } > } > > if (m_oldIndex != -1 && m_templatePropertiesPanel.getTabbedPane().getTabCount() > m_oldIndex && m_oldTitle.equals( > m_templatePropertiesPanel.getTabbedPane().getTitleAt(m_oldIndex) > )) > { > m_templatePropertiesPanel.getTabbedPane().setSelectedIndex(m_oldIndex); > > } > else > { > if (m_templatePropertiesPanel.getTabbedPane().getTabCount()>0) > m_templatePropertiesPanel.getTabbedPane().setSelectedIndex(0); > } > > } > } > ); > } > > private void holdSelection() > { > m_oldIndex = m_templatePropertiesPanel.getTabbedPane().getSelectedIndex(); > m_oldTitle = m_oldIndex == -1 ? "" : m_templatePropertiesPanel.getTabbedPane().getTitleAt(m_oldIndex); > } > > private void addListenerToSelectedItem(ModelElement template) > { > template.addPropertyChangeListener( > new PropertyChangeListener() > { > public void propertyChange(PropertyChangeEvent evt) > { > if (evt.getPropertyName().startsWith("property.")) > { > m_templatePropertiesPanel.fireTableChanged(); > } > } > } > ); > } > > public JComponent getDisplayComponent() > { > return m_templatePropertiesPanel; > } > > public class PropertyTableEntry extends SimpleStringKey > { > private String m_propertyName; > private FormularProperty m_formularProperty; > private int m_subPropertyIndex; > private String[] m_templateIDs; > private String m_propertyKey; > private boolean m_section; > > private boolean m_multibleValues; > > > public PropertyTableEntry(String section, String[] templateIDs, FormularProperty formularProperty) > { > super(section); > m_templateIDs = templateIDs; > m_formularProperty = formularProperty; > m_section = true; > m_propertyName = section; > } > > public PropertyTableEntry(FormularProperty formularProperty, int subPropertyIndex, String[] templateIDs, String propertyKey) > { > super(null); // nur für Tabele - wird nicht in table angezeigt > m_formularProperty = formularProperty; > m_subPropertyIndex = subPropertyIndex; > m_templateIDs = templateIDs; > m_propertyKey = propertyKey; > > m_propertyName = m_formularProperty.getSubProperties()[m_subPropertyIndex].getLabel(); > } > > public String getPropertyName() > { > return m_propertyName; > } > > public FormularProperty getFormularProperty() > { > return m_formularProperty; > } > > public boolean isSection() > { > return m_section; > } > > public int getSubPropertyIndex() > { > return m_subPropertyIndex; > } > > public void setPropertySubTemplateValue(Object value) > { > if (value == null) > { > return; > } > > for (int i = 0; i < m_templateIDs.length; i++) > { > String templateID = m_templateIDs[i]; > m_formularEditorModel.getTemplate(templateID).setProperty( > m_propertyKey, > m_formularProperty.getSubProperties()[m_subPropertyIndex].getSubPropKey(), > value > ); > } > > } > > public Object getPropertySubTemplateValue() > { > if (m_section) > { > return ""; > } > > try > { > > Object s = null; > m_multibleValues = false; > > for (int i = 0; i < m_templateIDs.length; i++) > { > String templateID = m_templateIDs[i]; > ModelElement template = m_formularEditorModel.getTemplate(templateID); > Object newProperty = template.getProperty(m_propertyKey).getValue( > m_formularProperty.getSubProperties()[m_subPropertyIndex].getSubPropKey() > ); > > if (i != 0) > { > if (ExtObject.equals(s, newProperty) == false) > { > m_multibleValues = true; > } > } > else > { > s = newProperty; > } > > } > > if (s == null) > { > throw new NullPointerException(); > } > > > return s; > } > catch (NullPointerException e) > { > throw e; > } > } > > public boolean isMultibleValues() > { > return m_multibleValues; > } > > public FormularProperty.DetailCallBack getDetailListComponent() > { > List selected = new ArrayList(); > for (int i = 0; i < m_templateIDs.length; i++) > { > String templateID = m_templateIDs[i]; > ModelElement template = m_formularEditorModel.getTemplate(templateID); > selected.add(template); > } > FormularProperty.DetailCallBack detailCallback = m_formularProperty.getDetailCallback(); > if (detailCallback == null) > { > detailCallback = new DefaultDetailCallBack(m_formularProperty.getSubProperties(), m_formularProperty.getKey()); > m_formularProperty.setDetailCallback(detailCallback); > } > return detailCallback; > } > } >} > >class DefaultDetailCallBack implements FormularProperty.DetailCallBack >{ > private SubProperty[] m_subProperties; > private String m_key; > > private List m_handlers = new ArrayList(); > private JPanel m_panel; > > public DefaultDetailCallBack(SubProperty[] subProperties, String key) > { > m_subProperties = subProperties; > m_key = key; > > String result = "3dlu"; > for (int i = 0; i < m_subProperties.length; i++) > { > result += ", p, 3dlu"; > } > > FormLayout layout = new FormLayout("4dlu, p:none, 4dlu,fill:max(p;60dlu):grow,4dlu p, 4dlu", result); > > PanelBuilder panelBuilder = new PanelBuilder(layout); > panelBuilder.nextLine(); > final Map componentMap = new HashMap(); > for (int i = 0; i < m_subProperties.length; i++) > { > SubProperty subProperty = m_subProperties[i]; > panelBuilder.nextColumn(); > panelBuilder.addLabel(subProperty.getLabel()); > panelBuilder.nextColumn(2); > > final TableCellComponent tableCellComponent = (TableCellComponent) subProperty.getTableCellEditor(); > final UIControl component = (UIControl) tableCellComponent.getComponent(); > final String subPropKey = subProperty.getSubPropKey(); > > componentMap.put(subPropKey, component); > //boolean hasMultiValues = hasMultiValues(selected, m_key, subPropKey); > panelBuilder.add((Component) component); > //if (hasMultiValues) > //{ > // panelBuilder.nextColumn(2); > // panelBuilder.add(new SHDLabel("M")); > //} > panelBuilder.nextLine(2); > > m_handlers.add(new DefaultPropertyControlHandler(component, subProperty.getSubPropKey(), m_key)); > } > m_panel = panelBuilder.getPanel(); > } > > public void setSelectedElements(ModelElement[] selectedElements, FormularEditorModel formularEditorModel) > { > for (Iterator iterator = m_handlers.iterator(); iterator.hasNext();) > { > DefaultPropertyControlHandler defaultPropertyControlHandler = (DefaultPropertyControlHandler) iterator.next(); > defaultPropertyControlHandler.setModel(selectedElements); > } > } > > public JComponent getDetailListComponent() > { > return m_panel; > } > > private boolean hasMultiValues(ModelElement[] modelElements, String propertyKey, String subPropKey) > { > Object last = null; > boolean multibleValues = false; > > for (int i = 0; i < modelElements.length; i++) > { > ModelElement template = modelElements[i]; > PropertyValuePropertyElement property = template.getProperty(propertyKey); > if (property == null) > { > throw new NullPointerException("for property " + propertyKey + " doesnt exist a value in model"); > } > Object newProperty = property.getValue(subPropKey); > > if (i != 0) > { > if (ExtObject.equals(last, newProperty) == false) > { > multibleValues = true; > } > } > last = newProperty; > > } > > return multibleValues; > } > >} > >class DefaultPropertyControlHandler >{ > private ModelElement[] m_selectedModelElements; > private UIControl m_component; > private String m_propertykey; > private boolean m_inUpdate; > private String m_subPropKey; > private ValueChangeListener m_valueChangeListener; > > public DefaultPropertyControlHandler(UIControl component, final String subPropKey, String propertykey) > { > m_component = component; > m_subPropKey = subPropKey; > m_propertykey = propertykey; > > > m_valueChangeListener = new ValueChangeListener() > { > public void valueChanged(ValueChangeEvent event) > { > handleValueChanged(); > } > }; > component.addValueChangeListener( > m_valueChangeListener > ); > > > > } > > private void handleValueChanged() > { > final Object newValue = getValueFromControl(m_component); > for (int j = 0; j < m_selectedModelElements.length; j++) > { > final ModelElement modelElement = m_selectedModelElements[j]; > if (newValue == null) > { > return; > } > if (m_inUpdate) > { > return; > } > m_inUpdate = true; > > //wegen snapToGrid, ich bekomme sonst in diesem Event wieder einen anderen Wert -> Attempt to mutate in notification > //SwingUtilities.invokeLater(new Runnable() > //{ > // public void run() > { > modelElement.setProperty(m_propertykey, m_subPropKey, newValue); > m_inUpdate = false; > > } > //}); > > } > } > > > private void setValue(String subPropKey, final UIControl control, Object newValue) > { > if (m_inUpdate) > { > return; > } > if (control == null) > { > throw new NullPointerException("no control for subkey -> " + subPropKey); > } > m_inUpdate = true; > setValueToControl(control, newValue); > m_inUpdate = false; > } > > private void setValueToControl(UIControl component, Object value) > { > if (component instanceof SingleValueUIControl) > { > if (value.equals(((SingleValueUIControl) component).getValue()) == false) > { > if (component instanceof SHDRadioButton) > { > ((SHDRadioButton) component).setSelectedKey(value); > } > else > { > ((SingleValueUIControl) component).setValue(value); > } > } > } > else > { > if (value instanceof Integer) > { > ((MultiValueUIControl) component).setSelectedKey((Integer) value); > } > else > { > if (value instanceof String == false) > { > value = value.toString();//throw new IllegalStateException("values class -> " + value.getClass() + " is not allowed."); > } > ((MultiValueUIControl) component).setSelectedKey((String) value); > } > > } > } > > > static Object getValueFromControl(UIControl component) > { > if (component instanceof SingleValueUIControl) > { > if (component instanceof SHDRadioButton) > { > return ((SHDRadioButton) component).getSelectedKey(); > } > else if (component instanceof SHDColorChooser) > { > return new Integer(((SHDColorChooser) component).getColor().getRGB()); > > } > return ((SingleValueUIControl) component).getValue(); > } > else > { > return ((MultiValueUIControl) component).getSelectedKey(); > } > } > > public void setModel(ModelElement[] selectedElements) > { > m_selectedModelElements = selectedElements; > //wenn alle gleich ist [0] egal, wenn nicht setze ich den Wert des erstSelektierten rein > > m_component.removeValueChangeListener( > m_valueChangeListener > ); > Object value = (selectedElements[0].getProperty(m_propertykey).getValue(m_subPropKey)); > if (value == null) > { > throw new IllegalStateException(); > } > setValueToControl(m_component, value); > > m_component.addValueChangeListener( > m_valueChangeListener > ); > > PropertyChangeListener propertyChangeListener = new PropertyChangeListener() > { > public void propertyChange(PropertyChangeEvent evt) > { > if (m_inUpdate) > { > return; > } > if (evt.getPropertyName().startsWith("property.")) > { > String key = evt.getPropertyName().substring(9, evt.getPropertyName().length()); > > String[] strings = ExtString.toPieces(key, "."); > > if (strings[0].equals(m_propertykey)) > { > Object newValue = evt.getNewValue(); > if (strings.length == 1) > { > PropertyValuePropertyElement newDefined = (PropertyValuePropertyElement) newValue; > Object value = newDefined.getValue(m_subPropKey); > setValue(m_subPropKey, m_component, value); > } > else > { > if (newValue instanceof PropertyValuePropertyElement) > { > newValue = ((PropertyValuePropertyElement) newValue).getValue(m_subPropKey); > } > > if (strings[1].equals(m_subPropKey)) > { > setValue(strings[1], m_component, newValue); > } > } > } > } > } > }; > > > for (int i = 0; i < selectedElements.length; i++) > { > ModelElement selectedModelElement = selectedElements[i]; > selectedModelElement.addPropertyChangeListener(propertyChangeListener); > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 132984
: 36869