public File publish(JasperDesign jd, JRReportTemplate img, MReportUnit mrunit, IProgressMonitor monitor, Set<String> fileset, IFile file) throws Exception { AFileResource fres = findFile(mrunit, monitor, jd, fileset, getExpression(img), file); if (fres != null) { JRSimpleTemplate jrt = (JRSimpleTemplate) JRXmlTemplateLoader.load(fres.getFile()); for (JRTemplateReference r : jrt.getIncludedTemplatesList()) { IFile[] fs = root.findFilesForLocationURI(fres.getFile().toURI()); if (fs != null && fs.length > 0) { File ftr = findFile(file, r.getLocation()); if (ftr != null && ftr.exists()) { fileset.add(ftr.getAbsolutePath()); addResource(monitor, mrunit, fileset, ftr, new PublishOptions()); } } } return fres.getFile(); } return null; }
public static void getStylesReference(IFile file, String location, List<JRStyle> list, Set<File> files) { if (location == null) return; File fileToBeOpened = getFile(location, file); if (files.contains(fileToBeOpened)) return; if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) { files.add(fileToBeOpened); JRSimpleTemplate jrst = (JRSimpleTemplate) JRXmlTemplateLoader.load(fileToBeOpened); list.addAll(jrst.getStylesList()); List<JRTemplateReference> tlist = jrst.getIncludedTemplatesList(); if (tlist != null && !tlist.isEmpty()) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IFile[] fs = root.findFilesForLocationURI(fileToBeOpened.toURI()); if (fs != null && fs[0] != null) for (JRTemplateReference tr : tlist) getStylesReference(fs[0], tr.getLocation(), list, files); } } }
public static void getStylesReference(String absoulteLocation, List<JRStyle> list, Set<File> files) { if (absoulteLocation == null) return; File fileToBeOpened = new File(absoulteLocation); if (files.contains(fileToBeOpened)) return; if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) { files.add(fileToBeOpened); JRSimpleTemplate jrst = (JRSimpleTemplate) JRXmlTemplateLoader.load(fileToBeOpened); list.addAll(jrst.getStylesList()); List<JRTemplateReference> tlist = jrst.getIncludedTemplatesList(); if (tlist != null && !tlist.isEmpty()) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IFile[] fs = root.findFilesForLocationURI(fileToBeOpened.toURI()); if (fs != null && fs[0] != null) for (JRTemplateReference tr : tlist) getStylesReference(fs[0], tr.getLocation(), list, files); } } }
@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(); } } }
protected void writeIncludedTemplates() throws IOException { JRTemplateReference[] includedTemplates = template.getIncludedTemplates(); if (includedTemplates != null) { for (int i = 0; i < includedTemplates.length; i++) { JRTemplateReference reference = includedTemplates[i]; writeIncludedTemplate(reference); } } }
protected void collectIncludedTemplates(JRTemplate template, List<JRStyle> externalStyles, Set<String> loadedLocations, Set<String> templateParentLocations) throws JRException { JRTemplateReference[] includedTemplates = template.getIncludedTemplates(); if (includedTemplates != null) { for (int i = 0; i < includedTemplates.length; i++) { JRTemplateReference reference = includedTemplates[i]; String location = reference.getLocation(); if (!templateParentLocations.add(location)) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_CIRCULAR_DEPENDENCY_FOUND, new Object[]{location} ); } if (loadedLocations.add(location)) { //template not yet loaded JRTemplate includedTemplate = JRFillReportTemplate.loadTemplate( location, this); collectStyles(includedTemplate, externalStyles, loadedLocations, templateParentLocations); } } } }
public static ANode createNode(ANode parent, Object obj, int index, IFile file, JRSimpleTemplate jrst) { if (obj instanceof JRDesignStyle) { index += jrst.getIncludedTemplatesList().size(); return new MStyle(parent, (JRDesignStyle) obj, index); } if (obj instanceof JRTemplateReference) { ANode n = new MStyleTemplateReference(parent, (JRTemplateReference) obj, index); createTemplateReference(n, ((JRTemplateReference) obj).getLocation(), -1, new HashSet<String>(), false, file); } return null; }
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; } }
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; }
public Object getPropertyValue(Object id) { JRTemplateReference jrTemplate = (JRTemplateReference) getValue(); if (id.equals(PROPERTY_LOCATION)) { //$NON-NLS-1$ return jrTemplate.getLocation(); } return null; }
public void setPropertyValue(Object id, Object value) { if (isEditable()) { JRTemplateReference jrTemplate = (JRTemplateReference) getValue(); if (id.equals(PROPERTY_LOCATION)) //$NON-NLS-1$ jrTemplate.setLocation((String) value); } }
@Override protected boolean enable(Node[] nodes) { if (IReportManager.getInstance().getActiveReport() == null) return false; for (int i=0; i<nodes.length; ++i) { if (nodes[i].getLookup().lookup(JRTemplateReference.class) == null) return false; } return nodes.length > 0; }
@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); } }); } }
@Override protected Node[] createNodes(Object key) { Node node = null; if (key instanceof JRDesignStyle) { node = new LibraryStyleNode(getTemplate(), (JRDesignStyle)key, getDoLkp()); } else if (key instanceof JRTemplateReference) { node = new LibraryTemplateReferenceNode(getTemplate(), (JRTemplateReference)key, getDoLkp()); } return new Node[]{node}; }
protected Node[] createNodes(Object key) { Node node = null; if (key instanceof JRDesignStyle) { node = new StyleNode(getTemplate(), (JRDesignStyle)key,getDoLkp()); } else if (key instanceof JRTemplateReference) { node = new TemplateReferenceNode(getTemplate(), (JRTemplateReference)key,getDoLkp()); } return new Node[]{node}; }
public TemplateReferenceNode(JRSimpleTemplate template, JRTemplateReference reference, Lookup doLkp) { super (Children.LEAF, new ProxyLookup(doLkp, Lookups.fixed(template, reference))); this.template = template; this.reference = reference; init(); }
@SuppressWarnings("unchecked") public LocationProperty(JRTemplateReference reference, JRSimpleTemplate template, TemplateReferenceNode node) { super( Node.PROP_NAME, String.class, "Location", "Location"); this.setReference(reference); this.template = template; this.node = node; this.setValue("oneline", Boolean.TRUE); }
protected void loadTemplateStyles(String location, Set<String> loadedLocations, Set<String> parentLocations) { if (!parentLocations.add(location)) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_CIRCULAR_DEPENDENCY_FOUND, new Object[]{location} ); } if (!loadedLocations.add(location)) { //already loaded return; } JRTemplate template; try { template = JRXmlTemplateLoader.getInstance(getJasperReportsContext()).loadTemplate(location); } catch (Exception e) { log.warn("Could not load template from location " + location + "; some styles might remain unresolved."); return; } JRTemplateReference[] includedTemplates = template.getIncludedTemplates(); if (includedTemplates != null) { for (int i = 0; i < includedTemplates.length; i++) { JRTemplateReference reference = includedTemplates[i]; loadTemplateStyles(reference.getLocation(), loadedLocations, parentLocations); } } collectStyles(template.getStyles()); }
protected void writeIncludedTemplate(JRTemplateReference reference) throws IOException { writer.writeCDATAElement(JRXmlConstants.TEMPLATE_ELEMENT_INCLUDED_TEMPLATE, reference.getLocation()); }
public String getDisplayText() { JRTemplateReference jt = (JRTemplateReference) getValue(); if (jt != null && jt.getLocation() != null) return iconDescriptor.getTitle() + "(" + jt.getLocation() + ")";//$NON-NLS-1$ //$NON-NLS-2$ return iconDescriptor.getTitle(); }
/** * Instantiates a new delete style template command. */ public DeleteStyleTemplateCommand(MStylesTemplate destNode, MStyleTemplateReference srcNode) { super(); this.jrDesign = (JRSimpleTemplate) destNode.getValue(); this.jrTemplate = (JRTemplateReference) srcNode.getValue(); }
public LibraryTemplateReferenceNode(JRSimpleTemplate template, JRTemplateReference reference, Lookup doLkp) { super (template, reference, doLkp); }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Node node = Visualizer.findNode(value); if (node != null) value = node; if (value instanceof LibraryStyleNode) { JRStyle style = ((LibraryStyleNode)value).getStyle(); String fontName = style.getFontName(); if (fontName == null) fontName = "SansSerif"; int size = style.getFontSize() == null ? 10 : style.getFontSize(); int font_style = 0; if (style.isBold() != null && style.isBold().booleanValue()) font_style |= Font.BOLD; if (style.isItalic() != null && style.isItalic().booleanValue()) font_style |= Font.ITALIC; label.setFont(new Font(fontName,font_style, size)); String text = style.getName(); if (style.isStrikeThrough() != null && style.isStrikeThrough().booleanValue()) text = "<s>" + text + "</s>"; if (style.isUnderline() != null && style.isUnderline().booleanValue()) text = "<u>" + text + "</u>"; label.setIcon(null); label.setText("<html>" +text); if (!isSelected) { label.setForeground(style.getForecolor()); if (style.getModeValue() != null && style.getModeValue() == ModeEnum.OPAQUE) { label.setBackground(style.getBackcolor()); label.setOpaque(true); } } } else if (value instanceof LibraryTemplateReferenceNode) { JRTemplateReference template = ((LibraryTemplateReferenceNode)value).getReference(); label.setText( ((LibraryTemplateReferenceNode)value).getDisplayName() ); Image img = ((LibraryTemplateReferenceNode)value).getIcon(BeanInfo.ICON_COLOR_16x16); if (img != null) { label.setIcon( new ImageIcon(img)); } else { label.setIcon(null); } } label.setPreferredSize(null); Dimension d = label.getPreferredSize(); if (d != null) { d.height += 4; setPreferredSize(d); } return label; }
/** * @return the reference */ public JRTemplateReference getReference() { return reference; }
/** * @param reference the reference to set */ public void setReference(JRTemplateReference reference) { this.reference = reference; }
/** * Instantiates a new creates the style template command. * * @param destNode * the dest node * @param srcNode * the src node * @param index * the index */ public CreateStyleTemplateReferenceCommand(MStylesTemplate destNode, MStyleTemplateReference srcNode, int index) { super(); this.jrDesign = (JRSimpleTemplate) destNode.getValue(); this.index = index; if (srcNode != null && srcNode.getValue() != null) this.jrTemplate = (JRTemplateReference) srcNode.getValue(); }
/** * Instantiates a new m style template. * * @param parent * the parent * @param jrstyle * the jrstyle * @param newIndex * the new index */ public MStyleTemplateReference(ANode parent, JRTemplateReference jrstyle, int newIndex) { super(parent, newIndex); setValue(jrstyle); }
/** * Creates the jr template. * * @return the jR design report template */ public static JRTemplateReference createJRTemplate() { JRTemplateReference jrDesignReportTemplate = new JRTemplateReference(); return jrDesignReportTemplate; }