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

项目:jasperreports    文件:JRDatasetFactory.java   
@Override
public Object createObject(Attributes attributes)
{
    JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1);
    JRDesignDataset dataset = new JRDesignDataset(xmlLoader.getJasperReportsContext(), false);

    dataset.setName(attributes.getValue(JRXmlConstants.ATTRIBUTE_name));
    dataset.setScriptletClass(attributes.getValue(JRXmlConstants.ATTRIBUTE_scriptletClass));

    dataset.setResourceBundle(attributes.getValue(JRXmlConstants.ATTRIBUTE_resourceBundle));

    WhenResourceMissingTypeEnum whenResourceMissingType = WhenResourceMissingTypeEnum.getByName(attributes.getValue(JRXmlConstants.ATTRIBUTE_whenResourceMissingType));
    if (whenResourceMissingType != null)
    {
        dataset.setWhenResourceMissingType(whenResourceMissingType);
    }

    String uuid = attributes.getValue(JRXmlConstants.ATTRIBUTE_uuid);
    if (uuid != null)
    {
        dataset.setUUID(UUID.fromString(uuid));
    }

    return dataset;
}
项目:jasperreports    文件:JRXmlLoader.java   
protected JRGroup resolveGroup(String groupName, XmlLoaderReportContext context)
{
    JRGroup group;
    if (context == null)
    {
        // main dataset groups
        Map<String,JRGroup> groupsMap = jasperDesign.getGroupsMap();
        group = groupsMap.get(groupName);
    }
    else
    {
        String datasetName = context.getSubdatesetName();
        JRDesignDataset dataset = (JRDesignDataset) jasperDesign.getDatasetMap().get(datasetName);
        if (dataset == null)
        {
            throw 
                new JRRuntimeException(
                    EXCEPTION_MESSAGE_KEY_SUBDATASET_NOT_FOUND,
                    new Object[]{datasetName});
        }

        group = dataset.getGroupsMap().get(groupName);
    }
    return group;
}
项目:jasperreports    文件:FilterAction.java   
@Override
public void performAction() throws ActionException {
    JRDesignDatasetRun datasetRun = (JRDesignDatasetRun)table.getDatasetRun();

    String datasetName = datasetRun.getDatasetName();

    JasperDesignCache cache = JasperDesignCache.getInstance(getJasperReportsContext(), getReportContext());

    JasperDesign jasperDesign = cache.getJasperDesign(targetUri);
    JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getDatasetMap().get(datasetName);

    // execute command
    try {
        getCommandStack().execute(
            new ResetInCacheCommand(
                new FilterCommand(getJasperReportsContext(), dataset, getFilterData()),
                getJasperReportsContext(),
                getReportContext(), 
                targetUri
                )
            );
    } catch (CommandException e) {
        throw new ActionException(e);
    }
}
项目:jasperreports    文件:SortAction.java   
@Override
public void performAction() throws ActionException {
    JRDesignDatasetRun datasetRun = (JRDesignDatasetRun)table.getDatasetRun();

    String datasetName = datasetRun.getDatasetName();

    JasperDesignCache cache = JasperDesignCache.getInstance(getJasperReportsContext(), getReportContext());

    JasperDesign jasperDesign = cache.getJasperDesign(targetUri);
    JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getDatasetMap().get(datasetName);

    // execute command
    try {
        getCommandStack().execute(
            new ResetInCacheCommand(
                new SortCommand(getJasperReportsContext(), dataset, getSortData()),
                getJasperReportsContext(),
                getReportContext(), 
                targetUri
                )
            );
    } catch (CommandException e) {
        throw new ActionException(e);
    }
}
项目:PDFReporter-Studio    文件:SqlProposalProvider.java   
protected void proposeJRParameter(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    Object obj = getDesigner(context);
    if (obj instanceof SQLQueryDesigner) {
        SQLQueryDesigner d = (SQLQueryDesigner) obj;
        JRDesignDataset ds = d.getjDataset();
        if (ds != null) {
            for (JRParameter p : ds.getParametersList()) {
                if (Number.class.isAssignableFrom(p.getValueClass()) || String.class.isAssignableFrom(p.getValueClass())) {
                    ICompletionProposal proposal = createCompletionProposal(p.getName(), context);
                    if (proposal != null)
                        acceptor.accept(proposal);
                }
            }
        }
    }
}
项目:PDFReporter-Studio    文件:EditPNotExpressionDialog.java   
@Override
protected Control createDialogArea(Composite parent) {
    Composite cmp = (Composite) super.createDialogArea(parent);
    cmp.setLayout(new GridLayout(5, false));

    DataBindingContext bindingContext = new DataBindingContext();

    new Label(cmp, SWT.NONE).setText(Messages.CreateParameterCommand_parameter_name);

    Combo operator = new Combo(cmp, SWT.READ_ONLY);
    JRDesignDataset ds = value.getRoot().getValue();
    List<JRParameter> prms = ds.getParametersList();
    String[] items = new String[prms.size()];
    for (int i = 0; i < items.length; i++)
        items[i] = prms.get(i).getName();
    operator.setItems(items);
    operator.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));

    bindingContext.bindValue(SWTObservables.observeSelection(operator), PojoObservables.observeValue(this, "prm")); //$NON-NLS-1$
    return cmp;
}
项目:PDFReporter-Studio    文件:CrosstabWizard.java   
/**
 * 
 * Return a list of JRCrosstabColumnGroup to be used from a
 * CrosstabWizardColumnPage
 * 
 * @param CrosstabWizard
 * 
 * @return void
 */
