Java 类net.sf.jasperreports.engine.design.JRDesignReportTemplate 实例源码

项目:PDFReporter-Studio    文件:StyleTemplateFactory.java   
public static ANode createTemplate(ANode parent, JRDesignReportTemplate jrObject, int newIndex, IFile file) {
    MStyleTemplate mStyleTemplate = new MStyleTemplate(parent, (JRDesignReportTemplate) jrObject, newIndex);
    JasperReportsConfiguration jConf =  parent.getJasperConfiguration();
    IFile project = (IFile) jConf.get(FileUtils.KEY_FILE);
    //Use the style manager to retrive the styles, so the result is cached
    String str = ExternalStylesManager.evaluateStyleExpression( (JRDesignReportTemplate) jrObject, project,jConf); 
    if (str != null) {
        Set<String> set = new HashSet<String>();
        if (file == null) {
            IEditorPart ep = SelectionHelper.getActiveJRXMLEditor();
            if (ep != null)
                file = ((IFileEditorInput) ep.getEditorInput()).getFile();
        }
        createTemplateReference(mStyleTemplate, str, -1, set, false, file);
        return mStyleTemplate;
    }
    return null;
}
项目:ireport-fork    文件:TemplateReferenceNode.java   
public void propertyChange(PropertyChangeEvent evt) {

        // Notify the change in the template...
        IReportManager.getInstance().notifyReportChange();

        if (evt.getPropertyName() == null) return;

        if (evt.getPropertyName().equals( JRDesignReportTemplate.PROPERTY_SOURCE_EXPRESSION ))
        {
            super.setName(Misc.getExpressionText(template.getSourceExpression()));
            super.fireNameChange(null, super.getName());
            super.fireDisplayNameChange(null, getDisplayName());

        }

        // Update the sheet
        this.firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue() );
    }
项目:ireport-fork    文件:AddTemplateReferenceToReportAction.java   
@Override
protected void performAction(Node[] nodes) {

        // Copy the style in the report...
    JasperDesign jd = IReportManager.getInstance().getActiveReport();
    for (int i=0; i<nodes.length; ++i)
    {
        JRTemplateReference reference = nodes[i].getLookup().lookup(JRTemplateReference.class);
        if (reference != null)
        {
                // Copy the reference...
                JRDesignReportTemplate reportTemplate = new JRDesignReportTemplate();
                reportTemplate.setSourceExpression(Misc.createExpression("java.lang.String", "\""+ Misc.string_replace("\\\\","\\",reference.getLocation()) +"\""));
                jd.addTemplate(reportTemplate);
                IReportManager.getInstance().notifyReportChange();
        }
    }

}
项目:jasperreports    文件:JRXmlDigesterFactory.java   
protected static void addTemplateRules(Digester digester)
{
    String templatePattern = JRXmlConstants.ELEMENT_jasperReport + "/" + JRXmlConstants.ELEMENT_template;
    //do not change the order
    digester.addObjectCreate(templatePattern, JRDesignReportTemplate.class);
    digester.addSetNext(templatePattern, "addTemplate", JRReportTemplate.class.getName());
    @SuppressWarnings("deprecation")
    Class<?> lcDepStringExprFactoryClass = JRStringExpressionFactory.class;
    digester.addFactoryCreate(templatePattern, lcDepStringExprFactoryClass);
    digester.addCallMethod(templatePattern, "setText", 0);
    digester.addSetNext(templatePattern, "setSourceExpression", JRExpression.class.getName());
}
项目:PDFReporter-Studio    文件:ExternalStylesManager.java   
/**
 * Check if a style reference expression is valuable or not 
 * 
 * @param template the model that contains the reference information
 * @param true if the expression can be evaluated (because it was already evaluated without errors or
 * because it was never evaluated) false otherwise (during the last attempt to evaluate the expression an
 * error happen)
 */
public static boolean isNotValuable(MStyleTemplate template){
    JasperReportsConfiguration jConf = template.getJasperConfiguration();
    IFile project = (IFile) jConf.get(FileUtils.KEY_FILE);
    String projectPath = project.getLocation().toPortableString();

    JRDesignReportTemplate jrTemplate = (JRDesignReportTemplate) template.getValue();
    String expression =  jrTemplate.getSourceExpression().getText();
    return (notEvaluableExpressions.contains(projectPath + "." + expression));
}
项目:PDFReporter-Studio    文件:ExternalStylesManager.java   
/**
 * Reload a style, ignoring if it expression was already evaluated before
 * 
 * @param template a template style element, the value inside the model must be an
 * instance of JRDesignReportTemplate
 */
