Search in sources :

Example 21 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class TermDbManagerDialog method createHelpControl.

/**
	 * 添加帮助按钮 robert 2012-09-06
	 */
@Override
protected Control createHelpControl(Composite parent) {
    // ROBERTHELP 术语库管理
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch06s04.html#tb-management", language);
    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
        }
    });
    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
    helpItem.setImage(helpImage);
    //$NON-NLS-1$
    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
    helpItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
        }
    });
    return toolBar;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 22 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class ImportTbxHandler method execute.

/**
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    TermDbManagerImportWizard wizard = new TermDbManagerImportWizard();
    TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(window.getShell(), wizard) {

        // robert help 2012-09-06
        @Override
        protected Control createHelpControl(Composite parent) {
            // ROBERTHELP 导入TBX
            String language = CommonFunction.getSystemLanguage();
            final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s03.html#create-tb-wizard-import-tbx", language);
            Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
            ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
            ((GridLayout) parent.getLayout()).numColumns++;
            toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
            final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
            toolBar.setCursor(cursor);
            toolBar.addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    cursor.dispose();
                }
            });
            ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
            helpItem.setImage(helpImage);
            //$NON-NLS-1$
            helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
            helpItem.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                }
            });
            return toolBar;
        }
    };
    dlg.setHelpAvailable(true);
    dlg.open();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DisposeListener(org.eclipse.swt.events.DisposeListener) TermDbManagerImportWizardDialog(net.heartsome.cat.database.ui.tb.wizard.TermDbManagerImportWizardDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TermDbManagerImportWizard(net.heartsome.cat.database.ui.tb.wizard.TermDbManagerImportWizard) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 23 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class TableHierarchicalExample method initDND.

/**
     * Init a simple drag and drop operation for moving rows in the table.
     * 
     * @param table
     * @param parent
     */
private void initDND(final JaretTable table, Composite parent) {
    // support move only
    int operations = DND.DROP_MOVE;
    final DragSource source = new DragSource(table, operations);
    // Provide data in Text format
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    source.setTransfer(types);
    source.addDragListener(new DragSourceListener() {

        public void dragStart(DragSourceEvent event) {
            // check whether drag occured on the hierarchy column
            IColumn column = table.colForX(event.x);
            if (column != null && table.isHierarchyColumn(column)) {
                // TODO check whether a resize may have
                // higher priority
                // possible row drag
                IRow row = table.rowForY(event.y);
                if (row != null) {
                    // row hit, start row drag
                    _draggedRow = row;
                    // capture the data for internal use
                    // row drag: use row at starting position
                    _parentTableNode = getParent(table.getHierarchicalModel().getRootNode(), (ITableNode) row);
                } else {
                    event.doit = false;
                }
            }
        }

        public void dragSetData(DragSourceEvent event) {
            // Provide the data of the requested type.
            if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
                if (_draggedRow != null) {
                    event.data = "row: " + _draggedRow.getId();
                }
            }
        }

        public void dragFinished(DragSourceEvent event) {
            // for this simple case we do all the manipulations in the drop
            // target
            // this is more of a hack ...
            _draggedRow = null;
        }
    });
    // ////////////////////
    // Drop target
    // moved to the drop target
    operations = DND.DROP_MOVE;
    final DropTarget target = new DropTarget(table, operations);
    // Receive data in Text
    final TextTransfer textTransfer = TextTransfer.getInstance();
    types = new Transfer[] { textTransfer };
    target.setTransfer(types);
    target.addDropListener(new DropTargetListener() {

        public void dragEnter(DropTargetEvent event) {
        }

        public void dragOver(DropTargetEvent event) {
            if (_draggedRow != null) {
            // no drag over effect right now
            }
        }

        public void dragOperationChanged(DropTargetEvent event) {
        }

        public void dragLeave(DropTargetEvent event) {
        }

        public void dropAccept(DropTargetEvent event) {
        }

        public void drop(DropTargetEvent event) {
            // this is kind of a hack ...
            if (textTransfer.isSupportedType(event.currentDataType)) {
                String text = (String) event.data;
                System.out.println("DROP: " + text);
                if (_draggedRow != null) {
                    int destY = Display.getCurrent().map(null, table, event.x, event.y).y;
                    int destX = Display.getCurrent().map(null, table, event.x, event.y).x;
                    IRow overRow = table.rowForY(destY);
                    if (overRow != null) {
                        System.out.println("over row " + overRow.getId());
                        // this is an action from the drag source listener
                        // ...
                        // this has to be done right here because otherwise
                        // the node would be at two places
                        // at the same time causing some redraw trouble ...
                        _parentTableNode.remNode((ITableNode) _draggedRow);
                        ITableNode node = (ITableNode) overRow;
                        node.addNode((ITableNode) _draggedRow);
                    }
                }
            }
        }
    });
    // Dispose listener on parent of timebar viewer to dispose the
    // dragsource and dragtarget BEFORE the timebar
    // viewer
    // this prevents an exception beeing thrown by SWT
    parent.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            source.dispose();
            target.dispose();
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) IRow(de.jaret.util.ui.table.model.IRow) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) IColumn(de.jaret.util.ui.table.model.IColumn) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) DropTarget(org.eclipse.swt.dnd.DropTarget) ITableNode(de.jaret.util.ui.table.model.ITableNode) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 24 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class StyleTextCellRenderer method draw.

