Search in sources :

Example 66 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class AbstractJarSelectDialog method createButtons.

/**
 * Adds the selection and deselection buttons to the dialog.
 *
 * @param composite the parent composite
 * @return Composite the composite the buttons were created in.
 */
protected Composite createButtons(final Composite composite, final boolean isSelect) {
    Composite buttonComposite = new Composite(composite, SWT.RIGHT);
    buttonComposite.setBackground(composite.getBackground());
    GridLayout layout = new GridLayout();
    layout.numColumns = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    buttonComposite.setLayout(layout);
    buttonComposite.setFont(composite.getFont());
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
    data.grabExcessHorizontalSpace = true;
    buttonComposite.setLayoutData(data);
    Button selectButton = createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, WorkbenchMessages.CheckedTreeSelectionDialog_select_all, false);
    SelectionListener listener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Object[] viewerElements = fContentProvider.getElements(fInput);
            if (fContainerMode) {
                if (isSelect) {
                    fViewer.setCheckedElements(viewerElements);
                    // ADD msjian 2011-8-9 TDQ-3199 fixed: Make it convenient to delete the jar which is used
                    // already.
                    handleChecked();
                    handleClassNameFromJarFile();
                // ADD end
                } else {
                    fManageViewer.setCheckedElements(viewerElements);
                }
            } else {
                for (Object viewerElement : viewerElements) {
                    if (isSelect) {
                        fViewer.setSubtreeChecked(viewerElement, true);
                    } else {
                        fManageViewer.setSubtreeChecked(viewerElement, true);
                    }
                }
            }
            updateOKStatus();
        }
    };
    selectButton.addSelectionListener(listener);
    Button deselectButton = createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, WorkbenchMessages.CheckedTreeSelectionDialog_deselect_all, false);
    listener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (isSelect) {
                fViewer.setCheckedElements(new Object[0]);
                // ADD msjian 2011-8-9 TDQ-3199 fixed: Make it convenient to delete the jar which is used
                // already.
                handleChecked();
                handleClassNameFromJarFile();
            // ADD end
            } else {
                fManageViewer.setCheckedElements(new Object[0]);
            }
            updateOKStatus();
        }
    };
    deselectButton.addSelectionListener(listener);
    if (!isSelect) {
        final Composite dialogComposite = composite;
        // $NON-NLS-1$
        Button addButton = createButton(buttonComposite, 22, Messages.getString("AbstractJarSelectDialog.add"), false);
        SelectionListener listenerAdd = new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                FileDialog dialog = new FileDialog(dialogComposite.getShell(), SWT.NONE | SWT.MULTI);
                // $NON-NLS-1$
                dialog.setFilterExtensions(new String[] { "*.jar" });
                String path = dialog.open();
                if (path != null) {
                    String[] fileNames = dialog.getFileNames();
                    for (String name : fileNames) {
                        IPath filePath = new Path(path);
                        filePath = filePath.removeLastSegments(1).append(name);
                        // TDQ-7451 Replace File copy with eclipse IFile create.make svn could syn and control.
                        IFile targetFile = ResourceManager.getUDIJarFolder().getFile(filePath.lastSegment());
                        createIFileFromFile(filePath.toFile(), targetFile, getDescriptionMessage(name));
                    }
                }
                // MOD msjian 2011-7-14 22092 feature: Java UDI: not convinient to delete udi jar files
                fViewer.refresh();
                fManageViewer.refresh();
                fViewer.setInput(ResourceManager.getUDIJarFolder());
                fManageViewer.setInput(ResourceManager.getUDIJarFolder());
                fIsEmpty = evaluateIfTreeEmpty(fInput);
                // getTreeViewer().setCheckedElements(new Object[0]);
                updateOKStatus();
            }
        };
        addButton.addSelectionListener(listenerAdd);
        Button delButton = createButton(// $NON-NLS-1$
        buttonComposite, // $NON-NLS-1$
        23, // $NON-NLS-1$
        Messages.getString("AbstractJarSelectDialog.delete"), false);
        SelectionListener listenerDel = new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                for (Object delFile : fManageViewer.getCheckedElements()) {
                    // Object delFile = manageSelectList.get(i);
                    if (delFile instanceof File) {
                        // MOD msjian 2011-8-9 TDQ-3199 fixed: Make it convenient to delete the jar which is used
                        // already.
                        ReturnCode rc = checkJarDependency((File) delFile);
                        if (selectedJars.containsKey(delFile)) {
                            rc.setOk(false);
                            rc.setMessage(getFileHasBeenSelectedMessages(delFile));
                        }
                        // MOD end
                        if (rc.isOk()) {
                            boolean delete = ((File) delFile).delete();
                            if (!delete) {
                                MessageDialog.openWarning(getParentShell(), // $NON-NLS-1$
                                Messages.getString("AbstractJarSelectDialog.delete"), // $NON-NLS-1$
                                Messages.getString("AbstractJarSelectDialog.deleteFail"));
                            }
                        } else {
                            MessageDialog.openWarning(getParentShell(), Messages.getString("AbstractJarSelectDialog.warning"), // $NON-NLS-1$
                            rc.getMessage());
                        }
                    }
                    refreshWorkspace();
                }
                // MOD msjian 2011-7-14 22092 feature: Java UDI: not convinient to delete udi jar files
                fViewer.refresh();
                fManageViewer.refresh();
                fIsEmpty = evaluateIfTreeEmpty(fInput);
                updateOKStatus();
            }
        };
        delButton.addSelectionListener(listenerDel);
    } else {
        createOKButton(buttonComposite);
        Button cancelButton = createButton(buttonComposite, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
        SelectionListener listenerCancel = new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                cancelPressed();
            }
        };
        cancelButton.addSelectionListener(listenerCancel);
    // TDQ-3556 ~
    }
    return buttonComposite;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ReturnCode(org.talend.utils.sugars.ReturnCode) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 67 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class AddPatternISBN13Task method doExecute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.migration.AMigrationTask#doExecute()
     */