public static void refreshStyle(ANode template){
    JasperReportsConfiguration jConf = template.getJasperConfiguration();
    IFile project = (IFile) jConf.get(FileUtils.KEY_FILE);
    String projectPath = project.getLocation().toPortableString();

    JRDesignReportTemplate jrTemplate = (JRDesignReportTemplate) template.getValue();
    String expression =  jrTemplate.getSourceExpression().getText();

    notEvaluableExpressions.remove(projectPath + "." + expression);
    //Recalculate the style overwriting the cache
    String evaluatedExpression = evaluateStyleExpression(jrTemplate, project, jConf);
    if (evaluatedExpression != null) {
        File styleFile = StyleTemplateFactory.getFile(evaluatedExpression, project);
        if (styleFile != null) {
            String key = styleFile.getAbsolutePath();
            List<JRStyle> cachedStyles = new ArrayList<JRStyle>();
            StyleTemplateFactory.getStylesReference(project, evaluatedExpression, cachedStyles, new HashSet<File>());
            externalStylesCache.put(key, cachedStyles);
            fireEvent(STYLE_FOUND_EVENT, jrTemplate);
        } else {
            JRExpression styleExpression = jrTemplate.getSourceExpression();
            String expString = styleExpression != null ? styleExpression.getText() : "";
            addNotValuableExpression(projectPath, expString);
            fireEvent(STYLE_NOT_FOUND_EVENT, jrTemplate);
        }
    }
}
项目:PDFReporter-Studio    文件:StyleTemplateFactory.java   
public static void openEditor(Object obj, IEditorInput editorInput, ANode node) {
    if (obj instanceof JRStyle || obj instanceof JRConditionalStyle) {
        if (node.getParent() instanceof MStyles)
            return;
        if (node instanceof MConditionalStyle)
            node = (ANode) node.getParent();
        if (node instanceof MStyle)
            node = (ANode) node.getParent();
    }
    if (node instanceof MStyleTemplate)
        obj = node.getValue();
    else if (node instanceof MStyleTemplateReference) {
        IFile file = getFile(node, ((FileEditorInput) editorInput).getFile());
        JRTemplateReference st = (JRTemplateReference) node.getValue();
        SelectionHelper.openEditor(file, st.getLocation());
    }

    if (obj instanceof JRDesignReportTemplate) {
        if (editorInput instanceof FileEditorInput) {
            JRDesignReportTemplate s = (JRDesignReportTemplate) obj;
            if (s.getSourceExpression() != null)
                SelectionHelper.openEditor((FileEditorInput) editorInput,
                        ExpressionUtil.eval(s.getSourceExpression(), node.getJasperConfiguration()));
        }
        return;
    }
}
项目:PDFReporter-Studio    文件:StyleTemplateFactory.java   
private static IFile getFile(ANode node, IFile refFile) {
    List<Object> plist = new ArrayList<Object>();
    ANode p = (ANode) node;
    JasperReportsConfiguration jConfig = node.getJasperConfiguration();
    plist.add(p.getValue());
    while (!(p.getParent() instanceof MStyles)) {
        p = (ANode) p.getParent();
        plist.add(p.getValue());
    }

    MStyleTemplate mst = (MStyleTemplate) p;
    JRDesignReportTemplate drt = (JRDesignReportTemplate) mst.getValue();

    return resolveTemplates(refFile, plist, jConfig, drt);
}
项目:PDFReporter-Studio    文件:StyleTemplateFactory.java   
protected static IFile resolveTemplates(IFile refFile, List<Object> plist, JasperReportsConfiguration jConfig,
        JRDesignReportTemplate drt) {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    String str = ExpressionUtil.eval(drt.getSourceExpression(), jConfig);
    if (str != null) {
        if (refFile == null)
            refFile = ((IFileEditorInput) SelectionHelper.getActiveJRXMLEditor().getEditorInput()).getFile();

        for (int i = plist.size() - 1; i >= 0; i--) {
            Object obj = plist.get(i);
            if (obj instanceof JRDesignReportTemplate) {
                str = ExpressionUtil.eval(((JRDesignReportTemplate) obj).getSourceExpression(), jConfig);
            } else if (obj instanceof JRTemplateReference) {
                str = ((JRTemplateReference) obj).getLocation();
            }

            FileResolver fileResolver = SelectionHelper.getFileResolver(refFile);
            File fileToBeOpened = fileResolver.resolveFile(str);
            if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) {
                IFile[] fs = root.findFilesForLocationURI(fileToBeOpened.toURI());
                if (fs != null && fs.length > 0) {
                    refFile = fs[0];
                } else
                    break;
            }
        }
        return refFile;
    }
    return null;
}
项目:PDFReporter-Studio    文件:MStyleTemplate.java   
@Override
public void createPropertyDescriptors(List<IPropertyDescriptor> desc, Map<String, Object> defaultsMap) {
    JRExpressionPropertyDescriptor sourceExpression = new JRExpressionPropertyDescriptor(
            JRDesignReportTemplate.PROPERTY_SOURCE_EXPRESSION, Messages.MStyleTemplate_source_expression);
    sourceExpression.setDescription(Messages.MStyleTemplate_source_expression_description);
    desc.add(sourceExpression);

    setHelpPrefix(desc, "net.sf.jasperreports.doc/docs/schema.reference.html?cp=0_1#template");
}
项目:PDFReporter-Studio    文件:MStyleTemplate.java   
public String getDisplayText() {
    JRDesignReportTemplate jt = (JRDesignReportTemplate) getValue();
    if (jt != null && jt.getSourceExpression() != null && jt.getSourceExpression().getText() != null){
        return  getIconDescriptor().getTitle() + "(" + jt.getSourceExpression().getText() + ")";
    }
    return getIconDescriptor().getTitle();
}
项目:PDFReporter-Studio    文件:MStyleTemplate.java   
/**
 * Return the image for this element, the image change if the style can not be resolved, in this 
 * way we can show something like an error decorator if the expression of the style is not solvable
 */
