Search in sources :

Example 1 with DateDialog

use of org.talend.commons.ui.runtime.swt.tableviewer.celleditor.DateDialog in project tdi-studio-se by Talend.

the class PromptDialog method createParameterComposite.

/**
     * DOC qiang.zhang Comment method "createParameterComposite".
     * 
     * @param parent
     * @param parameter
     * @param label
     */
private void createParameterComposite(final Composite parent, final IContextParameter parameter, Label label) {
    final Composite child = new Composite(parent, SWT.NONE);
    final GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    child.setLayout(layout);
    child.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (DefaultCellEditorFactory.isList(parameter.getType())) {
        createListParameterArea(parameter, label, child);
        return;
    }
    final Text text = new Text(child, SWT.SINGLE | SWT.BORDER);
    text.setText(parameter.getValue());
    text.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            parameter.setValue(text.getText());
        }
    });
    //$NON-NLS-1$
    String stringTip = "";
    //$NON-NLS-1$
    String comment = "";
    if (parameter.getType().equalsIgnoreCase("String") && LanguageManager.getCurrentLanguage() == ECodeLanguage.PERL) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        stringTip = Messages.getString("PromptDialog.stringTip");
    }
    comment = parameter.getComment();
    if (!stringTip.equals("")) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        comment = comment + " " + stringTip;
    }
    label.setToolTipText(comment);
    text.setToolTipText(comment);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.minimumWidth = MINIMUM_WIDTH;
    text.setLayoutData(data);
    if (DefaultCellEditorFactory.isDate(parameter.getType())) {
        text.setEditable(false);
        final Button b = new Button(child, SWT.NONE);
        //$NON-NLS-1$
        b.setText("...");
        b.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                DateDialog d = new DateDialog(((Button) e.getSource()).getShell());
                int res = d.open();
                if (res == Dialog.OK) {
                    text.setText(DefaultCellEditorFactory.getAddQuoteString(d.getTalendDateString()));
                }
            }
        });
    } else if (DefaultCellEditorFactory.isFile(parameter.getType())) {
        text.setEditable(false);
        final Button b = new Button(child, SWT.NONE);
        //$NON-NLS-1$
        b.setText("...");
        b.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                FileDialog d = new FileDialog(((Button) e.getSource()).getShell());
                if (text.getText() != null) {
                    d.setFileName(PathUtils.getOSPath(DefaultCellEditorFactory.getRemoveQuoteString(text.getText())));
                }
                String open = d.open();
                if (open != null) {
                    text.setText(DefaultCellEditorFactory.getAddQuoteString(PathUtils.getPortablePath(open)));
                }
            }
        });
    } else if (DefaultCellEditorFactory.isDirectory(parameter.getType())) {
        text.setEditable(false);
        final Button b = new Button(child, SWT.NONE);
        //$NON-NLS-1$
        b.setText("...");
        b.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog d = new DirectoryDialog(((Button) e.getSource()).getShell());
                if (text.getText() != null) {
                    d.setFilterPath(PathUtils.getOSPath(DefaultCellEditorFactory.getRemoveQuoteString(text.getText())));
                }
                String open = d.open();
                if (open != null) {
                    open = PathUtils.getPortablePath(open);
                    //$NON-NLS-1$
                    open += "/";
                    text.setText(DefaultCellEditorFactory.getAddQuoteString(open));
                }
            }
        });
    } else if (DefaultCellEditorFactory.isPassword(parameter.getType())) {
        text.setEchoChar('*');
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DateDialog(org.talend.commons.ui.runtime.swt.tableviewer.celleditor.DateDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 2 with DateDialog

use of org.talend.commons.ui.runtime.swt.tableviewer.celleditor.DateDialog in project tdi-studio-se by Talend.

the class DateController method createCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
public Command createCommand(Button button) {
    DateDialog dateDial = new DateDialog(composite.getShell());
    int returnValue = dateDial.open();
    if (returnValue == DateDialog.OK) {
        String propertyName = (String) button.getData(PARAMETER_NAME);
        String date = dateDial.getTalendDateString();
        if (date != null && !date.equals(elem.getPropertyValue(propertyName))) {
            elem.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
            return new PropertyChangeCommand(elem, propertyName, TalendTextUtils.addQuotes(date));
        }
    }
    return null;
}
Also used : PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DateDialog(org.talend.commons.ui.runtime.swt.tableviewer.celleditor.DateDialog) Point(org.eclipse.swt.graphics.Point)

Aggregations

DateDialog (org.talend.commons.ui.runtime.swt.tableviewer.celleditor.DateDialog)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 DirectoryDialog (org.eclipse.swt.widgets.DirectoryDialog)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Text (org.eclipse.swt.widgets.Text)1 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)1