Search in sources :

Example 21 with IStructuredSelection

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

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

the class NewProjectWizardSourceFilePage 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));
    setControl(container);
    fileListViewer = new ListViewer(container, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    fileListViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    fileListViewer.setContentProvider(new ArrayContentProvider());
    fileListViewer.setInput(srcFileList);
    if (this.converterCaller != null) {
        final Button btnConvert = new Button(container, SWT.CHECK);
        btnConvert.setText(Messages.getString("wizard.NewProjectWizardSourceFilePage.btnConvert"));
        btnConvert.setSelection(true);
        isOpenConverter = true;
        btnConvert.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                isOpenConverter = btnConvert.getSelection();
            }
        });
    }
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false, 1, 1));
    Button addBtn = new Button(composite, SWT.NONE);
    addBtn.setText(Messages.getString("wizard.NewProjectWizardSourceFilePage.addBtn"));
    addBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dlg = new FileDialog(getShell(), SWT.MULTI);
            // CONVERTEREXTENTION
            String[] supExtentions = new String[] { "*.mif;*.idml;*.inx;*.xlf;*.rtf;*.po;*.properties;*.js;*.mqxlz;*.doc;*.xls;*.ppt;" + "*.docx;*.xlsx;*.pptx;*.odt;*.ods;*.odp;*.odg;*.rtf;*.sdlxliff;*.ttx;*.htm;*.html;*.txt;*.resx;*.rc;*.xml;*.txml", "*.*" };
            dlg.setFilterExtensions(supExtentions);
            if (dlg.open() != null) {
                String[] files = dlg.getFileNames();
                for (int i = 0; i < files.length; i++) {
                    StringBuffer buf = new StringBuffer(dlg.getFilterPath());
                    buf.append(File.separator);
                    buf.append(files[i]);
                    String file = buf.toString();
                    if (!srcFileList.contains(file)) {
                        srcFileList.add(file);
                    }
                }
                fileListViewer.refresh();
            }
        }
    });
    Button deleteBtn = new Button(composite, SWT.NONE);
    deleteBtn.setText(Messages.getString("wizard.NewProjectWizardSourceFilePage.deleteBtn"));
    deleteBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selections = (IStructuredSelection) fileListViewer.getSelection();
            Iterator<?> it = selections.iterator();
            while (it.hasNext()) {
                String file = (String) it.next();
                srcFileList.remove(file);
            }
            fileListViewer.refresh();
        }
    });
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 23 with IStructuredSelection

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

the class MultiSelectionPropertyTester method test.

public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    IProject curProject = null;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            if (page.getActivePartReference() == null) {
                return false;
            }
            String partId = page.getActivePartReference().getId();
            if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
                // 导航视图处于激活状态
                IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
                StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
                ArrayList<IFile> selectedIFileList = new ArrayList<IFile>();
                if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                    List<?> lstObj = ((IStructuredSelection) selection).toList();
                    for (Object obj : lstObj) {
                        if (obj instanceof IFile) {
                            IFile file = (IFile) obj;
                            // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                            if (file.getFileExtension() == null || !CommonFunction.validXlfExtension(file.getFileExtension())) {
                                return false;
                            } else {
                                String xlfFolderPath = file.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
                                if (!file.getFullPath().toOSString().startsWith(xlfFolderPath)) {
                                    return false;
                                }
                                if (curProject == null) {
                                    curProject = file.getProject();
                                } else {
                                    if (curProject != file.getProject()) {
                                        return false;
                                    }
                                }
                                selectedIFileList.add(file);
                            }
                        } else if (obj instanceof IFolder) {
                            IFolder folder = (IFolder) obj;
                            String xlfFolderPath = folder.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
                            if (!folder.getFullPath().toOSString().startsWith(xlfFolderPath)) {
                                return false;
                            }
                            try {
                                ResourceUtils.getXliffs(folder, selectedIFileList);
                            } catch (CoreException e) {
                                logger.error(Messages.getString("propertyTester.MultiSelectionPropertyTester.logger1"), folder.getFullPath().toOSString(), e);
                            }
                            if (curProject == null) {
                                curProject = folder.getProject();
                            } else {
                                if (curProject != folder.getProject()) {
                                    return false;
                                }
                            }
                        }
                    }
                    CommonFunction.removeRepeateSelect(selectedIFileList);
                    if (selectedIFileList.size() < 2) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
    return true;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFolder(org.eclipse.core.resources.IFolder)

Example 24 with IStructuredSelection

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

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

IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)600 ISelection (org.eclipse.jface.viewers.ISelection)177 GridData (org.eclipse.swt.layout.GridData)97 ArrayList (java.util.ArrayList)88 Composite (org.eclipse.swt.widgets.Composite)80 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)78 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)77 SelectionEvent (org.eclipse.swt.events.SelectionEvent)74 GridLayout (org.eclipse.swt.layout.GridLayout)73 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)67 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)60 List (java.util.List)56 TableViewer (org.eclipse.jface.viewers.TableViewer)51 Button (org.eclipse.swt.widgets.Button)51 Iterator (java.util.Iterator)46 IResource (org.eclipse.core.resources.IResource)42 RepositoryNode (org.talend.repository.model.RepositoryNode)41 IFile (org.eclipse.core.resources.IFile)40 TreeViewer (org.eclipse.jface.viewers.TreeViewer)39 Label (org.eclipse.swt.widgets.Label)38