Search in sources :

Example 71 with SelectionEvent

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

the class CatalogManagerDialog method initListener.

/**
	 * 给三个按钮添加事件 ;
	 */
public void initListener() {
    addBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AddOrEditCatalogDialog addDialog = new AddOrEditCatalogDialog(getShell(), root, adHandler, true);
            // 如果是点击的确定按钮,那么更新数据
            if (addDialog.open() == IDialogConstants.OK_ID) {
                String[][] cataValue = getCatalogValue();
                tableViewer.setInput(cataValue);
                tableViewer.getTable().setSelection(cataValue.length - 1);
                tableViewer.getTable().showSelection();
            }
        }
    });
    // <public publicId="-//W3C//DTD XMLSCHEMA 200102//EN" uri="xml/XMLSchema.dtd"/>
    // <system systemId="xliff.dtd" uri="xliff/xliff.dtd"/>
    // <uri name="http://www.heartsome.net.cn/2008/XLFExtension" uri="heartsome/XLFExtension.xsd"/>
    // <nextCatalog catalog="docbook5.0/catalog.xml"/>
    deleteBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (table.getSelectionCount() >= 1) {
                boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("dialogs.CatalogManagerDialog.msgTitle"), Messages.getString("dialogs.CatalogManagerDialog.msg1"));
                if (!response) {
                    return;
                }
                TableItem[] selectItems = table.getSelection();
                List<String> xpathList = new LinkedList<String>();
                List<String[]> dataList = new LinkedList<String[]>();
                for (int i = 0; i < selectItems.length; i++) {
                    String name = selectItems[i].getText(1);
                    String id = selectItems[i].getText(2);
                    String url = selectItems[i].getText(3);
                    StringBuffer xpathSB = new StringBuffer();
                    if ("public".equalsIgnoreCase(name)) {
                        xpathSB.append("/catalog/public[@publicId='" + id + "' and @uri='" + url + "']");
                    } else if ("system".equalsIgnoreCase(name)) {
                        xpathSB.append("/catalog/system[@systemId='" + id + "' and @uri='" + url + "']");
                    } else if ("uri".equalsIgnoreCase(name)) {
                        xpathSB.append("/catalog/uri[@name='" + id + "' and @uri='" + url + "']");
                    } else if ("nextCatalog".equalsIgnoreCase(name)) {
                        xpathSB.append("/catalog/nextCatalog[@catalog='" + url + "']");
                    }
                    xpathList.add(xpathSB.toString());
                    dataList.add(new String[] { name, id, url });
                }
                adHandler.deleteCatalog(catalogXmlLocation, xpathList, dataList);
                // 更新列表
                tableViewer.setInput(getCatalogValue());
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("dialogs.CatalogManagerDialog.msgTitle2"), Messages.getString("dialogs.CatalogManagerDialog.msg2"));
            }
        }
    });
    editBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            editCatalog();
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            editCatalog();
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) LinkedList(java.util.LinkedList) List(java.util.List)

Example 72 with SelectionEvent

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

the class XmlConvertManagerDialog method initListener.

/**
	 * 给增删改三个按钮添加点击事件 ;
	 */