@Override
protected boolean doExecute() throws Exception {
    parameter = new PatternParameter();
    ReturnCode rc1 = new ReturnCode(true), rc2 = new ReturnCode(true), rc3 = new ReturnCode(true);
    // number folder
    // $NON-NLS-1$
    IFolder folder = ResourceManager.getPatternRegexFolder().getFolder("number");
    if (folder.exists()) {
        // only create ISBN 13 Checker when not found.
        if (!folder.getFile("ISBN_13_Checker_0.1.pattern").exists()) {
            Pattern pattern = newPattern(// $NON-NLS-1$ //$NON-NLS-2$
            "ISBN 13 Checker", // $NON-NLS-1$ //$NON-NLS-2$
            "Java", // $NON-NLS-1$
            "'^ISBN(?:-13)?:?\\ *(97(?:8|9)([ -]?)(?=[0-9]{1,5}\\2?[0-9]{1,7}\\2?[0-9]{1,6}\\2?[0-9])(?:[0-9]\\2*){9}[0-9])$'");
            if (pattern != null) {
                setTagValue(// $NON-NLS-1$
                pattern, // $NON-NLS-1$
                "ISBN-13: 978-2711791415 | ISBN 978-2711791415 |  ISBN: 978-2711791415", // $NON-NLS-1$
                "International Standard Book Number 13 digits");
                rc1 = ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
    }
    // Update IPv6 Address.pattern.
    // $NON-NLS-1$
    IFile file = ResourceManager.getPatternRegexFolder().getFolder("internet").getFile("IPv6_Address_0.1.pattern");
    if (file.exists()) {
        Pattern ipv6Pattern = PatternResourceFileHelper.getInstance().findPattern(file);
        if (ipv6Pattern != null) {
            List<PatternComponent> componentLs = new ArrayList<PatternComponent>();
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("Java", REGEX_BODY, ExpressionType.REGEXP));
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("MySQL", REGEX_BODY, ExpressionType.REGEXP));
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("PostgreSQL", REGEX_BODY, ExpressionType.REGEXP));
            ipv6Pattern.getComponents().clear();
            ipv6Pattern.getComponents().addAll(componentLs);
            rc2 = PatternResourceFileHelper.getInstance().save(ipv6Pattern);
        }
    }
    // Update EN Month.pattern. for expresstion add ()
    // $NON-NLS-1$ //$NON-NLS-2$
    IFile file2 = ResourceManager.getPatternRegexFolder().getFolder("date").getFile("EN_Month_0.1.pattern");
    if (file2.exists()) {
        Pattern enMonthPattern = PatternResourceFileHelper.getInstance().findPattern(file2);
        if (enMonthPattern != null) {
            List<PatternComponent> componentLs = new ArrayList<PatternComponent>();
            // $NON-NLS-1$
            String regexBody = "'^(January|June|July|February|March|May|April|August|September|October|November|December)$'";
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("SQL", regexBody, ExpressionType.REGEXP));
            enMonthPattern.getComponents().clear();
            enMonthPattern.getComponents().addAll(componentLs);
            rc3 = PatternResourceFileHelper.getInstance().save(enMonthPattern);
        }
    }
    return rc1.isOk() && rc2.isOk() && rc3.isOk();
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) ReturnCode(org.talend.utils.sugars.ReturnCode) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) PatternParameter(org.talend.dq.analysis.parameters.PatternParameter) IFolder(org.eclipse.core.resources.IFolder)

