Search in sources :

Example 21 with ItemRecord

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

the class ImportWizardPage method textModified.

/**
 * DOC sgandon Comment method "dirTextModified".
 */
protected void textModified(String pathStr) {
    IPath path = new Path(pathStr);
    if (path.toFile().exists()) {
        ItemRecord input = writer.computeInput(path);
        migrate();
        repositoryTree.setInput(input);
        repositoryTree.expandAll();
        TreeItem[] topItems = repositoryTree.getTree().getItems();
        for (TreeItem treeItem : topItems) {
            repositoryTree.setSubtreeChecked(treeItem.getData(), true);
        }
        repositoryTree.refresh();
    } else {
        repositoryTree.setInput(null);
    }
    populateElement();
    checkforErrors();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) TreeItem(org.eclipse.swt.widgets.TreeItem) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord)

Example 22 with ItemRecord

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

the class ImportWizardPage 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) {
                archTxt.setText(result);
            }
        }

        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();
        }
    });
    overwriteBTN.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // MOD msjian 2012-2-29 TDQ-4701: fixed another issue, when the user checked the overwrite checkbox, do
            // not do migration
            populateElement();
            checkforErrors();
        // TDQ-4701 ~
        }
    });
    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()) {
                        ItemRecord findRecord = ItemRecord.findRecord(file);
                        if (findRecord != null) {
                            repositoryTree.setChecked(findRecord, checked);
                        }
                    }
                } else {
                    ModelElement element = record.getElement();
                    List<ModelElement> dependencyClients;
                    if (element != null) {
                        dependencyClients = EObjectHelper.getDependencyClients(element);
                        ImportAndExportUtils.iterateUncheckClientDependency(dependencyClients, repositoryTree);
                    } 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);
                    }
                }
            }
            populateElement();
            repositoryTree.refresh();
            checkforErrors();
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) 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) File(java.io.File) Property(org.talend.core.model.properties.Property) SelectionListener(org.eclipse.swt.events.SelectionListener) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 23 with ItemRecord

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

the class ImportWizardPage method getElements.

/**
 * DOC bZhou Comment method "getElements".
 *
 * @return
 */
public ItemRecord[] getElements() {
    List<ItemRecord> itemRecords = new ArrayList<ItemRecord>();
    Object[] checkedElements = repositoryTree.getCheckedElements();
    for (Object obj : checkedElements) {
        if (obj instanceof ItemRecord) {
            ItemRecord record = (ItemRecord) obj;
            // MOD qiongli 2012-4-20,add related subreport jrxml/jasper file to elements.
            File file = record.getFile();
            if (file.isFile()) {
                itemRecords.add(record);
                if (file.getName().endsWith(FactoriesUtil.JRXML)) {
                    addSubRepToElements(record, itemRecords);
                }
                // if it is Mean Indicator, import it's dependency Sum Indicator also
                // $NON-NLS-1$
                String meanIndicatorUuid = "_ccI48RF2Ed2PKb6nEJEvhw";
                ModelElement element = record.getElement();
                if (element != null && element instanceof IndicatorDefinition && meanIndicatorUuid.equals(ResourceHelper.getUUID(element))) {
                    File sumIndicatorFile = getSumIndicatorFile(element);
                    if (sumIndicatorFile != null) {
                        itemRecords.add(new ItemRecord(sumIndicatorFile, record.getRootFolderPath()));
                    }
                }
            }
        }
    }
    return itemRecords.toArray(new ItemRecord[itemRecords.size()]);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) ArrayList(java.util.ArrayList) File(java.io.File) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 24 with ItemRecord

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

the class ImportWizardPage 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);
    File parentFile = file.getParentFile().getParentFile();
    if (parentFile == null || !parentFile.exists()) {
        return;
    }
    File subRepFolder = new Path(parentFile.getPath() + IPath.SEPARATOR + subrepName).toFile();
    if (subRepFolder == null || !subRepFolder.exists()) {
        return;
    }
    Map<String, List<String>> mainSubRepMap = ReportFileHelper.getMainSubRepMap();
    String fName;
    for (File f : subRepFolder.listFiles()) {
        fName = f.getName();
        if (f.getName().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, record.getRootFolderPath());
            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, record.getRootFolderPath());
                    itemRecords.add(itemRecord);
                }
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File)

Example 25 with ItemRecord

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

the class FileTreeLabelProviderTest method testGetImageObjectCase1.

/**
 * Test method for {@link org.talend.dataprofiler.core.ui.imex.FileTreeLabelProvider#getImage(java.lang.Object)}.
 * case 1 :element is match rule
 */
@Test
public void testGetImageObjectCase1() {
    File file = ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path(createTDQMatchRuleItem.getMatchRule().eResource().getURI().toPlatformString(false))).getLocation().toFile();
    ItemRecord itemRecord = new ItemRecord(file);
    FileTreeLabelProvider fileTreeLabelProvider = new FileTreeLabelProvider();
    Image image = fileTreeLabelProvider.getImage(itemRecord);
    Assert.assertEquals(ImageLib.getImage(ImageLib.MATCH_RULE_ICON), image);
}
Also used : Path(org.eclipse.core.runtime.Path) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) Image(org.eclipse.swt.graphics.Image) File(java.io.File) Test(org.junit.Test)

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