protected void initListener() {
    addBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AddOrEditElementOfXmlConvertDialog dialog = new AddOrEditElementOfXmlConvertDialog(getShell(), true, elementsList);
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                refreshTable(dialog.getCurrentElement());
            }
        }
    });
    editBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            editElement();
        }
    });
    deleteBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = tableViewer.getSelection();
            if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                if (MessageDialog.openConfirm(getShell(), Messages.getString("dialogs.XmlConvertManagerDialog.msgTitle1"), Messages.getString("dialogs.XmlConvertManagerDialog.msg1"))) {
                    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                    @SuppressWarnings("unchecked") Iterator<ElementBean> iter = structuredSelection.iterator();
                    ElementBean bean = new ElementBean();
                    while (iter.hasNext()) {
                        bean = iter.next();
                        elementsList.remove(bean);
                    }
                    refreshTable(null);
                }
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("dialogs.XmlConvertManagerDialog.msgTitle2"), Messages.getString("dialogs.XmlConvertManagerDialog.msg2"));
            }
        }
    });
}
Also used : ElementBean(net.heartsome.cat.ts.ui.advanced.model.ElementBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 73 with SelectionEvent

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

the class XmlConverterConfigurationDialog method createHelpToolItem.

/**
	 * 添加帮助按钮,备注,这里的配置与其他的不一样
	 * robert	2012-09-06
	 */
protected Control createHelpToolItem(Composite parent) {
    // ROBERTHELP xml 转换器配置
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch08.html#configure-xml-converter", language);
    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    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 74 with SelectionEvent

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

the class XmlConverterConfigurationDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridDataFactory.fillDefaults().grab(true, true).hint(400, 450).minSize(400, 450).applyTo(tparent);
    tableViewer = new TableViewer(tparent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    String[] columnNames = new String[] { Messages.getString("dialogs.XmlConverterConfigurationDialog.columnNames1"), Messages.getString("dialogs.XmlConverterConfigurationDialog.columnNames2") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
        tableColumn.setWidth(50);
        // 处理排序的问题
        switch(i) {
            case 0:
                tableColumn.addSelectionListener(new SelectionAdapter() {

                    // 升序
                    boolean asc = true;

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        tableViewer.setSorter(asc ? XmlConvertOrder.index_ASC : XmlConvertOrder.index_DESC);
                        asc = !asc;
                    }
                });
                break;
            case 1:
                tableColumn.addSelectionListener(new SelectionAdapter() {

                    // 升序
                    boolean asc = true;

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        tableViewer.setSorter(asc ? XmlConvertOrder.xmlName_ASC : XmlConvertOrder.xmlName_DESC);
                        asc = !asc;
                    }
                });
                break;
            default:
                break;
        }
    }
    tableViewer.setInput(getXmlConfigFilesInfo());
    // 让列表列宽动态变化
    table.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event event) {
            final Table table = ((Table) event.widget);
            final TableColumn[] columns = table.getColumns();
            event.widget.getDisplay().syncExec(new Runnable() {

                public void run() {
                    double[] columnWidths = new double[] { 0.1, 0.85 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            editConfigXml();
        }
    });
    return tparent;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerLabelProvider(net.heartsome.cat.ts.ui.advanced.TableViewerLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 75 with SelectionEvent

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

the class XmlConverterConfigurationDialog method initListener.

public void initListener() {
    addBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AddOrEditXmlConvertConfigDialog dialog = new AddOrEditXmlConvertConfigDialog(getShell(), true);
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                String curentConvertXMl = dialog.getCurentConverXML();
                refreshTable();
                setTableSelection(curentConvertXMl);
            }
        }
    });
    editBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            editConfigXml();
        }
    });
    deleteBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = tableViewer.getSelection();
            if (!selection.isEmpty() && selection != null && selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                @SuppressWarnings("unchecked") Iterator<String[]> iter = structuredSelection.iterator();
                while (iter.hasNext()) {
                    String convertXmlName = iter.next()[1];
                    String convertXmlLoaction = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).append(convertXmlName).toOSString();
                    File convertXml = new File(convertXmlLoaction);
                    convertXml.delete();
                }
                refreshTable();
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("dialogs.XmlConverterConfigurationDialog.msgTitle"), Messages.getString("dialogs.XmlConverterConfigurationDialog.msg1"));
            }
        }
    });
    analysisBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AnalysisXmlConvertConfigDialg dialog = new AnalysisXmlConvertConfigDialg(getShell());
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                String curentConvertXMl = dialog.getCurentConverXML();
                refreshTable();
                setTableSelection(curentConvertXMl);
            }
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) File(java.io.File)

Aggregations

SelectionEvent (org.eclipse.swt.events.SelectionEvent)1136 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)923 GridData (org.eclipse.swt.layout.GridData)670 GridLayout (org.eclipse.swt.layout.GridLayout)566 Button (org.eclipse.swt.widgets.Button)558 Composite (org.eclipse.swt.widgets.Composite)553 Label (org.eclipse.swt.widgets.Label)370 SelectionListener (org.eclipse.swt.events.SelectionListener)262 Text (org.eclipse.swt.widgets.Text)253 Group (org.eclipse.swt.widgets.Group)193 ModifyEvent (org.eclipse.swt.events.ModifyEvent)160 ModifyListener (org.eclipse.swt.events.ModifyListener)159 Combo (org.eclipse.swt.widgets.Combo)140 Point (org.eclipse.swt.graphics.Point)98 MenuItem (org.eclipse.swt.widgets.MenuItem)95 Menu (org.eclipse.swt.widgets.Menu)94 TableViewer (org.eclipse.jface.viewers.TableViewer)91 Table (org.eclipse.swt.widgets.Table)91 ToolItem (org.eclipse.swt.widgets.ToolItem)90 ArrayList (java.util.ArrayList)88