Search in sources :

Example 1 with MobileSource

use of com.twinsoft.convertigo.eclipse.dnd.MobileSource in project convertigo by convertigo.

the class MobilePickerComposite method makeUI.

private void makeUI(Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    parent.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final MobilePickerContentProvider contentProvider = (MobilePickerContentProvider) checkboxTreeViewer.getContentProvider();
            if (contentProvider != null) {
                btnSequence.setSelection(false);
                btnDatabase.setSelection(false);
                btnAction.setSelection(false);
                btnShared.setSelection(false);
                btnIteration.setSelection(false);
                btnForm.setSelection(false);
                btnGlobal.setSelection(false);
                ToolItem button = (ToolItem) e.widget;
                button.setSelection(true);
                if (btnSequence.getSelection()) {
                    contentProvider.setFilterBy(Filter.Sequence);
                } else if (btnDatabase.getSelection()) {
                    contentProvider.setFilterBy(Filter.Database);
                } else if (btnAction.getSelection()) {
                    contentProvider.setFilterBy(Filter.Action);
                } else if (btnShared.getSelection()) {
                    contentProvider.setFilterBy(Filter.Shared);
                } else if (btnIteration.getSelection()) {
                    contentProvider.setFilterBy(Filter.Iteration);
                } else if (btnForm.getSelection()) {
                    contentProvider.setFilterBy(Filter.Form);
                } else if (btnGlobal.getSelection()) {
                    contentProvider.setFilterBy(Filter.Global);
                }
                modelTreeViewer.setInput(null);
                checkboxTreeViewer.getTree().removeAll();
                checkboxTreeViewer.refresh();
                initTreeSelection(checkboxTreeViewer, null);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    };
    SelectionListener c_listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean isCustom = b_custom.getSelection();
            boolean doSetCustomText = false;
            if (isParentDialog) {
                MobileSmartSource cs = MobileSmartSource.valueOf(currentSource);
                if (cs != null && cs.getModel() != null && cs.getModel().getCustom().isEmpty()) {
                    doSetCustomText = true;
                }
            } else {
                doSetCustomText = true;
            }
            if (doSetCustomText) {
                MobileSmartSource nmss = MobileSmartSource.valueOf(getSmartSourceString());
                if (nmss != null) {
                    if (isCustom && !t_custom.getEnabled()) {
                        t_custom.setText(nmss.getModel().computeValue());
                    }
                    if (!isCustom && t_custom.getEnabled()) {
                        t_custom.setText("");
                    }
                }
            }
            t_custom.setEnabled(isCustom);
            t_prefix.setEnabled(!isCustom);
            t_data.setEnabled(!isCustom);
            t_suffix.setEnabled(!isCustom);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    };
    headerComposite = new Composite(parent, SWT.NONE);
    headerComposite.setLayout(SwtUtils.newGridLayout(2, false, 0, 0, 0, 0));
    headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 1, 1));
    ToolBar toolbar = new ToolBar(headerComposite, SWT.NONE);
    int btnStyle = SWT.CHECK;
    Image image = null;
    btnSequence = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/core/images/sequence_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnSequence.setText("SQ");
    }
    btnSequence.setImage(image);
    btnSequence.setToolTipText("Show Sequence Sources");
    btnSequence.addSelectionListener(listener);
    btnSequence.setSelection(true);
    btnDatabase = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/connectors/images/fullsyncconnector_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnDatabase.setText("FS");
    }
    btnDatabase.setImage(image);
    btnDatabase.setToolTipText("Show FullSync Databases Sources");
    btnDatabase.addSelectionListener(listener);
    btnAction = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/mobile/components/images/uicustomaction_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnAction.setText("AC");
    }
    btnAction.setImage(image);
    btnAction.setToolTipText("Show Action Sources");
    btnAction.addSelectionListener(listener);
    btnShared = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/mobile/components/images/uisharedcomponent_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnShared.setText("SH");
    }
    btnShared.setImage(image);
    btnShared.setToolTipText("Show Shared component Sources");
    btnShared.addSelectionListener(listener);
    btnIteration = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/steps/images/iterator_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnIteration.setText("IT");
    }
    btnIteration.setImage(image);
    btnIteration.setToolTipText("Show Iterators on current page Sources");
    btnIteration.addSelectionListener(listener);
    btnForm = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/mobile/components/images/uiform_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnForm.setText("FM");
    }
    btnForm.setImage(image);
    btnForm.setToolTipText("Show Forms on current page Sources");
    btnForm.addSelectionListener(listener);
    btnGlobal = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/mobile/components/dynamic/images/setglobalaction_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnGlobal.setText("GS");
    }
    btnGlobal.setImage(image);
    btnGlobal.setToolTipText("Show Global Shared objects");
    btnGlobal.addSelectionListener(listener);
    message = new Label(headerComposite, SWT.NONE);
    message.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    SashForm treesSashForm = new SashForm(parent, SWT.NONE);
    treesSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    checkboxTreeViewer = new CheckboxTreeViewer(treesSashForm, SWT.BORDER | SWT.SINGLE);
    checkboxTreeViewer.setContentProvider(new MobilePickerContentProvider());
    checkboxTreeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            Object element = event.getElement();
            if (element instanceof TVObject) {
                if (btnIteration.getSelection() || btnForm.getSelection() || btnGlobal.getSelection()) {
                    checkboxTreeViewer.setChecked(element, !event.getChecked());
                    return;
                }
                TVObject tvoChecked = (TVObject) element;
                if (event.getChecked())
                    checkedList.add(tvoChecked);
                else
                    checkedList.remove(tvoChecked);
                updateGrayChecked();
                updateTexts();
            }
        }
    });
    checkboxTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object selected = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (selected instanceof TVObject && !selected.equals(lastSelected)) {
                TVObject tvoSelected = (TVObject) selected;
                lastSelected = selected;
                if (firstSelected == null) {
                    firstSelected = selected;
                }
                checkedList.clear();
                checkedList.add(tvoSelected);
                modelTreeViewer.setInput(null);
                updateModel(tvoSelected);
                updateGrayChecked();
                updateTexts();
            }
        }
    });
    modelTreeViewer = new TreeViewer(treesSashForm, SWT.BORDER);
    modelTreeViewer.setContentProvider(new MobilePickerContentProvider());
    modelTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object selected = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (selected instanceof TVObject) {
                updateTexts();
            }
        }
    });
    treesSashForm.setWeights(new int[] { 1, 1 });
    Composite sourceComposite = new Composite(parent, SWT.NONE);
    sourceComposite.setLayout(new GridLayout(2, false));
    sourceComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    if (isParentDialog) {
        l_source = new Label(sourceComposite, SWT.NONE);
        ((Label) l_source).setText(" SOURCE ");
    } else {
        l_source = new Button(sourceComposite, SWT.NONE);
        ((Button) l_source).setText(" SOURCE ");
        l_source.setToolTipText("Drag me on a Mobile UI component in the project tree to bind this source to an UI component property");
    }
    Composite dataComposite = new Composite(sourceComposite, SWT.NONE);
    dataComposite.setLayout(new GridLayout(2, false));
    dataComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label l_prefix = new Label(dataComposite, SWT.NONE);
    l_prefix.setText("Prefix");
    t_prefix = new Text(dataComposite, SWT.BORDER);
    t_prefix.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label l_data = new Label(dataComposite, SWT.NONE);
    l_data.setText("Data");
    t_data = new Text(dataComposite, SWT.BORDER | SWT.READ_ONLY);
    t_data.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label l_suffix = new Label(dataComposite, SWT.NONE);
    l_suffix.setText("Suffix");
    t_suffix = new Text(dataComposite, SWT.BORDER);
    t_suffix.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    b_custom = new Button(dataComposite, SWT.CHECK);
    b_custom.setText("Custom");
    b_custom.addSelectionListener(c_listener);
    t_custom = new Text(dataComposite, SWT.BORDER);
    t_custom.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    t_custom.setEnabled(false);
    // Add DND support
    boolean dragEnabled = !isParentDialog;
    if (dragEnabled) {
        Transfer[] dragTransfers = new Transfer[] { MobileSourceTransfer.getInstance() };
        int operations = DND.DROP_COPY | DND.DROP_MOVE;
        DragSourceAdapter dragAdapter = new DragSourceAdapter() {

            @Override
            public void dragStart(DragSourceEvent event) {
                try {
                    String jsonString = getSmartSourceString();
                    if (jsonString != null && !jsonString.isEmpty()) {
                        event.doit = true;
                        MobileSourceTransfer.getInstance().setMobileSource(new MobileSource(jsonString));
                    }
                } catch (Exception e) {
                    ConvertigoPlugin.logException(e, "Cannot drag");
                }
            }
        };
        DragSource source = null;
        source = new DragSource(modelTreeViewer.getTree(), operations);
        source.setTransfer(dragTransfers);
        source.addDragListener(dragAdapter);
        source = new DragSource(l_source, operations);
        source.setTransfer(dragTransfers);
        source.addDragListener(dragAdapter);
    }
}
Also used : TVObject(com.twinsoft.convertigo.eclipse.views.mobile.MobilePickerContentProvider.TVObject) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) DragSource(org.eclipse.swt.dnd.DragSource) MobileSource(com.twinsoft.convertigo.eclipse.dnd.MobileSource) PartInitException(org.eclipse.ui.PartInitException) JSONException(org.codehaus.jettison.json.JSONException) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) SashForm(org.eclipse.swt.custom.SashForm) MobileSmartSource(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) Transfer(org.eclipse.swt.dnd.Transfer) MobileSourceTransfer(com.twinsoft.convertigo.eclipse.dnd.MobileSourceTransfer) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) TVObject(com.twinsoft.convertigo.eclipse.views.mobile.MobilePickerContentProvider.TVObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) MobilePageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePageComponentTreeObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with MobileSource

