Search in sources :

Example 6 with ItemRecord

use of org.talend.dataprofiler.core.ui.imex.model.ItemRecord in project tdq-studio-se by Talend.

the class ExportWizard method performFinish.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
@Override
public boolean performFinish() {
    if (!exportPage.canFinish()) {
        return false;
    }
    final IExportWriter writer = exportPage.getWriter();
    final ItemRecord[] records = exportPage.getElements();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            // $NON-NLS-1$
            monitor.beginTask("Export Item", records.length);
            writer.write(records, monitor);
            monitor.done();
        }
    };
    try {
        ProgressUI.popProgressDialog(op);
    } catch (Exception e) {
        log.error(e, e);
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IExportWriter(org.talend.dataprofiler.core.ui.imex.model.IExportWriter) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 7 with ItemRecord

use of org.talend.dataprofiler.core.ui.imex.model.ItemRecord in project tdq-studio-se by Talend.

the class ExportWizardPage method createUtilityButtons.

/**
 * DOC bZhou Comment method "createUtilityButtons".
 *
 * @param treeComposite
 */
protected void createUtilityButtons(Composite treeComposite) {
    Composite utilityComposite = new Composite(treeComposite, SWT.NONE);
    utilityComposite.setLayout(new GridLayout());
    utilityComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    Composite btnsComposite = new Composite(utilityComposite, SWT.NONE);
    btnsComposite.setLayout(new GridLayout());
    GridData gd = new GridData();
    gd.verticalAlignment = SWT.BEGINNING;
    gd.horizontalIndent = 0;
    gd.horizontalSpan = 0;
    btnsComposite.setLayoutData(gd);
    selectAllBTN = new Button(btnsComposite, SWT.PUSH);
    selectAllBTN.setText(SELECT_ALL);
    selectAllBTN.setToolTipText(SELECT_ALL);
    deselectAllBTN = new Button(btnsComposite, SWT.PUSH);
    deselectAllBTN.setText(DESELECT_ALL);
    deselectAllBTN.setToolTipText(DESELECT_ALL);
    addRequireBTN = new Button(btnsComposite, SWT.PUSH);
    addRequireBTN.setText(INCLUDE_DEPENDANCY);
    addRequireBTN.setToolTipText(INCLUDE_DEPENDANCY);
    Composite infoComposite = new Composite(utilityComposite, SWT.NONE);
    infoComposite.setLayout(new GridLayout());
    gd = new GridData(GridData.FILL_BOTH);
    gd.verticalAlignment = SWT.BOTTOM;
    gd.horizontalIndent = 0;
    gd.horizontalSpan = 0;
    infoComposite.setLayoutData(gd);
    final Button showSelectBTN = new Button(infoComposite, SWT.CHECK);
    showSelectBTN.setText(SHOW_ONLY_SELECTED);
    showSelectBTN.setToolTipText(SHOW_ONLY_SELECTED);
    Button[] utilityBTNs = new Button[] { selectAllBTN, deselectAllBTN, addRequireBTN };
    for (Button btn : utilityBTNs) {
        gd = new GridData();
        gd.widthHint = 170;
        gd.verticalIndent = 0;
        gd.horizontalIndent = 0;
        btn.setLayoutData(gd);
    }
    selectAllBTN.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TreeItem[] topItems = repositoryTree.getTree().getItems();
            for (TreeItem treeItem : topItems) {
                repositoryTree.setSubtreeChecked(treeItem.getData(), true);
            }
            repositoryTree.refresh();
            updatePageStatus();
        }
    });
    deselectAllBTN.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TreeItem[] topItems = repositoryTree.getTree().getItems();
            for (TreeItem treeItem : topItems) {
                repositoryTree.setSubtreeChecked(treeItem.getData(), false);
            }
            repositoryTree.refresh();
            updatePageStatus();
        }
    });
    addRequireBTN.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (showSelectBTN.getSelection()) {
                filterUncheckedItems(false);
            }
            ItemRecord[] records = getElements();
            for (ItemRecord record : records) {
                for (File depFile : record.getDependencySet()) {
                    // ignore it(means not export it).
                    if (!DqFileUtils.isLocalProjectFile(depFile)) {
                        continue;
                    }
                    // TDQ-12245~
                    ItemRecord depRecord = ItemRecord.findRecord(depFile);
                    if (!repositoryTree.getChecked(depRecord)) {
                        repositoryTree.setChecked(depRecord, true);
                    }
                }
            }
            if (showSelectBTN.getSelection()) {
                filterUncheckedItems(true);
            }
            checkForErrors();
        }
    });
    showSelectBTN.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            filterUncheckedItems(showSelectBTN.getSelection());
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 8 with ItemRecord

