Search in sources :

Example 66 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method editTotalDigits.

// EditMaxLength
private void editTotalDigits() {
    XSDTotalDigitsFacet currentValue = std.getTotalDigitsFacet();
    // $NON-NLS-1$
    String stringValue = "0";
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle6, Messages.XSDEditFacetAction_DialogTitle6Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
    IInputValidator() {

        public String isValid(String newText) {
            int val;
            try {
                val = Integer.parseInt(newText);
            } catch (Exception e) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            if (val < 0) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            return null;
        }
    });
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    int intValue = Integer.parseInt(((InputDialog) dialog).getValue());
    if (intValue > 0) {
        XSDTotalDigitsFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDTotalDigitsFacet();
        // $NON-NLS-1$
        f.setLexicalValue("" + intValue);
        std.getFacetContents().add(f);
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 67 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method editMinLength.

// EditLength
private void editMinLength() {
    XSDMinLengthFacet currentValue = std.getMinLengthFacet();
    // $NON-NLS-1$
    String stringValue = "0";
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle4, Messages.XSDEditFacetAction_DialogTitle4Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
    IInputValidator() {

        public String isValid(String newText) {
            int val;
            try {
                val = Integer.parseInt(newText);
            } catch (Exception e) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            if (val < 0) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            return null;
        }
    });
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    int intValue = Integer.parseInt(((InputDialog) dialog).getValue());
    if (intValue > 0) {
        XSDMinLengthFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMinLengthFacet();
        // $NON-NLS-1$
        f.setLexicalValue("" + intValue);
        std.getFacetContents().add(f);
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 68 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method editMaxLength.

// EditMinLength
private void editMaxLength() {
    XSDMaxLengthFacet currentValue = std.getMaxLengthFacet();
    // $NON-NLS-1$
    String stringValue = "0";
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle5, Messages.XSDEditFacetAction_DialogTitle4Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
    IInputValidator() {

        public String isValid(String newText) {
            int val;
            try {
                val = Integer.parseInt(newText);
            } catch (Exception e) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            if (val < 0) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            return null;
        }
    });
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    int intValue = Integer.parseInt(((InputDialog) dialog).getValue());
    if (intValue > 0) {
        XSDMaxLengthFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMaxLengthFacet();
        // $NON-NLS-1$
        f.setLexicalValue("" + intValue);
        std.getFacetContents().add(f);
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 69 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method editMaxInclusive.

private void editMaxInclusive() {
    XSDMaxInclusiveFacet currentValue = std.getMaxInclusiveFacet();
    String stringValue = null;
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    boolean isDateType = true;
    dialog = getInputDialog4Date(Messages.XSDEditFacetAction_DialogTitle8, Messages.XSDEditFacetAction_DialogTitle8Tip, stringValue);
    if (dialog == null) {
        isDateType = false;
        dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle8, Messages.XSDEditFacetAction_DialogTitle8Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
        IInputValidator() {

            public String isValid(String newText) {
                if (newText.trim().isEmpty()) {
                    return null;
                }
                return isValidBoundaryNumber(std, newText);
            }
        });
    }
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    String input = ((InputDialog) dialog).getValue();
    if (!input.trim().isEmpty()) {
        XSDMaxInclusiveFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMaxInclusiveFacet();
        if (isDateType) {
            f.setLexicalValue(input.trim());
            std.getFacetContents().add(f);
        } else if (Double.parseDouble(input) >= 0) {
            // $NON-NLS-1$
            f.setLexicalValue("" + getValidBoundaryNumber(std, input));
            std.getFacetContents().add(f);
        }
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 70 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project archi by archimatetool.

the class SaveModelAsTemplateToCollectionWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    GridData gd;
    Label label;
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout());
    setControl(container);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(container, getHelpID());
    fDoStoreInCollectionButton = new Button(container, SWT.CHECK);
    fDoStoreInCollectionButton.setText(Messages.SaveModelAsTemplateToCollectionWizardPage_0);
    fDoStoreInCollectionButton.setSelection(true);
    fDoStoreInCollectionButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean enabled = fDoStoreInCollectionButton.getSelection();
            fCategoriesTableViewer.getControl().setEnabled(enabled);
            fNewGroupButton.setEnabled(enabled);
            // Select first group, or none
            if (enabled) {
                Object o = fCategoriesTableViewer.getElementAt(0);
                if (o != null) {
                    fCategoriesTableViewer.setSelection(new StructuredSelection(o));
                }
            } else {
                fCategoriesTableViewer.setSelection(new StructuredSelection());
            }
        }
    });
    label = new Label(container, SWT.NULL);
    label.setText(Messages.SaveModelAsTemplateToCollectionWizardPage_1);
    Composite fieldContainer = new Composite(container, SWT.NULL);
    fieldContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    fieldContainer.setLayout(layout);
    Composite tableComp = new Composite(fieldContainer, SWT.NULL);
    tableComp.setLayout(new TableColumnLayout());
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 120;
    tableComp.setLayoutData(gd);
    fCategoriesTableViewer = new TemplateGroupsTableViewer(tableComp, SWT.BORDER | SWT.MULTI);
    fCategoriesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            fSelectedTemplateGroup = (ITemplateGroup) ((IStructuredSelection) event.getSelection()).getFirstElement();
        }
    });
    fCategoriesTableViewer.setInput(fTemplateManager.getUserTemplateGroups());
    fNewGroupButton = new Button(fieldContainer, SWT.NULL);
    fNewGroupButton.setText(Messages.SaveModelAsTemplateToCollectionWizardPage_2);
    gd = new GridData(SWT.TOP, SWT.TOP, false, false);
    fNewGroupButton.setLayoutData(gd);
    fNewGroupButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IInputValidator validator = new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return "".equals(newText) ? "" : hasGroup(newText) ? Messages.SaveModelAsTemplateToCollectionWizardPage_3 : null;
                }

                boolean hasGroup(String name) {
                    for (ITemplateGroup group : fTemplateManager.getUserTemplateGroups()) {
                        if (name.equals(group.getName())) {
                            return true;
                        }
                    }
                    return false;
                }
            };
            InputDialog dialog = new InputDialog(getShell(), Messages.SaveModelAsTemplateToCollectionWizardPage_4, Messages.SaveModelAsTemplateToCollectionWizardPage_5, // $NON-NLS-1$
            "", validator);
            if (dialog.open() == Window.OK) {
                String name = dialog.getValue();
                if (StringUtils.isSetAfterTrim(name)) {
                    ITemplateGroup group = new TemplateGroup(name);
                    fTemplateManager.getUserTemplateGroups().add(group);
                    fCategoriesTableViewer.refresh();
                    fCategoriesTableViewer.setSelection(new StructuredSelection(group), true);
                }
            }
        }
    });
    setPageComplete(true);
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TemplateGroup(com.archimatetool.templates.model.TemplateGroup) ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)101 InputDialog (org.eclipse.jface.dialogs.InputDialog)88 Composite (org.eclipse.swt.widgets.Composite)20 IStatus (org.eclipse.core.runtime.IStatus)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 ArrayList (java.util.ArrayList)12 Button (org.eclipse.swt.widgets.Button)12 GridData (org.eclipse.swt.layout.GridData)11 GridLayout (org.eclipse.swt.layout.GridLayout)10 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)9 List (java.util.List)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 Label (org.eclipse.swt.widgets.Label)8 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Control (org.eclipse.swt.widgets.Control)7 Display (org.eclipse.swt.widgets.Display)7 IResource (org.eclipse.core.resources.IResource)6 CoreException (org.eclipse.core.runtime.CoreException)6 Window (org.eclipse.jface.window.Window)6 Event (org.eclipse.swt.widgets.Event)6