Search in sources :

Example 41 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project translationstudio8 by heartsome.

the class LanguageCodesPreferencePage method addListener.

// 对需要添加监听的控件添加相应的监听器
private void addListener() {
    // 添加语言列表选择事件监听
    fFilteredTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty()) {
                return;
            }
        // 暂时注释
        // if (selection instanceof IStructuredSelection) {
        // refreshFormatControls((IStructuredSelection) selection);
        // }
        }
    });
    // 注册添加按钮的选择监听器
    addBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            addLanguage();
        }
    });
    // 注册编辑按钮的选择监听器
    editBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            verifyCurrentSelected(EDIT);
        }
    });
    // 注册删除按钮的选择监听器
    removeBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            verifyCurrentSelected(REMOVE);
        }
    });
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 42 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project translationstudio8 by heartsome.

the class NewProjectWizardLanguagePage method createControl.

/**
	 * Create contents of the wizard.
	 * @param parent
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(1, false));
    // source language control
    Group sourceLanguageGrp = new Group(container, SWT.NONE);
    sourceLanguageGrp.setLayout(new GridLayout(1, false));
    sourceLanguageGrp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    sourceLanguageGrp.setText(Messages.getString("wizard.NewProjectWizardLanguagePage.sourceLanguageGrp"));
    srcLangComboViewer = new TableComboViewer(sourceLanguageGrp, SWT.READ_ONLY | SWT.BORDER);
    TableCombo tableCombo = srcLangComboViewer.getTableCombo();
    // set options.
    tableCombo.setShowTableLines(false);
    tableCombo.setShowTableHeader(false);
    tableCombo.setDisplayColumnIndex(-1);
    tableCombo.setShowImageWithinSelection(true);
    tableCombo.setShowColorWithinSelection(false);
    tableCombo.setShowFontWithinSelection(false);
    tableCombo.setVisibleItemCount(20);
    srcLangComboViewer.getTableCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    srcLangComboViewer.setLabelProvider(new LanguageLabelProvider());
    srcLangComboViewer.setContentProvider(new ArrayContentProvider());
    srcLangComboViewer.setInput(languages);
    srcLangComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            srcLanguage = (Language) selection.getFirstElement();
            validator.update();
        }
    });
    // initialization remember value
    String rmSrcLangCode = ps.getString(IPreferenceConstants.NEW_PROJECT_SRC_LANG);
    if (rmSrcLangCode != null && !rmSrcLangCode.equals("")) {
        for (Language srcLang : languages) {
            if (srcLang.getCode().equals(rmSrcLangCode)) {
                srcLangComboViewer.setSelection(new StructuredSelection(srcLang));
                break;
            }
        }
    }
    // end source language
    // target language control
    Group targetLanguageGrp = new Group(container, SWT.NONE);
    targetLanguageGrp.setLayout(new GridLayout(3, false));
    targetLanguageGrp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    targetLanguageGrp.setText(Messages.getString("wizard.NewProjectWizardLanguagePage.targetLanguageGrp"));
    targetLangControl.createControl(targetLanguageGrp);
    // end Target language
    setControl(container);
    validator.update();
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) LanguageLabelProvider(net.heartsome.cat.ts.ui.composite.LanguageLabelProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableComboViewer(org.eclipse.nebula.jface.tablecomboviewer.TableComboViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Language(net.heartsome.cat.common.locale.Language) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableCombo(org.eclipse.nebula.widgets.tablecombo.TableCombo)

Example 43 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project translationstudio8 by heartsome.

the class NonTranslationQAPage method initListener.

/**
	 * 一些事件的添加
	 */
public void initListener() {
    // 非译元素的添加事件
    addBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            addNonTransElement();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            addNonTransElement();
        }
    });
    editBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            editNontransElement();
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
            editNontransElement();
        }
    });
    // 删除按钮的点击操作
    deleteBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            deleteElement();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            deleteElement();
        }
    });
    // 给comboViewer添加事件,同时传入内置元素
    comboViewer.getCombo().addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            addInternalElement();
            comboViewer.getCombo().setText(Messages.getString("qa.preference.NonTranslationQAPage.addInterElement"));
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            addInternalElement();
            comboViewer.getCombo().setText(Messages.getString("qa.preference.NonTranslationQAPage.addInterElement"));
        }
    });
    // 非译元素列表的点击事件
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = tableViewer.getSelection();
            if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                if (structuredSelection.getFirstElement() instanceof NontransElementBean) {
                    if (structuredSelection.size() == 1 && !validIsInternalElementNonTip((NontransElementBean) structuredSelection.getFirstElement())) {
                        editBtn.setEnabled(true);
                    } else {
                        editBtn.setEnabled(false);
                    }
                    deleteBtn.setEnabled(true);
                } else {
                    setAddModel();
                }
            } else {
                setAddModel();
            }
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent arg0) {
            editNontransElement();
        }
    });
}
Also used : NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 44 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project translationstudio8 by heartsome.

the class SelectionProviderAdapter method setSelection.

/**
	 * 设置被选中对象,并用安全线程通知监听器。
	 * @param selection
	 *            the selection
	 * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
	 */
public void setSelection(ISelection selection) {
    theSelection = selection;
    final SelectionChangedEvent e = new SelectionChangedEvent(this, selection);
    Object[] listenersArray = listeners.toArray();
    for (int i = 0; i < listenersArray.length; i++) {
        final ISelectionChangedListener l = (ISelectionChangedListener) listenersArray[i];
        SafeRunner.run(new SafeRunnable() {

            public void run() {
                l.selectionChanged(e);
            }
        });
    }
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SafeRunnable(org.eclipse.jface.util.SafeRunnable) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 45 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project translationstudio8 by heartsome.

the class RowSelectionProvider method handleLayerEvent.

public void handleLayerEvent(ILayerEvent event) {
    if (event instanceof ISelectionEvent) {
        int[] rowPositions = selectionLayer.getFullySelectedRowPositions();
        if (fullySelectedRowsOnly && rowPositions.length == 0) {
            ActiveCellRegion.setActiveCellRegion(null);
            return;
        }
        Arrays.sort(rowPositions);
        int rowPosition = rowPositions[rowPositions.length - 1];
        if (rowPosition == currentRowPosition) {
            return;
        }
        currentRowPosition = rowPosition;
        int rowIndex = selectionLayer.getRowIndexByPosition(rowPosition);
        ISelection selection = new StructuredSelection(rowIndex);
        SelectionChangedEvent e = new SelectionChangedEvent(this, selection);
        for (ISelectionChangedListener listener : listeners) {
            listener.selectionChanged(e);
        }
    }
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ISelectionEvent(net.sourceforge.nattable.selection.event.ISelectionEvent)

Aggregations

ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)770 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)750 GridData (org.eclipse.swt.layout.GridData)411 Composite (org.eclipse.swt.widgets.Composite)332 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)302 GridLayout (org.eclipse.swt.layout.GridLayout)246 SelectionEvent (org.eclipse.swt.events.SelectionEvent)190 Label (org.eclipse.swt.widgets.Label)158 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)147 TableViewer (org.eclipse.jface.viewers.TableViewer)145 Button (org.eclipse.swt.widgets.Button)141 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)138 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)130 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)118 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)116 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)116 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)116 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)115 Table (org.eclipse.swt.widgets.Table)92 ISelection (org.eclipse.jface.viewers.ISelection)85