use of org.talend.dataprofiler.core.ui.imex.model.ItemRecord in project tdq-studio-se by Talend.

the class ExportWizardPage method addSubRepToElements.

/**
 * add related subReport jrxml/jasper file to List.
 *
 * @param record
 * @param itemRecords
 */
private void addSubRepToElements(ItemRecord record, List<ItemRecord> itemRecords) {
    File file = record.getFile();
    if (record.getProperty() == null) {
        return;
    }
    String version = record.getProperty().getVersion();
    String nameWithoutVersion = file.getName().replaceAll(underlineStr + version, PluginConstant.EMPTY_STRING).replaceAll(PluginConstant.DOT_STRING + FactoriesUtil.JRXML, PluginConstant.EMPTY_STRING);
    IFile iFile = ResourceManager.getJRXMLFolder().getFile(subrepName);
    File subRepFolder = WorkspaceUtils.ifileToFile(iFile);
    if (subRepFolder == null || !subRepFolder.exists()) {
        return;
    }
    Map<String, List<String>> mainSubRepMap = ReportFileHelper.getMainSubRepMap();
    String fName;
    for (File f : subRepFolder.listFiles()) {
        fName = f.getName();
        if (fName.equalsIgnoreCase(file.getName())) {
            continue;
        }
        // add the same name jasper file when the sub-report jrxml is checked on UI.
        if (fName.equalsIgnoreCase(nameWithoutVersion + PluginConstant.DOT_STRING + PluginConstant.JASPER_STRING)) {
            ItemRecord itemRecord = new ItemRecord(f);
            itemRecords.add(itemRecord);
            continue;
        }
        // add sub-reports jrxml and jasper when the main-report is checked on UI.
        List<String> subLsFromMap = mainSubRepMap.get(nameWithoutVersion);
        if (subLsFromMap != null) {
            for (String name : subLsFromMap) {
                if (fName.startsWith(name)) {
                    ItemRecord itemRecord = new ItemRecord(f);
                    itemRecords.add(itemRecord);
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) List(java.util.List) ArrayList(java.util.ArrayList) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 9 with ItemRecord

use of org.talend.dataprofiler.core.ui.imex.model.ItemRecord in project tdq-studio-se by Talend.

the class ExportWizardPage method addListeners.

/**
 * DOC bZhou Comment method "addListeners".
 */
private void addListeners() {
    SelectionListener modeSwitchListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setDirState(isDirState());
            setArchState(!isDirState());
        }
    };
    dirBTN.addSelectionListener(modeSwitchListener);
    archBTN.addSelectionListener(modeSwitchListener);
    ModifyListener populateListener = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            updateBasePath();
        }
    };
    dirTxt.addModifyListener(populateListener);
    archTxt.addModifyListener(populateListener);
    browseDirBTN.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String result = openDirectoryDialog();
            if (result != null) {
                dirTxt.setText(result);
            }
        }

        private String openDirectoryDialog() {
            DirectoryDialog dialog = new DirectoryDialog(Display.getDefault().getActiveShell());
            if (dirTxt.getText() != null) {
                dialog.setFilterPath(dirTxt.getText());
            }
            return dialog.open();
        }
    });
    browseArchBTN.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String result = openFileDialog();
            if (result != null) {
                IPath path = new Path(result);
                if (StringUtils.isBlank(path.getFileExtension())) {
                    // $NON-NLS-1$
                    path = path.addFileExtension("zip");
                }
                archTxt.setText(path.toOSString());
            }
        }

        private String openFileDialog() {
            FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell());
            dialog.setFilterExtensions(FILE_EXPORT_MASK);
            if (archTxt.getText() != null) {
                dialog.setFileName(archTxt.getText());
            }
            return dialog.open();
        }
    });
    repositoryTree.getTree().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TreeItem item = (TreeItem) e.item;
            ItemRecord record = (ItemRecord) item.getData();
            if (record.getFile().isFile()) {
                // MOD qiongli TDQ-5368 only uncheck the client dependecy when uncheck an item,not supplier
                // dependency.
                boolean checked = item.getChecked();
                if (checked) {
                    for (File file : record.getDependencySet()) {
                        // ignore it(means not export it).
                        if (!DqFileUtils.isLocalProjectFile(file)) {
                            continue;
                        }
                        // TDQ-12245~
                        ItemRecord findRecord = ItemRecord.findRecord(file);
                        if (findRecord != null) {
                            repositoryTree.setChecked(findRecord, checked);
                        } else {
                            // $NON-NLS-1$
                            log.error("Can't find the file: " + file.getAbsolutePath());
                        }
                    }
                } else {
                    ModelElement element = record.getElement();
                    List<ModelElement> dependencyClients;
                    if (element != null) {
                        dependencyClients = EObjectHelper.getDependencyClients(element);
                    } else {
                        // for context,the dependency should include related Connection
                        Property property = record.getProperty();
                        dependencyClients = ImportAndExportUtils.getContextClientDepend(property.getId());
                    }
                    if (!dependencyClients.isEmpty()) {
                        ImportAndExportUtils.iterateUncheckClientDependency(dependencyClients, repositoryTree);
                    }
                }
            }
            repositoryTree.refresh();
            checkForErrors();
        }
    });
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ModifyListener(org.eclipse.swt.events.ModifyListener) IPath(org.eclipse.core.runtime.IPath) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) List(java.util.List) ArrayList(java.util.ArrayList) FileDialog(org.eclipse.swt.widgets.FileDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Property(org.talend.core.model.properties.Property) SelectionListener(org.eclipse.swt.events.SelectionListener) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 10 with ItemRecord

use of org.talend.dataprofiler.core.ui.imex.model.ItemRecord in project tdq-studio-se by Talend.

the class ImportAndExportUtils method getContextClientDepend.

/**
 * Find client dependencies by contextId. it might be Connection
 *
 * @param contextId
 * @return
 */
public static List<ModelElement> getContextClientDepend(String contextId) {
    List<ModelElement> modelElementLs = new ArrayList<ModelElement>();
    if (StringUtils.isEmpty(contextId)) {
        return modelElementLs;
    }
    for (ItemRecord record : ItemRecord.getAllItemRecords()) {
        Property property = record.getProperty();
        if (property == null) {
            continue;
        }
        Item item = property.getItem();
        if (item instanceof ConnectionItem) {
            Connection connection = ((ConnectionItem) item).getConnection();
            if (connection.isContextMode() && contextId.equals(connection.getContextId())) {
                modelElementLs.add(record.getElement());
            }
        }
    }
    return modelElementLs;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ArrayList(java.util.ArrayList) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) Connection(org.talend.core.model.metadata.builder.connection.Connection) Property(org.talend.core.model.properties.Property)

Aggregations

ItemRecord (org.talend.dataprofiler.core.ui.imex.model.ItemRecord)26 File (java.io.File)15 ArrayList (java.util.ArrayList)14 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)10 IFile (org.eclipse.core.resources.IFile)6 Path (org.eclipse.core.runtime.Path)6 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)5 List (java.util.List)4 Image (org.eclipse.swt.graphics.Image)4 TreeItem (org.eclipse.swt.widgets.TreeItem)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 IPath (org.eclipse.core.runtime.IPath)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Test (org.junit.Test)3 Property (org.talend.core.model.properties.Property)3 HashMap (java.util.HashMap)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2