public ImageDescriptor getImagePath() {
    JRDesignReportTemplate jt = (JRDesignReportTemplate) getValue();
    if (jt != null && jt.getSourceExpression() != null && jt.getSourceExpression().getText() != null && ExternalStylesManager.isNotValuable(this)){
        return styleNotFoundImage;
    }
    return getIconDescriptor().getIcon16();
}
项目:PDFReporter-Studio    文件:MStyleTemplate.java   
/**
 * Return the textual tooltip of the style. If its expression can not be solved an error message is also 
 * shown
 */
@Override
public String getToolTip() {
    JRDesignReportTemplate jt = (JRDesignReportTemplate) getValue();
    if (jt != null && jt.getSourceExpression() != null && jt.getSourceExpression().getText() != null && ExternalStylesManager.isNotValuable(this)){
        return "The resource can not be found, fix the expression and reload the style to use it";
    } else  return getIconDescriptor().getToolTip();
}
项目:PDFReporter-Studio    文件:MStyleTemplate.java   
public Object getPropertyValue(Object id) {
    JRDesignReportTemplate jrTemplate = (JRDesignReportTemplate) getValue();
    if (id.equals(JRDesignReportTemplate.PROPERTY_SOURCE_EXPRESSION))
        return ExprUtil.getExpression(jrTemplate.getSourceExpression());

    return null;
}
项目:PDFReporter-Studio    文件:MStyleTemplate.java   
@Override
public void propertyChange(PropertyChangeEvent evt) {
    //If the expression change try to reload the style
    if (evt.getPropertyName().equals(JRDesignReportTemplate.PROPERTY_SOURCE_EXPRESSION)){
        performUpdate();
    }
    super.propertyChange(evt);
}
项目:PDFReporter-Studio    文件:MStyleTemplate.java   
/**
 * Refresh the children of a template sytle by reloading them from the external styles cache
 */