public List<Object> getAvailableColumnGroups() {
    List<Object> objects = new ArrayList<Object>();
    JRDesignDataset ds = getDataset();
    if (ds == null)
        return objects;

    String dsname = ds.getName();
    if (ds.isMainDataset())
        dsname = "_MAIN_DATASET"; //$NON-NLS-1$
    if (colGroups == null || !colGroups.getDsname().equals(dsname)) {
        colGroups = new ReportObjects(
                ModelUtils.getReportObjects4Datasource(ds), dsname);
    }

    if (colGroups != null) {
        JRDesignCrosstab jdc = (JRDesignCrosstab) crosstab.getValue();
        for (Object f : colGroups.getReportObects()) {
            objects.add(createColumnGroups(jdc, f));
        }
    }
    return objects;
}
项目:PDFReporter-Studio    文件:CrosstabWizard.java   
/**
 * 
 * Return a list of JRCrosstabRowGroup to be used from a
 * CrosstabWizardColumnPage
 * 
 * @param CrosstabWizard
 * 
 * @return void
 */
public List<Object> getAvailableRowGroups() {
    List<Object> objects = new ArrayList<Object>();
    JRDesignDataset ds = getDataset();
    if (ds == null)
        return objects;

    String dsname = ds.getName();
    if (ds.isMainDataset())
        dsname = "_MAIN_DATASET"; //$NON-NLS-1$
    if (rowGroups == null || !rowGroups.getDsname().equals(dsname)) {
        rowGroups = new ReportObjects(
                ModelUtils.getReportObjects4Datasource(ds), dsname);
    }

    if (rowGroups != null) {
        JRDesignCrosstab jdc = (JRDesignCrosstab) crosstab.getValue();
        for (Object f : rowGroups.getReportObects()) {
            objects.add(createRowGroups(jdc, f));
        }
    }
    return objects;
}
项目:PDFReporter-Studio    文件:CrosstabWizard.java   
/**
 * 
 * Return a list of JRCrosstabRowGroup to be used from a
 * CrosstabWizardColumnPage
 * 
 * @param CrosstabWizard
 * 
 * @return void
 */
