Search in sources :

Example 11 with Widget

use of org.eclipse.swt.widgets.Widget in project translationstudio8 by heartsome.

the class GridTableViewer method editElement.

/**
	 * {@inheritDoc}
	 */
public void editElement(Object element, int column) {
    try {
        getControl().setRedraw(false);
        Widget item = findItem(element);
        if (item != null) {
            ViewerRow row = getViewerRowFromItem(item);
            if (row != null) {
                ViewerCell cell = row.getCell(column);
                if (cell != null) {
                    triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
                }
            }
        }
    } finally {
        getControl().setRedraw(true);
    }
// }
}
Also used : Widget(org.eclipse.swt.widgets.Widget) ViewerRow(org.eclipse.jface.viewers.ViewerRow) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 12 with Widget

use of org.eclipse.swt.widgets.Widget in project translationstudio8 by heartsome.

the class XLFEditor method hookListener.

/**
	 * 初始化监听器。
	 */
private void hookListener() {
    // 添加文本修改监听器,用于调整文本框大小,使其高度自适应文本内容。
    textModifyListener = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            StyledText st = (StyledText) e.widget;
            GridData gd = (GridData) st.getLayoutData();
            if (gd == null) {
                gd = new GridData(GridData.FILL_BOTH);
            }
            Point computeSize = st.computeSize(st.getSize().x, SWT.DEFAULT, false);
            // 此行代码是为了保持列宽不变。减 10 是因为 computeSize 后宽度每次会增加 5 个像素,
            // 因此需要减去上次和本次增加的共10像素。为什么会这样原因不明。
            gd.widthHint = computeSize.x - 10;
            st.setLayoutData(gd);
            editorContentComposite.layout();
            oScrolledComposite.setMinSize(editorContentComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }
    };
    // 添加鼠标跟踪监听器,用于监听鼠标位置,根据编辑器模式切换光标样式。
    mouseTrackListener = new MouseTrackListener() {

        private void setArrowCursor(MouseEvent arg0) {
            Widget srcWidget = arg0.widget;
            if (isEditModel && srcWidget instanceof StyledText) {
                ((StyledText) srcWidget).setCursor(cursorIbeam);
            } else {
                ((StyledText) srcWidget).setCursor(cursorArrow);
            }
        }

        public void mouseEnter(MouseEvent arg0) {
            setArrowCursor(arg0);
        }

        public void mouseExit(MouseEvent arg0) {
            setArrowCursor(arg0);
        }

        public void mouseHover(MouseEvent arg0) {
            setArrowCursor(arg0);
        }
    };
    mouseListener = new MouseListener() {

        public void mouseDoubleClick(MouseEvent arg0) {
            // 切换为编辑模式
            isEditModel = true;
            System.out.println("It's running edit model.");
            Control ctrl = arg0.display.getCursorControl();
            ctrl.setCursor(cursorIbeam);
        }

        public void mouseDown(MouseEvent arg0) {
            int inx = (Integer) arg0.widget.getData(DATAKEY_INDEX);
            setSelectionRowColor(inx);
            // 选中模式下要隐藏光标。
            if (!isEditModel) {
                // 通过为容器组件设置焦点,实现在选中模式时隐藏文本框组件中闪烁的光标
                txtComposites[inx].forceFocus();
            }
        }

        public void mouseUp(MouseEvent arg0) {
        }
    };
    keyListener = new KeyListener() {

        public void keyPressed(KeyEvent arg0) {
            // 按 Esc 键切换到选择模式。
            if (arg0.keyCode == SWT.ESC) {
                isEditModel = false;
                Control ctrl = arg0.display.getCursorControl();
                ctrl.setCursor(cursorArrow);
            }
        }

        public void keyReleased(KeyEvent arg0) {
        }
    };
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseListener(org.eclipse.swt.events.MouseListener) ModifyListener(org.eclipse.swt.events.ModifyListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) GridData(org.eclipse.swt.layout.GridData) Widget(org.eclipse.swt.widgets.Widget) KeyListener(org.eclipse.swt.events.KeyListener) Point(org.eclipse.swt.graphics.Point)

Example 13 with Widget

use of org.eclipse.swt.widgets.Widget in project cubrid-manager by CUBRID.

the class DropDownAction method runWithEvent.

public void runWithEvent(Event event) {
    // FIXME remove commented code if don't need it anymore.
    //if (event.detail == SWT.ARROW) {
    Widget widget = event.widget;
    if (widget instanceof ToolItem) {
        ToolItem toolItem = (ToolItem) widget;
        Composite parent = toolItem.getParent();
        Rectangle rect = toolItem.getBounds();
        Point pt = new Point(rect.x, rect.y + rect.height);
        pt = parent.toDisplay(pt);
        Menu contextMenu = menuManager.createContextMenu(parent);
        contextMenu.setLocation(pt.x, pt.y);
        contextMenu.setVisible(true);
    }
//		} else {
//			run();
//		}
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Widget(org.eclipse.swt.widgets.Widget) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Menu(org.eclipse.swt.widgets.Menu) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 14 with Widget

use of org.eclipse.swt.widgets.Widget in project cubrid-manager by CUBRID.

the class ProxyAction method runWithEvent.

public void runWithEvent(Event event) {
    if (event.detail == SWT.ARROW) {
        Widget widget = event.widget;
        if (widget instanceof ToolItem) {
            ToolItem toolItem = (ToolItem) widget;
            Composite parent = toolItem.getParent();
            Rectangle rect = toolItem.getBounds();
            Point pt = new Point(rect.x, rect.y + rect.height);
            pt = parent.toDisplay(pt);
            MenuManager menuManager = new MenuManager();
            ActionManager.getInstance().setActionsMenu(menuManager);
            Menu contextMenu = menuManager.createContextMenu(parent);
            contextMenu.setLocation(pt.x, pt.y);
            contextMenu.setVisible(true);
        }
    } else {
        run();
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Widget(org.eclipse.swt.widgets.Widget) Rectangle(org.eclipse.swt.graphics.Rectangle) MenuManager(org.eclipse.jface.action.MenuManager) Point(org.eclipse.swt.graphics.Point) Menu(org.eclipse.swt.widgets.Menu) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 15 with Widget

use of org.eclipse.swt.widgets.Widget in project tesb-studio-se by Talend.

the class JavaCamelJobScriptsExportWSWizardPage method handleEvent.

@Override
public void handleEvent(Event e) {
    super.handleEvent(e);
    Widget source = e.widget;
    if (source instanceof Combo) {
        String destination = ((Combo) source).getText();
        if (getDialogSettings() != null) {
            IDialogSettings section = getDialogSettings().getSection(DESTINATION_FILE);
            if (section == null) {
                section = getDialogSettings().addNewSection(DESTINATION_FILE);
            }
            section.put(DESTINATION_FILE, destination);
        }
    }
}
Also used : IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) Widget(org.eclipse.swt.widgets.Widget) Combo(org.eclipse.swt.widgets.Combo)

Aggregations

Widget (org.eclipse.swt.widgets.Widget)15 Combo (org.eclipse.swt.widgets.Combo)5 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)3 Point (org.eclipse.swt.graphics.Point)3 GridData (org.eclipse.swt.layout.GridData)3 Composite (org.eclipse.swt.widgets.Composite)3 Menu (org.eclipse.swt.widgets.Menu)3 ToolItem (org.eclipse.swt.widgets.ToolItem)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Control (org.eclipse.swt.widgets.Control)2 Label (org.eclipse.swt.widgets.Label)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 MenuManager (org.eclipse.jface.action.MenuManager)1 ColumnViewerEditorActivationEvent (org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent)1