Search in sources :

Example 41 with SelectionChangedEvent

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

the class XLIFFEditorActionHandler method addTextViewer.

/**
	 * Add a <code>Text</code> control to the handler so that the Cut, Copy, Paste, Delete, Undo, Redo and Select All
	 * actions are redirected to it when active.
	 * @param viewer
	 *            the inline <code>Text</code> control
	 */
public void addTextViewer(SegmentViewer viewer) {
    if (viewer == null) {
        return;
    }
    this.viewer = viewer;
    StyledText textControl = viewer.getTextWidget();
    // 移除 StyledText 默认绑定的 Delete 键。解决“按下 Delete 键后会删除两次”的 Bug。
    textControl.setKeyBinding(SWT.DEL, SWT.NULL);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            updateActionsEnableState();
        }
    });
    textControl.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            updateActionsEnableState();
        }
    });
    actionBar.setGlobalActionHandler(ActionFactory.CUT.getId(), textCutAction);
    actionBar.setGlobalActionHandler(ActionFactory.COPY.getId(), textCopyAction);
    actionBar.setGlobalActionHandler(ActionFactory.PASTE.getId(), textPasteAction);
    actionBar.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), textSelectAllAction);
    actionBar.setGlobalActionHandler(ActionFactory.DELETE.getId(), textDeleteAction);
    actionBar.setGlobalActionHandler(ActionFactory.UNDO.getId(), textUndoAction);
    actionBar.setGlobalActionHandler(ActionFactory.REDO.getId(), textRedoAction);
    if (textControl.isFocusControl()) {
        updateActionsEnableState();
    } else {
        actionBar.updateActionBars();
    }
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) StyledText(org.eclipse.swt.custom.StyledText) ModifyListener(org.eclipse.swt.events.ModifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 42 with SelectionChangedEvent

use of org.eclipse.jface.viewers.SelectionChangedEvent 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 43 with SelectionChangedEvent

use of org.eclipse.jface.viewers.SelectionChangedEvent 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 44 with SelectionChangedEvent

use of org.eclipse.jface.viewers.SelectionChangedEvent 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 45 with SelectionChangedEvent

use of org.eclipse.jface.viewers.SelectionChangedEvent 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)

Aggregations

SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)802 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)754 GridData (org.eclipse.swt.layout.GridData)417 Composite (org.eclipse.swt.widgets.Composite)332 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)303 GridLayout (org.eclipse.swt.layout.GridLayout)245 SelectionEvent (org.eclipse.swt.events.SelectionEvent)187 Label (org.eclipse.swt.widgets.Label)158 TableViewer (org.eclipse.jface.viewers.TableViewer)153 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)147 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)140 Button (org.eclipse.swt.widgets.Button)140 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)126 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)121 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)120 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)116 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)116 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)116 Table (org.eclipse.swt.widgets.Table)93 ISelection (org.eclipse.jface.viewers.ISelection)84