public void refreshChildren(){
    JasperReportsConfiguration jConf = getJasperConfiguration();
    IFile project = (IFile) jConf.get(FileUtils.KEY_FILE);
    JRDesignReportTemplate jrTemplate = (JRDesignReportTemplate) getValue();
    getChildren().clear();
    List<JRStyle> styles = ExternalStylesManager.getStyles(jrTemplate, project, jConf);

    for (JRStyle s : styles) {
        APropertyNode n = (APropertyNode) ReportFactory.createNode(getActualStyle(), s, -1);
        n.setEditable(false);
    }
    fireChildrenChangeEvent();
}
项目:PDFReporter-Studio    文件:CreateStyleTemplateCommand.java   
private void createObject() {
    if (jrTemplate == null) {
        FilteredResourcesSelectionDialog fd = new FilteredHelpDialog(Display.getCurrent().getActiveShell(),false, ResourcesPlugin.getWorkspace().getRoot(), IResource.FILE);
        fd.setInitialPattern("*.jrtx");//$NON-NLS-1$
        if (fd.open() == Dialog.OK) {
            IFile file = (IFile) fd.getFirstResult();
            File  fileToBeOpened = file.getRawLocation().makeAbsolute().toFile();
            boolean showErrorMessage = false;
            //Check if the file is a valid template before add it to the model
            if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) {
                try{
                    //Try to load the file to see if it is a valid template
                    JRXmlTemplateLoader.load(fileToBeOpened);
                    this.jrTemplate = MStyleTemplate.createJRTemplate();
                    JRDesignExpression jre = new JRDesignExpression();
                    jre.setText("\"" + getStylePath(file) + "\"");//$NON-NLS-1$ //$NON-NLS-2$
                    ((JRDesignReportTemplate) jrTemplate).setSourceExpression(jre);
                } catch(Exception ex){
                    showErrorMessage = true;
                }
            } else {
                showErrorMessage = true;
            }
            if (showErrorMessage){
                MessageDialog.open(MessageDialog.ERROR, Display.getCurrent().getActiveShell(), Messages.UIUtils_ExceptionTitle, Messages.CreateStyleTemplateCommand_loadStyleError, SWT.NONE);
            }
        }
    }
}
项目:ireport-fork    文件:StylesChildren.java   
protected Node[] createNodes(Object key) {

        if (key instanceof JRDesignStyle)
        {
            return new Node[]{new StyleNode(jd, (JRDesignStyle)key, doLkp)};
        }
        else //if (key instanceof JRReportTemplate)
        {
            return new Node[]{new TemplateReferenceNode(jd, (JRDesignReportTemplate)key, doLkp)};
        }
    }
项目:ireport-fork    文件:TemplateReferenceChildren.java   
@SuppressWarnings("unchecked")
public TemplateReferenceChildren(JasperDesign jd, JRDesignReportTemplate template,JRDesignDataset dataset, Lookup doLkp) {
    super(new ArrayList());
    this.jd = jd;
    this.doLkp=doLkp;
    this.template = template;
    this.template.getEventSupport().addPropertyChangeListener(this);
}
项目:ireport-fork    文件:TemplateReferenceChildren.java   
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName() == null) return;
    if (evt.getPropertyName().equals( JRDesignReportTemplate.PROPERTY_SOURCE_EXPRESSION ))
    {
        recalculateKeys();
    }
}
项目:ireport-fork    文件:TemplateReferenceNode.java   
public TemplateReferenceNode(JasperDesign jd, JRDesignReportTemplate template, Lookup doLkp)
{
    super (new TemplateReferenceChildren(jd, template, doLkp), new ProxyLookup(doLkp, Lookups.fixed(jd, template)));
    this.jd = jd;
    this.template = template;
    init();
    template.getEventSupport().addPropertyChangeListener(this);
}
项目:ireport-fork    文件:TemplateReferenceNode.java   
@SuppressWarnings("unchecked")
public SourceExpressionProperty(JRDesignReportTemplate template, JasperDesign jd)
{
    super(template, jd.getMainDesignDataset());

    setName(JRDesignReportTemplate.PROPERTY_SOURCE_EXPRESSION);
    setDisplayName("Source Expression");
    this.template = template;
    this.jd = jd;
}
项目:ireport-fork    文件:TemplateReferenceNode.java   
public SourceExpressionClassNameProperty(JRDesignReportTemplate template)
{
    super(JRDesignExpression.PROPERTY_VALUE_CLASS_NAME, String.class,
          I18n.getString("Expression_Class"),
          I18n.getString("Expression_Class"));
    this.template = template;

    setValue("canEditAsText", true);
    setValue("oneline", true);
    setValue("suppressCustomEditor", false);
}
项目:ireport-fork    文件:DragTemplateReferenceAction.java   
@Override
public void drop(DropTargetDropEvent dtde) {

    JasperDesign jd = getJasperDesign();
    Object toActivate = null;

    JRTemplateReference reference = (JRTemplateReference)getPaletteItem().getData();
    if (reference != null)
    {
            // Copy the reference...
            JRDesignReportTemplate reportTemplate = new JRDesignReportTemplate();
            reportTemplate.setSourceExpression(Misc.createExpression("java.lang.String", "\""+ Misc.string_replace("\\\\","\\",reference.getLocation()) +"\""));
            jd.addTemplate(reportTemplate);
            IReportManager.getInstance().notifyReportChange();
            toActivate = reportTemplate;
    }

    final Object obj = toActivate;

    if (obj != null)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                IReportManager.getInstance().setSelectedObject(obj);
                IReportManager.getInstance().getActiveVisualView().requestActive();
                IReportManager.getInstance().getActiveVisualView().requestAttention(true);
            }
        });
    }
}
项目:PDFReporter-Studio    文件:StyleTemplateSection.java   
@Override
protected void initializeProvidedProperties() {
    super.initializeProvidedProperties();
    addProvidedProperties(JRDesignReportTemplate.PROPERTY_SOURCE_EXPRESSION, Messages.MStyleTemplate_source_expression);
}
项目:PDFReporter-Studio    文件:MStyleTemplate.java   
public void setPropertyValue(Object id, Object value) {
    JRDesignReportTemplate jrTemplate = (JRDesignReportTemplate) getValue();
    if (id.equals(JRDesignReportTemplate.PROPERTY_SOURCE_EXPRESSION))
        jrTemplate.setSourceExpression(ExprUtil.setValues(jrTemplate.getSourceExpression(), value));
}
项目:PDFReporter-Studio    文件:DeleteStyleTemplateCommand.java   
/**
 * Instantiates a new delete style template command.
 */