Example 68 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class DQRuleWriter method save.

@Override
public ReturnCode save(final Item item, final boolean careDependency) {
    ReturnCode rc = new ReturnCode();
    RepositoryWorkUnit<Object> repositoryWorkUnit = new // $NON-NLS-1$
    RepositoryWorkUnit<Object>(// $NON-NLS-1$
    "save DQRule item") {

        @Override
        protected void run() throws LoginException, PersistenceException {
            TDQBusinessRuleItem ruleItem = (TDQBusinessRuleItem) item;
            DQRule rule = ruleItem.getDqrule();
            // MOD yyi 2012-02-07 TDQ-4621:Update dependencies(connection) when careDependency is true.
            if (careDependency) {
                saveWithDependencies(ruleItem, rule);
            } else {
                saveWithoutDependencies(ruleItem, rule);
            }
        }
    };
    repositoryWorkUnit.setAvoidUnloadResources(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
    try {
        repositoryWorkUnit.throwPersistenceExceptionIfAny();
    } catch (PersistenceException e) {
        log.error(e, e);
        rc.setOk(Boolean.FALSE);
        rc.setMessage(e.getMessage());
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) DQRule(org.talend.dataquality.rules.DQRule)

Example 69 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class MatchRuleDefinitionWriter method save.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.writer.AElementPersistance#save(org.talend.core.model.properties.Item, boolean)
     */
@Override
public ReturnCode save(final Item item, final boolean careDependency) {
    ReturnCode rc = new ReturnCode();
    RepositoryWorkUnit<Object> repositoryWorkUnit = new // $NON-NLS-1$
    RepositoryWorkUnit<Object>(// $NON-NLS-1$
    "save MatchRule Definition item") {

        @Override
        protected void run() throws LoginException, PersistenceException {
            TDQMatchRuleItem matchRuleItem = (TDQMatchRuleItem) item;
            MatchRuleDefinition matchRuleDefinition = matchRuleItem.getMatchRule();
            if (careDependency) {
                saveWithDependencies(matchRuleItem, matchRuleDefinition);
            } else {
                saveWithoutDependencies(matchRuleItem, matchRuleDefinition);
            }
        }
    };
    repositoryWorkUnit.setAvoidUnloadResources(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
    try {
        repositoryWorkUnit.throwPersistenceExceptionIfAny();
    } catch (PersistenceException e) {
        log.error(e, e);
        rc.setOk(Boolean.FALSE);
        rc.setMessage(e.getMessage());
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition)

Example 70 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ReportWriter method removeDependencies.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.writer.AElementPersistance#removeDependencies(org.talend.core.model.properties.Item)
     */
@Override
protected ReturnCode removeDependencies(Item item) {
    ReturnCode rc = new ReturnCode();
    TDQReportItem anaItem = (TDQReportItem) item;
    TdReport report = (TdReport) anaItem.getReport();
    List<Property> clintDependency = DependenciesHandler.getInstance().getClintDependency(anaItem.getProperty());
    EList<AnalysisMap> analysisMap = report.getAnalysisMap();
    for (Property currentClient : clintDependency) {
        ModelElement modelElement = PropertyHelper.getModelElement(currentClient);
        if (!analysisMap.contains(modelElement)) {
            boolean isSuccess = DependenciesHandler.getInstance().removeDependenciesBetweenModel(report, modelElement);
            if (isSuccess) {
                rc.setOk(EMFUtil.saveSingleResource(modelElement.eResource()));
            } else {
                rc.setOk(false);
                rc.setMessage(// $NON-NLS-1$
                Messages.getString(// $NON-NLS-1$
                "ReportWriter.CanNotFindDependencyElement", // $NON-NLS-1$
                report.getName(), modelElement.getName()));
            }
        }
    }
    return rc;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) TdReport(org.talend.dataquality.reports.TdReport) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) Property(org.talend.core.model.properties.Property) TDQReportItem(org.talend.dataquality.properties.TDQReportItem)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10