public List<Object> getAvailableMeasures() {
    List<Object> objects = new ArrayList<Object>();
    JRDesignDataset ds = getDataset();
    if (ds == null)
        return objects;

    String dsname = ds.getName();
    if (ds.isMainDataset())
        dsname = "_MAIN_DATASET"; //$NON-NLS-1$
    if (measures == null || !measures.getDsname().equals(dsname)) {
        measures = new ReportObjects(
                ModelUtils.getReportObjects4Datasource(ds), dsname);
    }

    if (measures != null) {
        JRDesignCrosstab jdc = (JRDesignCrosstab) crosstab.getValue();
        for (Object f : measures.getReportObects()) {
            objects.add(createMesures(jdc, f));
        }
    }
    return objects;
}
项目:PDFReporter-Studio    文件:ListWizard.java   
@Override
public IWizardPage getNextPage(IWizardPage page) {

    // Configuring next steps..
    if (page == step2) {

        // If we come from this step, we have devided which
        // dataset to use, it could be an existing one, a new one
        // or even an empty one.

        JRDesignDataset listDataset = step1.getSelectedDataset();
        if (listDataset != null && listDataset.getFieldsList().size() > 0)
        {
            getSettings().put( WizardDataSourcePage.DISCOVERED_FIELDS, new ArrayList<Object>( listDataset.getFieldsList() ));
            getSettings().put( WizardDataSourcePage.DISCOVERED_PARAMETERS, new ArrayList<Object>( listDataset.getParametersList() ));
        }
        else
        {
            // we need to skip step3...
            page = step3;
        }
    }
    return super.getNextPage(page);
}
项目:PDFReporter-Studio    文件:ListComponentFactory.java   
public ExpressionContext getElementExpressionContext(Object jrObject) {
    if (jrObject instanceof MList
            && ((MList) jrObject).getValue() instanceof JRDesignComponentElement) {
        MList mlist = (MList) jrObject;
        StandardListComponent listComponent = (StandardListComponent) mlist
                .getValue().getComponent();
        JRDesignDataset designDS = ModelUtils
                .getDesignDatasetForDatasetRun(mlist
                        .getJasperConfiguration().getJasperDesign(),
                        listComponent.getDatasetRun());
        return new ExpressionContext(designDS,
                mlist.getJasperConfiguration());
    }

    return null;
}
项目:PDFReporter-Studio    文件:TableTemplateEngine.java   
@Override
public void setReportDataAdapter(ReportBundle bundle, DataAdapterDescriptor dataadapter, JRPropertiesMap properties) {
    JRDesignDataset tableDataset = (JRDesignDataset)bundle.getJasperDesign().getDatasetMap().get("tableDataset"); //$NON-NLS-1$
    JasperDesign jd = bundle.getJasperDesign();
    for (String key : properties.getPropertyNames()){
        jd.setProperty(key, properties.getProperty(key));
        if (key.contains("ireport")) tableDataset.setProperty(key, properties.getProperty(key)); //$NON-NLS-1$
    }
    tableDataset.setProperty(DataQueryAdapters.DEFAULT_DATAADAPTER, dataadapter.getName());
    jd.setProperty(DataQueryAdapters.DEFAULT_DATAADAPTER, dataadapter.getName());

    //Remove the main dataset query
    JRDesignDataset mainDataset = jd.getMainDesignDataset();

    ((JRDesignQuery) mainDataset.getQuery()).setText(null);
    ((JRDesignQuery) mainDataset.getQuery()).setLanguage(null);
    for (JRField field : mainDataset.getFields())
        mainDataset.removeField(field);
}
项目:PDFReporter-Studio    文件:DatasetDialog.java   
public DatasetDialog(Shell shell, MDataset mdataset, JasperReportsConfiguration jConfig, CommandStack cmdStack) {
    super(shell);
    this.cmdStack = cmdStack;
    this.mdataset = mdataset;
    this.jConfig = jConfig;
    newdataset = (JRDesignDataset) ((JRDesignDataset) mdataset.getValue()).clone();

    mapfields = new HashMap<JRField, JRField>();
    List<JRField> newFieldsList = newdataset.getFieldsList();
    List<JRField> oldFieldsList = mdataset.getValue().getFieldsList();
    for (int i = 0; i < oldFieldsList.size(); i++)
        mapfields.put(oldFieldsList.get(i), newFieldsList.get(i));

    mapparam = new HashMap<JRParameter, JRParameter>();
    List<JRParameter> newParamList = newdataset.getParametersList();
    List<JRParameter> oldParamList = mdataset.getValue().getParametersList();
    for (int i = 0; i < oldParamList.size(); i++)
        mapparam.put(oldParamList.get(i), newParamList.get(i));
}
项目:PDFReporter-Studio    文件:ConnectToDomainWizardPage.java   
@Override
public void createControl(Composite parent) {

    //Calculate which parameters are needed and where they are needed
    String datasetName = (String)connectedDataset.getPropertyActualValue(JRDesignDataset.PROPERTY_NAME);
    runReferences = DeleteDatasetCommand.getDatasetUsage(connectedDataset.getRoot().getChildren(), datasetName);
    missingParamOnMain = getMissingParameterOnMainDataset();
    missingParamOnDataset = getMissingParameterOnDataset();
    missingParamOnRun = getMissingDatasetsRun();

    //Create the appropriate controls for this parameters
  ScrolledComposite scrollComposite = new ScrolledComposite(parent, SWT.V_SCROLL);
  scrollComposite.setExpandVertical(true);
    Composite mainComposite = new Composite(scrollComposite, SWT.NONE);
    scrollComposite.setContent(mainComposite);
    mainComposite.setLayout(new GridLayout(1,false));
    if (missingParamOnMain.isEmpty() && missingParamOnRun.isEmpty() && missingParamOnRun.isEmpty()){
        new Label(mainComposite, SWT.NONE).setText(Messages.ConnectToDomainWizardPage_noChangesLabel);
    } else createNotEmptyContent(mainComposite);
    mainComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    scrollComposite.setMinSize(mainComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    mainComposite.setSize(mainComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
   UIUtils.resizeAndCenterShell(parent.getShell(), 650, 550);
    setControl(mainComposite);
}
项目:PDFReporter-Studio    文件:ModelUtils.java   
/**
 * Verifies if the specified element belongs to a dataset.
 * It makes sense for the element to be a field, variable or parameter.
 * 
 * @param element the element to check
 * @param datasetName the (target) dataset name
 * @return <code>true</code> if the element belongs to the dataset, <code>false</code> otherwise
 */
public static boolean belongsToDataset(APropertyNode element, String datasetName) {
    Assert.isNotNull(element);
    Assert.isNotNull(datasetName);
    if(datasetName!=null) {
        ANode upperParent = element.getParent().getParent();
        if(upperParent instanceof MDataset) {
            JRDesignDataset value = ((MDataset)upperParent).getValue();
            String fDsName = value.getName();
            return datasetName.equals(fDsName);
        }
        else if(upperParent instanceof MReport) {
            MDataset mainDS = (MDataset) ((MReport)upperParent).getPropertyValue(JasperDesign.PROPERTY_MAIN_DATASET);
            String mainDSName = (String) mainDS.getPropertyValue(JRDesignDataset.PROPERTY_NAME);
            return datasetName.equals(mainDSName);              
        }
    }
    return false;
}
项目:PDFReporter-Studio    文件:ExpressionUtil.java   
/**
 * 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);
        }
}
项目:PDFReporter-Studio    文件:ExpressionInterpreter.java   
public ExpressionInterpreter(JRDesignDataset dataset, JasperDesign jasperDesign, JasperReportsConfiguration jConfig) {
    try {
        this.jConfig = jConfig;
        if (jasperDesign.getLanguage().equalsIgnoreCase(JRReport.LANGUAGE_JAVA))
            interpreter = new JavaInterpreter();
        else if (jasperDesign.getLanguage().equalsIgnoreCase(JRReport.LANGUAGE_GROOVY))
            interpreter = new GroovyInterpretter();
        else if (jasperDesign.getLanguage().equalsIgnoreCase("bsh"))
            interpreter = new JavaInterpreter();
        else if (jasperDesign.getLanguage().equalsIgnoreCase("jeval"))
            interpreter = new JEvalInterpreter();

        if (interpreter != null) interpreter.prepareExpressionEvaluator(dataset, jasperDesign, jConfig);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
项目:PDFReporter-Studio    文件:AInterpreter.java   
public void prepareExpressionEvaluator(JRDesignDataset dataset, JasperDesign jasperDesign,
        JasperReportsConfiguration jConfig) throws Exception {
    this.dataset = dataset;
    this.jasperDesign = jasperDesign;
    this.jConfig = jConfig;
    try {
        IFile file = (IFile) jConfig.get(FileUtils.KEY_FILE);
        if (file != null) {
            IProject project = file.getProject();
            if (project.getNature(JavaCore.NATURE_ID) != null)
                javaProject = JavaCore.create(project);
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }

    classLoader = jConfig.getClassLoader();
    if (classLoader == null) {
        if (jasperDesign != null)
            classLoader = jasperDesign.getClass().getClassLoader();
        else
            classLoader = Thread.currentThread().getContextClassLoader();
    }
}
项目:jasperreports    文件:JRXmlDigesterFactory.java   
private static void addDatasetRules(Digester digester)
{
    String subDatasetPattern = "jasperReport/" + JRXmlConstants.ELEMENT_subDataset;
    digester.addFactoryCreate(subDatasetPattern, JRDatasetFactory.class.getName());
    digester.addSetNext(subDatasetPattern, "addDataset", JRDesignDataset.class.getName());

    String datasetRunPattern = "*/" + JRXmlConstants.ELEMENT_datasetRun;
    digester.addFactoryCreate(datasetRunPattern, JRDatasetRunFactory.class.getName());
    digester.addSetNext(datasetRunPattern, "setDatasetRun", JRDatasetRun.class.getName());

    String datasetParamPattern = datasetRunPattern + "/" + JRXmlConstants.ELEMENT_datasetParameter;
    digester.addFactoryCreate(datasetParamPattern, JRDatasetRunParameterFactory.class.getName());
    digester.addSetNext(datasetParamPattern, "addParameter", JRDatasetParameter.class.getName());

    String datasetParamExprPattern = datasetParamPattern + "/" + JRXmlConstants.ELEMENT_datasetParameterExpression;
    digester.addFactoryCreate(datasetParamExprPattern, JRExpressionFactory.class.getName());
    digester.addSetNext(datasetParamExprPattern, "setExpression", JRExpression.class.getName());
    digester.addCallMethod(datasetParamExprPattern, "setText", 0);

    String returnValuePattern = datasetRunPattern + "/" + JRXmlConstants.ELEMENT_returnValue;
    digester.addObjectCreate(returnValuePattern, DesignReturnValue.class.getName());
    digester.addSetProperties(returnValuePattern, 
            new String[]{JRXmlConstants.ATTRIBUTE_incrementerFactoryClass, JRXmlConstants.ATTRIBUTE_calculation}, 
            new String[]{"incrementerFactoryClassName"});
    digester.addRule(returnValuePattern, new XmlConstantPropertyRule(
            JRXmlConstants.ATTRIBUTE_calculation, CalculationEnum.values()));
    digester.addSetNext(returnValuePattern, "addReturnValue");
}
项目:jasperreports    文件:HeaderToolbarElementUtils.java   
/**
 * 
 */
public static JRField getField(String name, JRDesignDataset dataSet) 
{
    JRField found = null;
    for (JRField field : dataSet.getFields())
    {
        if (name.equals(field.getName()))
        {
            found = field;
            break;
        }
    }
    return found;
}
项目:jasperreports    文件:HeaderToolbarElementUtils.java   
/**
 * 
 */
public static JRVariable getVariable(String name, JRDesignDataset dataSet) 
{
    JRVariable found = null;
    for (JRVariable var : dataSet.getVariables())
    {
        if (name.equals(var.getName()))
        {
            found = var;
            break;
        }
    }
    return found;
}
项目:jasperreports    文件:SortElementJsonHandler.java   
private String getCurrentSortField(JasperReportsContext jasperReportsContext, ReportContext reportContext, String uuid, String sortDatasetName, String sortColumnName, String sortColumnType) 
{
    JasperDesignCache cache = JasperDesignCache.getInstance(jasperReportsContext, reportContext);
    SortAction action = new SortAction();
    action.init(jasperReportsContext, reportContext);
    CommandTarget target = action.getCommandTarget(UUID.fromString(uuid));
    if (target != null)
    {
        JasperDesign jasperDesign = cache.getJasperDesign(target.getUri());
        JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getMainDataset();

        List<JRSortField> existingFields =  dataset.getSortFieldsList();
        String sortField = null;

        if (existingFields != null && existingFields.size() > 0) {
            for (JRSortField field: existingFields) {
                if (field.getName().equals(sortColumnName) && field.getType().getName().equals(sortColumnType)) {
                    sortField = sortColumnName + SortElement.SORT_COLUMN_TOKEN_SEPARATOR + sortColumnType + SortElement.SORT_COLUMN_TOKEN_SEPARATOR;
                    switch (field.getOrderValue()) {
                        case ASCENDING:
                            sortField += SortElement.SORT_ORDER_ASC;
                            break;
                        case DESCENDING:
                            sortField += SortElement.SORT_ORDER_DESC;
                            break;
                    }
                    break;
                }
            }
        }

        return sortField;
    }

    return null;
}
项目:jasperreports    文件:SortElementJsonHandler.java   
private List<FieldFilter> getExistingFiltersForField(
    JasperReportsContext jasperReportsContext, 
    ReportContext reportContext, 
    String uuid, 
    String filterFieldName
    ) 
{
    JasperDesignCache cache = JasperDesignCache.getInstance(jasperReportsContext, reportContext);
    FilterAction action = new FilterAction();
    action.init(jasperReportsContext, reportContext);
    CommandTarget target = action.getCommandTarget(UUID.fromString(uuid));
    List<FieldFilter> result = new ArrayList<FieldFilter>();
    if (target != null)
    {
        JasperDesign jasperDesign = cache.getJasperDesign(target.getUri());
        JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getMainDataset();

        // get existing filter as JSON string
        String serializedFilters = "[]";
        JRPropertiesMap propertiesMap = dataset.getPropertiesMap();
        if (propertiesMap.getProperty(FilterCommand.DATASET_FILTER_PROPERTY) != null) {
            serializedFilters = propertiesMap.getProperty(FilterCommand.DATASET_FILTER_PROPERTY);
        }

        List<? extends DatasetFilter> existingFilters = JacksonUtil.getInstance(jasperReportsContext).loadList(serializedFilters, FieldFilter.class);
        if (existingFilters.size() > 0) {
            for (DatasetFilter filter: existingFilters) {
                if (((FieldFilter)filter).getField().equals(filterFieldName)) {
                    result.add((FieldFilter)filter);
                    break;
                }
            }
        }
    }

    return result;
}
项目:jasperreports    文件:FilterAction.java   
@Override
public void performAction() throws ActionException {

    if (filterData != null) {
        CommandTarget target = getCommandTarget(UUID.fromString(filterData.getTableUuid()));
        if (target != null)
        {
            JasperDesignCache cache = JasperDesignCache.getInstance(getJasperReportsContext(), getReportContext());

            JasperDesign jasperDesign = cache.getJasperDesign(target.getUri());
            JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getMainDataset();

            // obtain command stack
            CommandStack commandStack = getCommandStack();

            // execute command
            try {
                commandStack.execute(
                    new ResetInCacheCommand(
                        new FilterCommand(getJasperReportsContext(), dataset, getFilterData()),
                        getJasperReportsContext(),
                        getReportContext(), 
                        target.getUri()
                        )
                    );
            } catch (CommandException e) {
                 throw new ActionException(e);
            }
        }
    }
}
项目:jasperreports    文件:SortCommand.java   
public SortCommand(JasperReportsContext jasperReportsContext, JRDesignDataset dataset, SortData sortData) 
    //public AbstractSortCommand(ReportContext reportContext, SortData sortData) 
    {
//      this.reportContext = reportContext;
        this.jasperReportsContext = jasperReportsContext;
        this.dataset = dataset;
        this.sortData = sortData;
//      this.cache = JasperDesignCache.getInstance(reportContext);
        this.individualCommandStack = new CommandStack();
    }
项目:jasperreports    文件:SortAction.java   
@Override
public void performAction() throws ActionException
{
    if (sortData != null) 
    {
        CommandTarget target = getCommandTarget(UUID.fromString(sortData.getTableUuid()));
        if (target != null)
        {
            JasperDesignCache cache = JasperDesignCache.getInstance(getJasperReportsContext(), getReportContext());

            JasperDesign jasperDesign = cache.getJasperDesign(target.getUri());
            JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getMainDataset();

            // obtain command stack
            CommandStack commandStack = getCommandStack();

            // execute command
            try {
                commandStack.execute(
                    new ResetInCacheCommand(
                        new SortCommand(getJasperReportsContext(), dataset, sortData),
                        getJasperReportsContext(),
                        getReportContext(),
                        target.getUri()
                        )
                    );
            } catch (CommandException e) {
                 throw new ActionException(e);
            }
        }
    }
}
项目:jasperreports    文件:SortElementHtmlHandler.java   
private String getCurrentSortField(JasperReportsContext jasperReportsContext, ReportContext reportContext, String uuid, String sortDatasetName, String sortColumnName, String sortColumnType) 
{
    JasperDesignCache cache = JasperDesignCache.getInstance(jasperReportsContext, reportContext);
    SortAction action = new SortAction();
    action.init(jasperReportsContext, reportContext);
    CommandTarget target = action.getCommandTarget(UUID.fromString(uuid));
    if (target != null)
    {
        JasperDesign jasperDesign = cache.getJasperDesign(target.getUri());
        JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getMainDataset();

        List<JRSortField> existingFields =  dataset.getSortFieldsList();
        String sortField = null;

        if (existingFields != null && existingFields.size() > 0) {
            for (JRSortField field: existingFields) {
                if (field.getName().equals(sortColumnName) && field.getType().getName().equals(sortColumnType)) {
                    sortField = sortColumnName + SortElement.SORT_COLUMN_TOKEN_SEPARATOR + sortColumnType + SortElement.SORT_COLUMN_TOKEN_SEPARATOR;
                    switch (field.getOrderValue()) {
                        case ASCENDING:
                            sortField += SortElement.SORT_ORDER_ASC;
                            break;
                        case DESCENDING:
                            sortField += SortElement.SORT_ORDER_DESC;
                            break;
                    }
                    break;
                }
            }
        }

        return sortField;
    }

    return null;
}
项目:jasperreports    文件:SortElementHtmlHandler.java   
private List<FieldFilter> getExistingFiltersForField(
    JasperReportsContext jasperReportsContext, 
    ReportContext reportContext, 
    String uuid, 
    String filterFieldName
    ) 
{
    JasperDesignCache cache = JasperDesignCache.getInstance(jasperReportsContext, reportContext);
    FilterAction action = new FilterAction();
    action.init(jasperReportsContext, reportContext);
    CommandTarget target = action.getCommandTarget(UUID.fromString(uuid));
    List<FieldFilter> result = new ArrayList<FieldFilter>();
    if (target != null)
    {
        JasperDesign jasperDesign = cache.getJasperDesign(target.getUri());
        JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getMainDataset();

        // get existing filter as JSON string
        String serializedFilters = "[]";
        JRPropertiesMap propertiesMap = dataset.getPropertiesMap();
        if (propertiesMap.getProperty(FilterCommand.DATASET_FILTER_PROPERTY) != null) {
            serializedFilters = propertiesMap.getProperty(FilterCommand.DATASET_FILTER_PROPERTY);
        }

        List<? extends DatasetFilter> existingFilters = JacksonUtil.getInstance(jasperReportsContext).loadList(serializedFilters, FieldFilter.class);
        if (existingFilters.size() > 0) {
            for (DatasetFilter filter: existingFilters) {
                if (((FieldFilter)filter).getField().equals(filterFieldName)) {
                    result.add((FieldFilter)filter);
                    break;
                }
            }
        }
    }

    return result;
}
项目:jasperreports    文件:TableCompiler.java   
protected void verifyGroupCells(TableComponent table, List<GroupCell> cells, int width, 
        String cellName, JRVerifier verifier)
{
    if (cells != null)
    {
        Set<String> groupNames = new HashSet<String>();
        for (GroupCell groupCell : cells)
        {
            String groupName = groupCell.getGroupName();
            if (groupName == null)
            {
                verifier.addBrokenRule("No group name set for table column group cell", groupCell);
            }
            else
            {
                if (!groupNames.add(groupName))
                {
                    verifier.addBrokenRule("Duplicate " + cellName + " for group \"" + groupName + "\"", 
                            groupCell);
                }

                JRDatasetRun datasetRun = table.getDatasetRun();
                if (datasetRun != null)
                {
                    JRDesignDataset dataset = (JRDesignDataset) verifier.getReportDesign().getDatasetMap().get(
                            datasetRun.getDatasetName());
                    if (dataset != null && dataset.getGroupsMap().get(groupName) == null)
                    {
                        verifier.addBrokenRule("No group named \"" + groupName 
                                + "\" found in subdataset " + datasetRun.getDatasetName(), 
                                groupCell);
                    }
                }
            }

            verifyCell(groupCell.getCell(), width, cellName, verifier);
        }
    }
}
项目:PDFReporter-Studio    文件:ExpressionContextUtils.java   
/**
 * Returns the list of parameters that are related to the specified dataset.
 * The list is populated only if the dataset is itself used in the input expression context.
 * 
 * @param exprContext the expression context to look into
 * @param ds the dataset
 * @return the list of parameters
 */
public static List<JRParameter> getDatasetParameters(ExpressionContext exprContext, JRDesignDataset ds) {
    List<JRParameter> parameters = new ArrayList<JRParameter>();
    for(JRDesignDataset d : exprContext.getDatasets()){
        if(d == ds) {
            parameters.addAll(d.getParametersList());
            break;
        }
    }
    return parameters;
}
项目:PDFReporter-Studio    文件:XLSDataAdapterComposite.java   
/**
 * This method will populate the data model with the Excel columns This also
 * checks the button "Skip the first line " and enables the delete button
 * 
 * @throws Exception
 */
private void getExcelColumns() throws Exception {

    if (textFileName.getText().length() > 0) {
        DataAdapterDescriptor da = getDataAdapter();
        if (jConfig == null)
            jConfig = JasperReportsConfiguration.getDefaultJRConfig();
        DataAdapterService das = DataAdapterServiceUtil.getInstance(jConfig).getService(da.getDataAdapter());
         ((AbstractDataAdapterService) das).getDataAdapter();
        jConfig.setJasperDesign(new JasperDesign());

        //The get fields method call once a next on the data adapter to get the first line and from that is read the
        //fields name. But is useFirstRowAsHeader flag is set to false than the next call will skip the first line
        //that is the only one read to get the fields, so it will return an empty set of column names. For this 
        //reason this flag must be force to true if the data adapter is used to get the column names
        XlsDataAdapter xlsAdapter = (XlsDataAdapter)da.getDataAdapter();
        boolean useRowHeader = xlsAdapter.isUseFirstRowAsHeader();
        xlsAdapter.setUseFirstRowAsHeader(true);
        List<JRDesignField> fields = ((IFieldsProvider) da).getFields(das, jConfig, new JRDesignDataset(jConfig, false));
        xlsAdapter.setUseFirstRowAsHeader(useRowHeader);

        rows.clear();
        int columnIndex = 0;
        for (JRDesignField f : fields) {
            rows.add(new String[] { f.getName(), String.valueOf(columnIndex++) });
        }
        tableViewer.setInput(rows);

        tableViewer.refresh();
        setTableSelection(-1);
        btnDelete.setEnabled(true);
    }
}
项目:PDFReporter-Studio    文件:CVItemDataDialog.java   
private ExpressionContext getExpressionContextFromDSRun() {
    if(dataset!=null){
        JRDesignDataset ds = ModelUtils.getDesignDatasetForDatasetRun(
                jconfig.getJasperDesign(), dataset.getDatasetRun());
        return new ExpressionContext(ds,jconfig);
    }
    return null;
}
项目:PDFReporter-Studio    文件:FieldNameValidator.java   
/**
 * The object must be the new name for the field, and using the target check if there are other fields
 * with the same name, under the same dataset
 */
@Override
public String isValid(Object value) {
    JRDesignDataset d = ModelUtils.getDataset(getTarget());
    if (d !=null ){
        JRField field = d.getFieldsMap().get(value);
        if (field != null && getTarget().getValue() != field){
            String message = MessageFormat.format(Messages.FieldNameValidator_fieldDuplicatedName, new Object[] { value });
            return message;
        }
    }
    return null;
}
项目:PDFReporter-Studio    文件:ElementDatasetDialog.java   
private ExpressionContext getExpressionContextFromDSRun() {
    if(dataset!=null){
        JRDesignDataset ds = ModelUtils.getDesignDatasetForDatasetRun(
                jConfig.getJasperDesign(), dataset.getDatasetRun());
        return new ExpressionContext(ds,jConfig);
    }
    return null;
}
项目:PDFReporter-Studio    文件:ElementItemDialog.java   
private void computeExpressionContext() {
    if(staticRBtn.getSelection()) {
        expContext = defaultExpressionContext;
    }
    else {
        String dsSelected = datasetCombo.getText();
        // update the expression context
        JRDesignDataset designDS = 
                ModelUtils.getDesignDatasetByName(jconfig.getJasperDesign(), elementDatasetsMap.get(dsSelected));
        expContext = new ExpressionContext(designDS,jconfig);
    }
}
项目:PDFReporter-Studio    文件:TableComponentFactory.java   
public ExpressionContext getElementExpressionContext(Object jrObject) {
    if (jrObject instanceof MTable && ((MTable) jrObject).getValue() instanceof JRDesignComponentElement) {
        MTable mtable = (MTable) jrObject;
        StandardTable table = (StandardTable) ((JRDesignComponentElement) mtable.getValue()).getComponent();
        JRDesignDataset designDS = ModelUtils.getDesignDatasetForDatasetRun(mtable.getJasperConfiguration().getJasperDesign(), table.getDatasetRun());
        return new ExpressionContext(designDS, mtable.getJasperConfiguration());
    }
    return null;
}
项目:PDFReporter-Studio    文件:VErrorPreview.java   
public static boolean openExpressionEditor(JasperReportsConfiguration jContext,
        JRExpressionCollector reportCollector, JRDesignDataset dataset, JRDesignExpression exp) {
    SelectionHelper.getActiveJRXMLEditor();

    JRExpressionCollector datasetCollector = reportCollector.getCollector(dataset);
    List<JRExpression> datasetExpressions = datasetCollector.getExpressions();
    for (JRExpression expr : datasetExpressions) {
        if (expr.getId() == exp.getId()) {
            if (!ExpressionEditorSupportUtil.isExpressionEditorDialogOpen()) {
                JRExpressionEditor wizard = new JRExpressionEditor();
                wizard.setExpressionContext(new ExpressionContext(dataset, jContext));
                wizard.setValue(exp);
                WizardDialog dialog = ExpressionEditorSupportUtil.getExpressionEditorWizardDialog(Display.getDefault()
                        .getActiveShell(), wizard);
                if (dialog.open() == Dialog.OK) {
                    JRExpression e = wizard.getValue();
                    IEditorPart activeJRXMLEditor = SelectionHelper.getActiveJRXMLEditor();
                    if (activeJRXMLEditor != null && activeJRXMLEditor instanceof JrxmlEditor) {
                        JrxmlEditor editor = (JrxmlEditor) activeJRXMLEditor;
                        CommandStack cs = (CommandStack) editor.getAdapter(CommandStack.class);
                        if (cs != null) {
                            cs.execute(new SetExpressionValueCommand((JRDesignExpression) expr, e.getText(), e.getValueClassName()));
                            jContext.getJasperDesign().getEventSupport()
                                    .firePropertyChange(JasperDesign.PROPERTY_NAME, true, false);
                        }
                    }
                }
            }
            return true;
        }
    }
    return false;
}
项目:PDFReporter-Studio    文件:OpenQueryHandler.java   
@Override
public void run() {
    APropertyNode reportRoot = HandlersUtil.getRootElement();
    if (reportRoot != null) {
        MDataset mdataset = (MDataset) reportRoot.getPropertyValue(JasperDesign.PROPERTY_MAIN_DATASET);
        MQuery mquery = (MQuery) mdataset.getPropertyValue(JRDesignDataset.PROPERTY_QUERY);
        PatternEditor wizard = new PatternEditor();
        wizard.setValue(mquery.getPropertyValue(JRDesignQuery.PROPERTY_TEXT).toString());
        new DatasetDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), mdataset, mquery.getJasperConfiguration(), getCommandStack()).open();
    } else
        MessageDialog.openWarning(UIUtils.getShell(), Messages.OpenQueryHandler_message_title, Messages.OpenQueryHandler_message_text);
}
项目:PDFReporter-Studio    文件:WizardDatasetPage.java   
/**
 * This method returns the final dataset selected by the user.
 * If the dataset is an exising one, it is taken from the
 * jasperdesign in the wizard configuration.
 * If the dataset is empty, this method returns null.
 * If the dataset is a new dataset, a temporary new dataset is returned. This last dataset
 * is actually created by the sub-wizard to create the dataset.
 * 
 * @return
 */