public DeleteStyleTemplateCommand(MStyles destNode, MStyleTemplate srcNode) {
    super();
    this.jrDesign = srcNode.getJasperDesign();
    this.jrTemplate = (JRDesignReportTemplate) srcNode.getValue();
}
项目:ireport-fork    文件:TemplateReferenceChildren.java   
public TemplateReferenceChildren(JasperDesign jd, JRDesignReportTemplate template, Lookup doLkp) {
    this(jd, template, jd.getMainDesignDataset(),doLkp);
    this.template = template;
}
项目:ireport-fork    文件:TemplateReferenceNode.java   
/**
 * @param template the template to set
 */
public void setTemplate(JRDesignReportTemplate template) {
    this.template = template;
}
项目:PDFReporter-Studio    文件:StyleTemplateSection.java   
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
    super.createControls(parent, tabbedPropertySheetPage);

    parent.setLayout(new GridLayout(2, false));

    createWidget4Property(parent, JRDesignReportTemplate.PROPERTY_SOURCE_EXPRESSION);
}
项目:PDFReporter-Studio    文件:CreateStyleTemplateCommand.java   
/**
 * Instantiates a new creates the style template command.
 * 
 * @param destNode
 *          the dest node
 * @param srcNode
 *          the src node
 * @param index
 *          the index
 */
public CreateStyleTemplateCommand(MStyles destNode, MStyleTemplate srcNode, int index) {
    super();
    this.jrDesign = destNode.getJasperDesign();
    this.jConfig = destNode.getJasperConfiguration();
    this.index = index;
    if (srcNode != null && srcNode.getValue() != null)
        this.jrTemplate = (JRDesignReportTemplate) srcNode.getValue();
}
项目:PDFReporter-Studio    文件:ReorderStyleTemplateCommand.java   
/**
 * Instantiates a new reorder style template command.
 * 
 * @param child
 *          the child
 * @param parent
 *          the parent
 * @param newIndex
 *          the new index
 */
public ReorderStyleTemplateCommand(MStyleTemplate child, MStyles parent, int newIndex) {
    super(Messages.common_reorder_elements);
    this.newIndex = Math.max(0, newIndex);
    this.jrDesign = parent.getJasperDesign();
    this.jrTemplate = (JRDesignReportTemplate) child.getValue();
}
项目:PDFReporter-Studio    文件:ReorderStyleTemplateCommand.java   
/**
 * Instantiates a new reorder style template command.
 * 
 * @param child
 *          the child
 * @param parent
 *          the parent
 * @param newIndex
 *          the new index
 */
public ReorderStyleTemplateCommand(MStyleTemplate child, MStyles parent, int newIndex) {
    super(Messages.common_reorder_elements);
    this.newIndex = newIndex;
    this.jrDesign = parent.getJasperDesign();
    this.jrTemplate = (JRDesignReportTemplate) child.getValue();
}
项目:PDFReporter-Studio    文件:StylesListSection.java   
/**
 * Return the value of the template
 * 
 * @return the JRElement of the template
 */
public JRDesignReportTemplate getTemplateValue() {
    return (JRDesignReportTemplate) externalTemplate.getValue();
}
项目:PDFReporter-Studio    文件:MStyleTemplate.java   
/**
 * Creates the jr template.
 * 
 * @return the jR design report template
 */
public static JRDesignReportTemplate createJRTemplate() {
    JRDesignReportTemplate jrDesignReportTemplate = new JRDesignReportTemplate();
    return jrDesignReportTemplate;
}