/** * Set the listener (only where they are not already set) to listen the changes * to a dataset and discard the cached interpreter for that dataset when they happen. * The listeners are set on both the dataset and his children * * @param parentDataset */ private static void setDatasetListners(JRDesignDataset parentDataset){ addEventIfnecessary(parentDataset, parentDataset); for(JRVariable var : parentDataset.getVariables()){ if (var instanceof JRChangeEventsSupport) addEventIfnecessary((JRChangeEventsSupport)var, parentDataset); } for(JRSortField sortField : parentDataset.getSortFields()){ if (sortField instanceof JRChangeEventsSupport) addEventIfnecessary((JRChangeEventsSupport)sortField, parentDataset); } for(JRParameter parameter : parentDataset.getParameters()){ if (parameter instanceof JRChangeEventsSupport) addEventIfnecessary((JRChangeEventsSupport)parameter, parentDataset); } for(JRField field : parentDataset.getFields()){ if (field instanceof JRChangeEventsSupport) addEventIfnecessary((JRChangeEventsSupport)field, parentDataset); } }
public void setValue(Object value) { if (this.value == value) return; unregister(); if (this.value != null && this.value instanceof JRChangeEventsSupport) { ((JRChangeEventsSupport) this.value).getEventSupport().removePropertyChangeListener(this); } if (value != null) { this.value = value; if (this.value instanceof JRChangeEventsSupport) ((JRChangeEventsSupport) this.value).getEventSupport().addPropertyChangeListener(this); register(); return; } this.value = value; }
/** * Wait the changes of the expression */ @Override public void propertyChange(PropertyChangeEvent evt) { if (JRDesignExpression.PROPERTY_TEXT.equals(evt.getPropertyName()) && element != null){ ANode parent = element.getParent(); //Refresh also the container if it is a table or something like that while (parent != null){ if (parent instanceof IGraphicalPropertiesHandler){ ((IGraphicalPropertiesHandler)parent).setChangedProperty(true); if (parent.getValue() instanceof JRChangeEventsSupport){ ((JRChangeEventsSupport)parent.getValue()).getEventSupport().firePropertyChange(FORCE_GRAPHICAL_REFRESH, null, null); } } parent = parent.getParent(); } //Notify the change to the element, no need to set the the refresh to true, it will be done by //the property change since the PROPERTY_EXPRESSION is a graphical property element.getValue().getEventSupport().firePropertyChange(JRDesignTextField.PROPERTY_EXPRESSION, evt.getOldValue(), evt.getNewValue()); } }
/** * Fire an event of style found or not found * * @param event the text of the event, should be STYLE_NOT_FOUND_EVENT or STYLE_FOUND_EVENT * @param element JRelement of the template style */ private static void fireEvent(String event, JRReportTemplate element){ if (element instanceof JRChangeEventsSupport){ JRChangeEventsSupport eventElement = (JRChangeEventsSupport)element; eventElement.getEventSupport().firePropertyChange(event, null, null); } }
/** * Recursively send the close editor event to the passed children and to every * child of them * * @param children the children */ private void sendDeleteEvent(List<INode> children){ if (children == null) return; for (INode child : children){ sendDeleteEvent(getChildren(child)); if (child.getValue() instanceof JRChangeEventsSupport){ JRChangeEventsSupport eventElement = (JRChangeEventsSupport)child.getValue(); eventElement.getEventSupport().firePropertyChange(ReportContainer.CLOSE_EDITOR_PROPERTY, child.getValue(), null); } } }
@Override protected void postPageChange(int newPageIndex, int oldPageIndex) { AbstractVisualEditor activeEditor = editors.get(newPageIndex); //request the rapaint of the element on the main editor node when switching between the subeditors, supposing they were modified in the subeditor if (oldPageIndex > 0){ AbstractVisualEditor oldEditor = editors.get(oldPageIndex); INode subModel = getInnerModel(oldEditor.getModel()); ((JRChangeEventsSupport)subModel.getValue()).getEventSupport().firePropertyChange(MGraphicElement.FORCE_GRAPHICAL_REFRESH, null, null); } IEditorActionBarContributor contributor = parent.getEditorSite().getActionBarContributor(); if (contributor != null && contributor instanceof MultiPageEditorActionBarContributor) { ((MultiPageEditorActionBarContributor) contributor).setActivePage(activeEditor); } }
/** * check if an object has a listener of a specific type * * @param support object from where the listeners are obtained * @param listenerClass class to search * @return true if the support object has a listener that has exactly the type listenerClass, * otherwise false */ private static boolean hasListener(JRChangeEventsSupport support, Class<?> listenerClass){ PropertyChangeListener[] listeners = support.getEventSupport().getPropertyChangeListeners(); for(PropertyChangeListener listener : listeners){ if (listener.getClass() == listenerClass) return true; } return false; }
/** * Add to an object that support the event change a dataset change listener, but only if * it hasen't already a listener of this type * * @param support the element * @param parentDataset the dataset that will be removed from the cache if the listener is called */ private static void addEventIfnecessary(JRChangeEventsSupport support, JRDesignDataset parentDataset){ if (!hasListener(support, DatasetChanges.class)){ support.getEventSupport().addPropertyChangeListener(new DatasetChanges(parentDataset)); } }