Search in sources :

Example 56 with ISelection

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

the class TmDbManagerDialog method addListeners.

/**
	 * Add Selection Listener to tree viewer
	 * @param viewer
	 *            ;
	 */
private void addListeners(final TreeViewer viewer) {
    // 选择事件
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof DatabaseModelBean) {
                DatabaseModelBean bean = (DatabaseModelBean) obj;
                setCurrDbType(bean.getDbType());
                bean.copyToOtherIntance(currServer);
                SystemDBOperator dbop = getCurrSysDbOp();
                if (dbop != null) {
                    executeSearch(dbop);
                }
                // 当数据库类型发生改变时重新初始化界面
                initUI(false);
            } else if (obj instanceof String) {
                setCurrDbType((String) obj);
                resetInputValue();
                currServerdbListInput.clear();
                initUI(true);
            }
        }
    });
    // 双击展开事件
    ((Tree) viewer.getControl()).addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(final SelectionEvent event) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof String) {
                String type = (String) obj;
                boolean expanded = viewer.getExpandedState(type);
                viewer.setExpandedState(type, !expanded);
            }
        }
    });
    // 右键菜单事件,判断何时出现右键菜单
    viewer.getControl().addMenuDetectListener(new MenuDetectListener() {

        public void menuDetected(MenuDetectEvent e) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            Tree tree = treeViewer.getTree();
            if (obj instanceof DatabaseModelBean) {
                // 将菜单挂到树上
                tree.setMenu(treePopMenu);
            } else {
                tree.setMenu(null);
            }
        }
    });
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener)

Example 57 with ISelection

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

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

the class LanguageCodesPreferencePage method verifyCurrentSelected.

// 验证当前的选择是否合法,如果合法,根据操作类型进行后续的操作
protected void verifyCurrentSelected(int operateType) {
    ISelection selection = fFilteredTree.getViewer().getSelection();
    if (selection.isEmpty()) {
        String messagePattern = Messages.getString("languagecode.LanguageCodesPreferencePage.msg1");
        Object[] values = new String[0];
        if (operateType == EDIT) {
            values = new String[] { Messages.getString("languagecode.LanguageCodesPreferencePage.msg2") };
        } else if (operateType == REMOVE) {
            values = new String[] { Messages.getString("languagecode.LanguageCodesPreferencePage.msg3") };
        }
        String message = MessageFormat.format(messagePattern, values);
        MessageDialog.openInformation(fFilteredTree.getShell(), Messages.getString("languagecode.LanguageCodesPreferencePage.msgTitle"), message);
        return;
    } else if (operateType == EDIT && fFilteredTree.getViewer().getTree().getSelectionCount() > 1) {
        MessageDialog.openInformation(fFilteredTree.getShell(), Messages.getString("languagecode.LanguageCodesPreferencePage.msgTitle"), Messages.getString("languagecode.LanguageCodesPreferencePage.msg4"));
        return;
    }
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection iStructuredSelection = (IStructuredSelection) selection;
        Object object = iStructuredSelection.getFirstElement();
        if (object instanceof Language) {
            if (operateType == EDIT) {
                Language language = (Language) object;
                editLanguage(language);
            } else if (operateType == REMOVE) {
                // 删除所选择的语言
                if (MessageDialog.openConfirm(fFilteredTree.getShell(), Messages.getString("languagecode.LanguageCodesPreferencePage.msgTitle"), Messages.getString("languagecode.LanguageCodesPreferencePage.msg5"))) {
                    removeLanguage(iStructuredSelection.toList());
                }
            }
        }
    }
}
Also used : Language(net.heartsome.cat.common.locale.Language) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 59 with ISelection

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

the class AddOrEditSrxConfigDialog method editLangRules.

/**
	 * 修改语言规则,备注,在修改语言规则名称时,也会同步修改映射中语言规则的名称 ;
	 */
private void editLangRules() {
    ISelection selection = langTableViewer.getSelection();
    if (!selection.isEmpty() && selection != null && selection instanceof StructuredSelection) {
        StructuredSelection struSelection = (StructuredSelection) selection;
        @SuppressWarnings("unchecked") Iterator<String[]> it = struSelection.iterator();
        if (it.hasNext()) {
            // 获取所选中的语言规则的名称
            String langRuleName = it.next()[1];
            SrxLanguageRulesManageDialog dialog = new SrxLanguageRulesManageDialog(getShell(), false, handler, srxLocation);
            dialog.create();
            dialog.setEditInitData(langRuleName);
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                refreshLangTable(dialog.getCurLanguageRuleName());
            }
        }
    } else {
        MessageDialog.openInformation(getShell(), Messages.getString("srx.AddOrEditSrxConfigDialog.msgTitle2"), Messages.getString("srx.AddOrEditSrxConfigDialog.msg6"));
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 60 with ISelection

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

the class SrxConfigurationDialog method editSrx.

/**
	 * 编辑SRX文件 ;
	 */
private void editSrx() {
    ISelection selection = tableViewer.getSelection();
    if (!selection.isEmpty() && selection != null && selection instanceof StructuredSelection) {
        StructuredSelection structSelection = (StructuredSelection) selection;
        @SuppressWarnings("unchecked") Iterator<String[]> it = structSelection.iterator();
        if (it.hasNext()) {
            String srxName = it.next()[1];
            if (isSystemSrx(srxName)) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialogs.CatalogManagerDialog.msgTitle2"), Messages.getString("srx.SrxConfigurationDialog.msg4"));
                return;
            }
            CreateOrUpdataSRXDialog editDialog = new CreateOrUpdataSRXDialog(getShell(), false);
            editDialog.create();
            editDialog.setEditInitData(srxName);
            int result = editDialog.open();
            if (result == IDialogConstants.OK_ID) {
                String editedSrxName = editDialog.getCurSrxName();
                if (!openSrx(ADConstants.configLocation + ADConstants.AD_SRXConfigFolder + File.separator + editedSrxName)) {
                    return;
                }
                AddOrEditSrxConfigDialog addDialog = new AddOrEditSrxConfigDialog(getShell(), editedSrxName, handler);
                addDialog.open();
                refreshTable(editedSrxName);
            }
        }
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Aggregations

ISelection (org.eclipse.jface.viewers.ISelection)951 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)595 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)173 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)113 ArrayList (java.util.ArrayList)102 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)101 IResource (org.eclipse.core.resources.IResource)89 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)88 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)85 IFile (org.eclipse.core.resources.IFile)84 GridData (org.eclipse.swt.layout.GridData)80 Composite (org.eclipse.swt.widgets.Composite)67 PartInitException (org.eclipse.ui.PartInitException)66 ITextSelection (org.eclipse.jface.text.ITextSelection)65 IEditorPart (org.eclipse.ui.IEditorPart)65 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)65 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)58 SelectionEvent (org.eclipse.swt.events.SelectionEvent)57 GridLayout (org.eclipse.swt.layout.GridLayout)57 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)52