public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    super.draw(gc, jaretTable, cellStyle, drawingArea, row, column, drawFocus, selected, printing);
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);
    String s = convertValue(row, column);
    if (s != null && strStyleText != null) {
        int index = -1;
        if (blnIsCaseSensitive) {
            index = s.toUpperCase().indexOf(strStyleText.toUpperCase());
        } else {
            index = s.indexOf(strStyleText);
        }
        if (index != -1) {
            if (textLayout == null) {
                textLayout = new TextLayout(gc.getDevice());
                jaretTable.getParent().addDisposeListener(new DisposeListener() {

                    public void widgetDisposed(DisposeEvent e) {
                        textLayout.dispose();
                    }
                });
            }
            textLayout.setText(s);
            textLayout.setFont(gc.getFont());
            textLayout.setWidth(rect.width);
            if (style == null) {
                final Color color = new Color(gc.getDevice(), 150, 100, 100);
                final Font font = new Font(gc.getDevice(), gc.getFont().getFontData()[0].getName(), gc.getFont().getFontData()[0].getHeight(), SWT.ITALIC);
                style = new TextStyle(font, color, null);
                jaretTable.getParent().addDisposeListener(new DisposeListener() {

                    public void widgetDisposed(DisposeEvent e) {
                        color.dispose();
                        font.dispose();
                    }
                });
            }
            for (int i = 1; i < strStyleText.length(); i++) {
                int j = indexOf(s, strStyleText, i, blnIsCaseSensitive);
                if (j != -1) {
                    textLayout.setStyle(style, j, j + strStyleText.length() - 1);
                } else {
                    break;
                }
            }
            gc.fillRectangle(rect);
            textLayout.draw(gc, rect.x, rect.y);
            gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
        }
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TextStyle(org.eclipse.swt.graphics.TextStyle) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Font(org.eclipse.swt.graphics.Font) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 25 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class HsImageLabel method createControl.

public Composite createControl(Composite parent) {
    parent.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            dispose();
        }
    });
    Composite content = new Composite(parent, SWT.NONE);
    GridLayout contentLayout = new GridLayout(2, false);
    contentLayout.marginWidth = 0;
    contentLayout.marginHeight = 0;
    content.setLayout(contentLayout);
    content.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    this.control = content;
    imageLabel = createImageLabel(content);
    if (imageLabel != null) {
        imageLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    }
    Composite composite = new Composite(content, SWT.NONE);
    GridLayout comLayout = new GridLayout();
    comLayout.marginWidth = 0;
    comLayout.marginHeight = 0;
    composite.setLayout(comLayout);
    composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    descriptionLabel = createDescriptionLabel(composite);
    if (descriptionLabel != null) {
        descriptionLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }
    body = new Composite(composite, SWT.NONE);
    GridLayout gd = new GridLayout();
    gd.marginRight = 0;
    gd.marginHeight = 0;
    body.setLayout(gd);
    if (body != null) {
        body.setLayoutData(new GridData(GridData.FILL_BOTH));
    }
    return body;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Aggregations

DisposeEvent (org.eclipse.swt.events.DisposeEvent)365 DisposeListener (org.eclipse.swt.events.DisposeListener)362 GridData (org.eclipse.swt.layout.GridData)103 Composite (org.eclipse.swt.widgets.Composite)91 SelectionEvent (org.eclipse.swt.events.SelectionEvent)88 GridLayout (org.eclipse.swt.layout.GridLayout)76 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)71 Image (org.eclipse.swt.graphics.Image)53 Cursor (org.eclipse.swt.graphics.Cursor)49 Label (org.eclipse.swt.widgets.Label)42 ToolBar (org.eclipse.swt.widgets.ToolBar)42 Point (org.eclipse.swt.graphics.Point)38 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)37 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)36 Control (org.eclipse.swt.widgets.Control)36 Color (org.eclipse.swt.graphics.Color)35 FillLayout (org.eclipse.swt.layout.FillLayout)35 Event (org.eclipse.swt.widgets.Event)35 MouseEvent (org.eclipse.swt.events.MouseEvent)32 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)31