public JRDesignDataset getSelectedDataset()
{
        switch (getSelectedOption())
        {
            case NEW_DATASET:
            {
                // We ask for a dataset form the sub-wizard we just run...
                if (getSelectedNode() != null && getSelectedNode().getWizard() != null)
                {
                    DatasetWizard dw = (DatasetWizard)getSelectedNode().getWizard();
                    return dw.getDataset();
                }

                return null;
            }
            case EXISTING_DATASET:
            {
                if (isMainDataset()) return getJasperDesign().getMainDesignDataset();
                return (JRDesignDataset)getJasperDesign().getDatasetMap().get( getSelectedDatasetName() );
            }
            case NO_DATASET:
            default:
            {
                return null;
            }
        }
}
项目:PDFReporter-Studio    文件:DatasetSection.java   
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
    super.createControls(parent, tabbedPropertySheetPage);

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

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    nameWidget = createWidget4Property(parent, JRDesignDataset.PROPERTY_NAME);
    nameWidget.getControl().setLayoutData(gd);

    gd = new GridData();
    gd.horizontalSpan = 2;
    createWidget4Property(parent, JRDesignDataset.PROPERTY_WHEN_RESOURCE_MISSING_TYPE).getControl().setLayoutData(gd);

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    createWidget4Property(parent, JRDesignDataset.PROPERTY_FILTER_EXPRESSION).getControl().setLayoutData(gd);

    gd = new GridData(GridData.FILL_HORIZONTAL);
    createWidget4Property(parent, JRDesignDataset.PROPERTY_SCRIPTLET_CLASS).getControl().setLayoutData(gd);

    gd = new GridData(GridData.FILL_HORIZONTAL);
    createWidget4Property(parent, JRDesignDataset.PROPERTY_RESOURCE_BUNDLE).getControl().setLayoutData(gd);

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = SWT.CENTER;
    createWidget4Property(parent, JRDesignDataset.PROPERTY_QUERY, false).getControl().setLayoutData(gd);
}