Search in sources :

Example 6 with ScrolledComposite

use of org.eclipse.swt.custom.ScrolledComposite in project translationstudio8 by heartsome.

the class NewProjectWizardProjInfoPage method reload.

public void reload() {
    if (lstText != null) {
        lstText.clear();
    }
    if (lstCombo != null) {
        lstCombo.clear();
    }
    ArrayList<String> lstField = PreferenceUtil.getProjectFieldList();
    LinkedHashMap<String, ArrayList<String>> mapAttr = PreferenceUtil.getProjectAttributeMap();
    if ((lstField != null && lstField.size() > 0) || (mapAttr != null && mapAttr.size() > 0)) {
        if (groupField == null || groupField.isDisposed()) {
            groupField = new Group((Composite) getControl(), SWT.None);
            groupField.setLayout(new GridLayout());
            GridData fieldData = new GridData(GridData.FILL_BOTH);
            groupField.setLayoutData(fieldData);
            groupField.setText(Messages.getString("wizards.NewProjectWizardProjInfoPage.groupField"));
            cmpScrolled = new ScrolledComposite(groupField, SWT.V_SCROLL);
            cmpScrolled.setAlwaysShowScrollBars(false);
            cmpScrolled.setLayoutData(new GridData(GridData.FILL_BOTH));
            cmpScrolled.setExpandHorizontal(true);
            cmpScrolled.setExpandVertical(true);
            cmpField = new Composite(cmpScrolled, SWT.None);
            cmpField.setLayout(new GridLayout(2, false));
            cmpScrolled.setContent(cmpField);
            cmpScrolled.setMinSize(cmpField.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }
        if (cmpField != null && !cmpField.isDisposed()) {
            for (Control control : cmpField.getChildren()) {
                control.dispose();
            }
            cmpField.layout();
            cmpScrolled.layout();
            groupField.layout();
            groupField.getParent().layout();
            cmpScrolled.setMinSize(cmpField.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            if (lstField != null && lstField.size() > 0) {
                if (lstText == null) {
                    lstText = new ArrayList<Text>();
                }
                for (String strField : lstField) {
                    Label lbl = new Label(cmpField, SWT.WRAP);
                    String strLbl = strField.replaceAll("&", "&&") + Messages.getString("wizards.NewProjectWizardProjInfoPage.colon");
                    lbl.setText(strLbl);
                    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(lbl);
                    GridData gd = (GridData) lbl.getLayoutData();
                    Point p = lbl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    if (p.x >= 100) {
                        gd.widthHint = 100;
                    }
                    Text txt = new Text(cmpField, SWT.BORDER);
                    txt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                    txt.setData(strField);
                    txt.addListener(SWT.Modify, this);
                    lstText.add(txt);
                    cmpScrolled.setMinSize(cmpField.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                }
            }
            if (mapAttr != null && mapAttr.size() > 0) {
                Iterator<Entry<String, ArrayList<String>>> it = mapAttr.entrySet().iterator();
                if (lstCombo == null) {
                    lstCombo = new ArrayList<Combo>();
                }
                while (it.hasNext()) {
                    Entry<String, ArrayList<String>> entry = (Entry<String, ArrayList<String>>) it.next();
                    String attrName = entry.getKey();
                    ArrayList<String> lstAttrVal = entry.getValue();
                    lstAttrVal.add(0, "");
                    Label lbl = new Label(cmpField, SWT.WRAP);
                    String strLbl = attrName.replaceAll("&", "&&") + Messages.getString("wizards.NewProjectWizardProjInfoPage.colon");
                    lbl.setText(strLbl);
                    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(lbl);
                    GridData gd = (GridData) lbl.getLayoutData();
                    Point p = lbl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    if (p.x >= 100) {
                        gd.widthHint = 100;
                    }
                    Combo cmb = new Combo(cmpField, SWT.READ_ONLY);
                    cmb.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                    cmb.setItems(lstAttrVal.toArray(new String[lstAttrVal.size()]));
                    cmb.select(0);
                    cmb.setData(attrName);
                    lstCombo.add(cmb);
                    cmpScrolled.setMinSize(cmpField.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                }
            }
            cmpScrolled.setMinSize(cmpField.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            cmpField.layout();
            cmpScrolled.layout();
            groupField.layout();
            groupField.getParent().layout();
        }
    } else if (groupField != null && !groupField.isDisposed()) {
        Composite cmpParent = groupField.getParent();
        groupField.dispose();
        cmpParent.layout();
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Entry(java.util.Map.Entry) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Example 7 with ScrolledComposite

use of org.eclipse.swt.custom.ScrolledComposite in project yyl_example by Relucent.

the class ScrolledComposite_TEST method main.

public static void main(String[] args) {
    Display display = new Display();
    Color red = display.getSystemColor(SWT.COLOR_RED);
    Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    // set the size of the scrolled content - method 1
    final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    final Composite c1 = new Composite(sc1, SWT.NONE);
    sc1.setContent(c1);
    c1.setBackground(red);
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    c1.setLayout(layout);
    Button b1 = new Button(c1, SWT.PUSH);
    b1.setText("first button");
    c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    // set the minimum width and height of the scrolled content - method 2
    final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    sc2.setExpandHorizontal(true);
    sc2.setExpandVertical(true);
    final Composite c2 = new Composite(sc2, SWT.NONE);
    sc2.setContent(c2);
    c2.setBackground(blue);
    layout = new GridLayout();
    layout.numColumns = 4;
    c2.setLayout(layout);
    Button b2 = new Button(c2, SWT.PUSH);
    b2.setText("first button");
    sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    Button add = new Button(shell, SWT.PUSH);
    add.setText("add children");
    final int[] index = new int[] { 0 };
    add.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            index[0]++;
            Button button = new Button(c1, SWT.PUSH);
            button.setText("button " + index[0]);
            // reset size of content so children can be seen - method 1
            c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            c1.layout();
            button = new Button(c2, SWT.PUSH);
            button.setText("button " + index[0]);
            // reset the minimum width and height so children can be seen - method 2
            sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            c2.layout();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Button(org.eclipse.swt.widgets.Button) Color(org.eclipse.swt.graphics.Color) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Event(org.eclipse.swt.widgets.Event) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display)

Example 8 with ScrolledComposite

use of org.eclipse.swt.custom.ScrolledComposite in project tdi-studio-se by Talend.

the class DefaultDropTargetListener method autoScroll.

private void autoScroll(DropTargetEvent event) {
    Composite currentComposite = null;
    Object source = event.getSource();
    if (source instanceof DropTarget) {
        Control control = ((DropTarget) source).getControl();
        if (control instanceof Composite) {
            currentComposite = (Composite) control;
        }
    }
    if (currentComposite == null) {
        return;
    }
    ScrolledComposite parentScrolledComposite = getParentScrolledComposite(currentComposite);
    if (parentScrolledComposite == null) {
        return;
    }
    ScrollBar vBar = parentScrolledComposite.getVerticalBar();
    Control content = parentScrolledComposite.getContent();
    if (content != null) {
        Point location = content.getLocation();
        int vSelection = vBar.getSelection();
        int increment = 0;
        int thumb = vBar.getThumb();
        if (lastCursorPosition == null || lastCursorPosition.y == event.y) {
            long currentTimeMillis = System.currentTimeMillis();
            long time = currentTimeMillis - lastDragTime;
            if (lastDragTime != 0 && time > 100) {
                Point pointToScrollComposite = parentScrolledComposite.toControl(event.x, event.y);
                // scroll up
                if (pointToScrollComposite.y < 40) {
                    increment = -20;
                } else // scroll down
                if (thumb - pointToScrollComposite.y < 40) {
                    increment = 20;
                } else {
                    return;
                }
            } else {
                return;
            }
        } else {
            increment = event.y - lastCursorPosition.y;
            if (increment > 0) {
                increment = increment + 3;
            } else {
                increment = increment - 3;
            }
        }
        if (vSelection >= 0 && vSelection + increment > 0 && vSelection + increment < vBar.getMaximum()) {
            vBar.setSelection(vSelection + increment);
        }
        content.setLocation(location.x, -vSelection);
        mapperManager.getUiManager().refreshBackground(true, false);
        lastDragTime = System.currentTimeMillis();
    }
// Event e = new Event();
// e.data = event.data;
// e.x = event.x;
// e.y = event.y;
// e.detail = event.detail;
// e.item = event.item;
// e.count = event.y > lastCursorPosition.y ? 1 : 0;
// e.display = event.display;
// e.widget = event.widget;
// if (parentScrolledComposite != null) {
// parentScrolledComposite.notifyListeners(SWT.MouseWheel, e);
// }
}
Also used : Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) DropTarget(org.eclipse.swt.dnd.DropTarget) Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Point(org.eclipse.swt.graphics.Point)

Example 9 with ScrolledComposite

use of org.eclipse.swt.custom.ScrolledComposite in project tdi-studio-se by Talend.

the class MapperUI method createVarsZoneWithTables.

private void createVarsZoneWithTables(MapperModel mapperModel, final Display display) {
    Control previousControl;
    // Feature TDI-26691 : Add search option
    SearchZone searchZone = new SearchZone(datasFlowViewSashForm, SWT.NONE, mapperManager);
    searchZone.createSearchZone();
    sc2 = new ScrolledComposite(searchZone, getBorder() | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData sc2GridData = new GridData(GridData.FILL_BOTH);
    sc2.setLayoutData(sc2GridData);
    varsTableZoneView = new VarsTableZoneView(sc2, getBorder(), mapperManager);
    sc2.setContent(varsTableZoneView);
    sc2.setBackgroundMode(SWT.INHERIT_DEFAULT);
    sc2.setExpandHorizontal(true);
    sc2.addControlListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        // System.out.println("sc2 controlMoved");
        }

        public void controlResized(ControlEvent e) {
            // System.out.println("sc2 controlResized");
            onSashResized(display);
        }
    });
    sc2MSListener = new MouseScrolledListener(mapperManager.getUiManager(), sc2);
    varsTableZoneView.initInsertionIndicator();
    // final Composite finalTablesZoneViewVars = tablesZoneViewVars;
    previousControl = null;
    for (VarsTable varsTable : mapperModel.getVarsDataMapTables()) {
        DataMapTableView dataMapTableView = new VarsDataMapTableView(varsTableZoneView, SWT.BORDER, varsTable, mapperManager);
        FormData formData = new FormData();
        formData.left = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.top = new FormAttachment(previousControl);
        dataMapTableView.setLayoutData(formData);
        previousControl = dataMapTableView;
        dataMapTableView.minimizeTable(varsTable.isMinimized());
        dataMapTableView.registerStyledExpressionEditor(getTabFolderEditors().getStyledTextHandler());
    // dataMapTableView.fillMinimumSize(false);
    }
    varsTableZoneView.setSize(varsTableZoneView.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc2MSListener.addMouseWheelListener(sc2);
}
Also used : FormData(org.eclipse.swt.layout.FormData) VarsTable(org.talend.designer.mapper.model.table.VarsTable) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView) InputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) MouseScrolledListener(org.talend.designer.abstractmap.ui.listener.MouseScrolledListener) SearchZone(org.talend.designer.mapper.ui.visualmap.zone.SearchZone) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) VarsTableZoneView(org.talend.designer.mapper.ui.visualmap.zone.scrollable.VarsTableZoneView)

Example 10 with ScrolledComposite

use of org.eclipse.swt.custom.ScrolledComposite in project tdi-studio-se by Talend.

the class MapperUI method createOutputZoneWithTables.

private void createOutputZoneWithTables(MapperModel mapperModel, final UIManager uiManager, final Display display) {
    Control previousControl;
    outputsZone = new OutputsZone(datasFlowViewSashForm, SWT.NONE, mapperManager);
    outputsZone.createHeaderZoneComponents();
    // this.dropTargetOperationListener.addControl(outputsZone);
    sc3 = new ScrolledComposite(outputsZone, getBorder() | SWT.H_SCROLL | SWT.V_SCROLL);
    // this.dropTargetOperationListener.addControl(sc3);
    GridData sc3GridData = new GridData(GridData.FILL_BOTH);
    sc3.setLayoutData(sc3GridData);
    sc3.setBackgroundMode(SWT.INHERIT_DEFAULT);
    sc3.addControlListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        // System.out.println("sc3 controlMoved");
        }

        public void controlResized(ControlEvent e) {
            // System.out.println("sc3 controlResized");
            onSashResized(display);
        }
    });
    outputTablesZoneView = new OutputTablesZoneView(sc3, getBorder(), mapperManager);
    // this.dropTargetOperationListener.addControl(outputTablesZoneView);
    outputTablesZoneView.setBackgroundMode(SWT.INHERIT_DEFAULT);
    sc3.setExpandHorizontal(true);
    sc3.setContent(outputTablesZoneView);
    outputTablesZoneView.initInsertionIndicator();
    previousControl = null;
    List<OutputTable> tables = mapperModel.getOutputDataMapTables();
    Boolean minimizeStateOfTables = getMinimizedButtonState(tables);
    if (minimizeStateOfTables != null) {
        outputsZone.getToolbar().setMinimizeButtonState(minimizeStateOfTables.booleanValue());
    }
    sc3MSListener = new MouseScrolledListener(mapperManager.getUiManager(), sc3);
    for (OutputTable outputTable : tables) {
        OutputDataMapTableView dataMapTableView = uiManager.createNewOutputTableView(previousControl, outputTable, outputTablesZoneView);
        previousControl = dataMapTableView;
    }
    outputTablesZoneView.setSize(outputTablesZoneView.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
Also used : Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlListener(org.eclipse.swt.events.ControlListener) OutputsZone(org.talend.designer.mapper.ui.visualmap.zone.OutputsZone) OutputTablesZoneView(org.talend.designer.mapper.ui.visualmap.zone.scrollable.OutputTablesZoneView) ControlEvent(org.eclipse.swt.events.ControlEvent) MouseScrolledListener(org.talend.designer.abstractmap.ui.listener.MouseScrolledListener) OutputTable(org.talend.designer.mapper.model.table.OutputTable) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView)

Aggregations

ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)61 GridData (org.eclipse.swt.layout.GridData)45 Composite (org.eclipse.swt.widgets.Composite)44 GridLayout (org.eclipse.swt.layout.GridLayout)40 Label (org.eclipse.swt.widgets.Label)27 FillLayout (org.eclipse.swt.layout.FillLayout)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 Point (org.eclipse.swt.graphics.Point)12 Button (org.eclipse.swt.widgets.Button)12 Text (org.eclipse.swt.widgets.Text)12 Control (org.eclipse.swt.widgets.Control)10 ControlEvent (org.eclipse.swt.events.ControlEvent)9 Group (org.eclipse.swt.widgets.Group)9 HistoryComposite (com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 ArrayList (java.util.ArrayList)5 ControlListener (org.eclipse.swt.events.ControlListener)5 FormAttachment (org.eclipse.swt.layout.FormAttachment)5 FormData (org.eclipse.swt.layout.FormData)5