use of com.twinsoft.convertigo.eclipse.dnd.MobileSource in project convertigo by convertigo.

the class NgxPickerComposite method makeUI.

private void makeUI(Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    parent.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final NgxPickerContentProvider contentProvider = (NgxPickerContentProvider) checkboxTreeViewer.getContentProvider();
            if (contentProvider != null) {
                btnSequence.setSelection(false);
                btnDatabase.setSelection(false);
                btnAction.setSelection(false);
                btnShared.setSelection(false);
                btnIteration.setSelection(false);
                btnForm.setSelection(false);
                btnGlobal.setSelection(false);
                ToolItem button = (ToolItem) e.widget;
                button.setSelection(true);
                if (btnSequence.getSelection()) {
                    contentProvider.setFilterBy(Filter.Sequence);
                } else if (btnDatabase.getSelection()) {
                    contentProvider.setFilterBy(Filter.Database);
                } else if (btnAction.getSelection()) {
                    contentProvider.setFilterBy(Filter.Action);
                } else if (btnShared.getSelection()) {
                    contentProvider.setFilterBy(Filter.Shared);
                } else if (btnIteration.getSelection()) {
                    contentProvider.setFilterBy(Filter.Iteration);
                } else if (btnForm.getSelection()) {
                    contentProvider.setFilterBy(Filter.Form);
                } else if (btnGlobal.getSelection()) {
                    contentProvider.setFilterBy(Filter.Global);
                }
                modelTreeViewer.setInput(null);
                checkboxTreeViewer.getTree().removeAll();
                checkboxTreeViewer.refresh();
                initTreeSelection(checkboxTreeViewer, null);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    };
    SelectionListener c_listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean isCustom = b_custom.getSelection();
            boolean doSetCustomText = false;
            if (isParentDialog) {
                MobileSmartSource cs = MobileSmartSource.valueOf(currentSource);
                if (cs != null && cs.getModel() != null && cs.getModel().getCustom().isEmpty()) {
                    doSetCustomText = true;
                }
            } else {
                doSetCustomText = true;
            }
            if (doSetCustomText) {
                MobileSmartSource nmss = MobileSmartSource.valueOf(getSmartSourceString());
                if (nmss != null) {
                    if (isCustom && !t_custom.getEnabled()) {
                        t_custom.setText(nmss.getModel().computeValue());
                    }
                    if (!isCustom && t_custom.getEnabled()) {
                        t_custom.setText("");
                    }
                }
            }
            t_custom.setEnabled(isCustom);
            t_prefix.setEnabled(!isCustom);
            t_data.setEnabled(!isCustom);
            t_suffix.setEnabled(!isCustom);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    };
    headerComposite = new Composite(parent, SWT.NONE);
    headerComposite.setLayout(SwtUtils.newGridLayout(2, false, 0, 0, 0, 0));
    headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 1, 1));
    ToolBar toolbar = new ToolBar(headerComposite, SWT.NONE);
    int btnStyle = SWT.CHECK;
    Image image = null;
    btnSequence = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/core/images/sequence_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnSequence.setText("SQ");
    }
    btnSequence.setImage(image);
    btnSequence.setToolTipText("Show Sequence Sources");
    btnSequence.addSelectionListener(listener);
    btnSequence.setSelection(true);
    btnDatabase = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/connectors/images/fullsyncconnector_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnDatabase.setText("FS");
    }
    btnDatabase.setImage(image);
    btnDatabase.setToolTipText("Show FullSync Databases Sources");
    btnDatabase.addSelectionListener(listener);
    btnAction = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/ngx/components/images/uicustomaction_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnAction.setText("AC");
    }
    btnAction.setImage(image);
    btnAction.setToolTipText("Show Action Sources");
    btnAction.addSelectionListener(listener);
    btnShared = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/ngx/components/images/uisharedcomponent_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnShared.setText("SH");
    }
    btnShared.setImage(image);
    btnShared.setToolTipText("Show Shared component Sources");
    btnShared.addSelectionListener(listener);
    btnIteration = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/steps/images/iterator_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnIteration.setText("IT");
    }
    btnIteration.setImage(image);
    btnIteration.setToolTipText("Show Iterators on current page Sources");
    btnIteration.addSelectionListener(listener);
    btnForm = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/ngx/components/images/uiform_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnForm.setText("FM");
    }
    btnForm.setImage(image);
    btnForm.setToolTipText("Show Forms on current page Sources");
    btnForm.addSelectionListener(listener);
    btnGlobal = new ToolItem(toolbar, btnStyle);
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath("/com/twinsoft/convertigo/beans/ngx/components/dynamic/images/setglobalaction_color_16x16.png", BeanInfo.ICON_COLOR_16x16);
    } catch (Exception e) {
        btnGlobal.setText("GS");
    }
    btnGlobal.setImage(image);
    btnGlobal.setToolTipText("Show Global Shared objects");
    btnGlobal.addSelectionListener(listener);
    message = new Label(headerComposite, SWT.NONE);
    message.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    SashForm treesSashForm = new SashForm(parent, SWT.NONE);
    treesSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    checkboxTreeViewer = new CheckboxTreeViewer(treesSashForm, SWT.BORDER | SWT.SINGLE);
    checkboxTreeViewer.setContentProvider(new NgxPickerContentProvider());
    checkboxTreeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            Object element = event.getElement();
            if (element instanceof TVObject) {
                if (btnIteration.getSelection() || btnForm.getSelection() || btnGlobal.getSelection()) {
                    checkboxTreeViewer.setChecked(element, !event.getChecked());
                    return;
                }
                TVObject tvoChecked = (TVObject) element;
                if (event.getChecked())
                    checkedList.add(tvoChecked);
                else
                    checkedList.remove(tvoChecked);
                updateGrayChecked();
                updateTexts();
            }
        }
    });
    checkboxTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object selected = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (selected instanceof TVObject && !selected.equals(lastSelected)) {
                TVObject tvoSelected = (TVObject) selected;
                lastSelected = selected;
                if (firstSelected == null) {
                    firstSelected = selected;
                }
                checkedList.clear();
                checkedList.add(tvoSelected);
                modelTreeViewer.setInput(null);
                updateModel(tvoSelected);
                updateGrayChecked();
                updateTexts();
            }
        }
    });
    modelTreeViewer = new TreeViewer(treesSashForm, SWT.BORDER);
    modelTreeViewer.setContentProvider(new NgxPickerContentProvider());
    modelTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object selected = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (selected instanceof TVObject) {
                updateTexts();
            }
        }
    });
    treesSashForm.setWeights(new int[] { 1, 1 });
    Composite sourceComposite = new Composite(parent, SWT.NONE);
    sourceComposite.setLayout(new GridLayout(2, false));
    sourceComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    if (isParentDialog) {
        l_source = new Label(sourceComposite, SWT.NONE);
        ((Label) l_source).setText(" SOURCE ");
    } else {
        l_source = new Button(sourceComposite, SWT.NONE);
        ((Button) l_source).setText(" SOURCE ");
        l_source.setToolTipText("Drag me on a Ngx UI component in the project tree to bind this source to an UI component property");
    }
    Composite dataComposite = new Composite(sourceComposite, SWT.NONE);
    dataComposite.setLayout(new GridLayout(2, false));
    dataComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label l_prefix = new Label(dataComposite, SWT.NONE);
    l_prefix.setText("Prefix");
    t_prefix = new Text(dataComposite, SWT.BORDER);
    t_prefix.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label l_data = new Label(dataComposite, SWT.NONE);
    l_data.setText("Data");
    t_data = new Text(dataComposite, SWT.BORDER | SWT.READ_ONLY);
    t_data.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label l_suffix = new Label(dataComposite, SWT.NONE);
    l_suffix.setText("Suffix");
    t_suffix = new Text(dataComposite, SWT.BORDER);
    t_suffix.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    b_custom = new Button(dataComposite, SWT.CHECK);
    b_custom.setText("Custom");
    b_custom.addSelectionListener(c_listener);
    t_custom = new Text(dataComposite, SWT.BORDER);
    t_custom.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    t_custom.setEnabled(false);
    // Add DND support
    boolean dragEnabled = !isParentDialog;
    if (dragEnabled) {
        Transfer[] dragTransfers = new Transfer[] { MobileSourceTransfer.getInstance() };
        int operations = DND.DROP_COPY | DND.DROP_MOVE;
        DragSourceAdapter dragAdapter = new DragSourceAdapter() {

            @Override
            public void dragStart(DragSourceEvent event) {
                try {
                    String jsonString = getSmartSourceString();
                    if (jsonString != null && !jsonString.isEmpty()) {
                        event.doit = true;
                        MobileSourceTransfer.getInstance().setMobileSource(new MobileSource(jsonString));
                    }
                } catch (Exception e) {
                    ConvertigoPlugin.logException(e, "Cannot drag");
                }
            }
        };
        DragSource source = null;
        source = new DragSource(modelTreeViewer.getTree(), operations);
        source.setTransfer(dragTransfers);
        source.addDragListener(dragAdapter);
        source = new DragSource(l_source, operations);
        source.setTransfer(dragTransfers);
        source.addDragListener(dragAdapter);
    }
}
Also used : TVObject(com.twinsoft.convertigo.eclipse.views.mobile.NgxPickerContentProvider.TVObject) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) DragSource(org.eclipse.swt.dnd.DragSource) MobileSource(com.twinsoft.convertigo.eclipse.dnd.MobileSource) PartInitException(org.eclipse.ui.PartInitException) JSONException(org.codehaus.jettison.json.JSONException) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) SashForm(org.eclipse.swt.custom.SashForm) MobileSmartSource(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSource) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) Transfer(org.eclipse.swt.dnd.Transfer) MobileSourceTransfer(com.twinsoft.convertigo.eclipse.dnd.MobileSourceTransfer) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) TVObject(com.twinsoft.convertigo.eclipse.views.mobile.NgxPickerContentProvider.TVObject) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 MobileObject (com.twinsoft.convertigo.beans.core.MobileObject)2 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)2 MobileSource (com.twinsoft.convertigo.eclipse.dnd.MobileSource)2 MobileSourceTransfer (com.twinsoft.convertigo.eclipse.dnd.MobileSourceTransfer)2 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)2 JSONException (org.codehaus.jettison.json.JSONException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)2 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)2 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 SashForm (org.eclipse.swt.custom.SashForm)2 DragSource (org.eclipse.swt.dnd.DragSource)2 DragSourceAdapter (org.eclipse.swt.dnd.DragSourceAdapter)2 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)2 Transfer (org.eclipse.swt.dnd.Transfer)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2