Search in sources :

Example 36 with IStructuredSelection

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

the class RowSelectionProvider method setSelection.

@SuppressWarnings("unchecked")
public void setSelection(ISelection selection) {
    if (selectionLayer != null && selection instanceof IStructuredSelection) {
        selectionLayer.clear();
        List<Integer> rowIndexs = ((IStructuredSelection) selection).toList();
        Set<Integer> rowPositions = new HashSet<Integer>();
        for (Integer rowIndex : rowIndexs) {
            int rowPosition = selectionLayer.getRowPositionByIndex(rowIndex);
            rowPositions.add(Integer.valueOf(rowPosition));
        }
        selectionLayer.doCommand(new SelectRowsCommand(selectionLayer, 0, ObjectUtils.asIntArray(rowPositions), false, true));
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HashSet(java.util.HashSet) SelectRowsCommand(net.sourceforge.nattable.selection.command.SelectRowsCommand)

Example 37 with IStructuredSelection

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

the class RowSelectionProvider method setSelection.

@SuppressWarnings("unchecked")
public void setSelection(ISelection selection) {
    if (selectionLayer != null && selection instanceof IStructuredSelection) {
        selectionLayer.clear();
        List<T> rowObjects = ((IStructuredSelection) selection).toList();
        Set<Integer> rowPositions = new HashSet<Integer>();
        for (T rowObject : rowObjects) {
            int rowIndex = rowDataProvider.indexOfRowObject(rowObject);
            int rowPosition = selectionLayer.getRowPositionByIndex(rowIndex);
            rowPositions.add(Integer.valueOf(rowPosition));
        }
        selectionLayer.doCommand(new SelectRowsCommand(selectionLayer, 0, ObjectUtils.asIntArray(rowPositions), false, true));
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HashSet(java.util.HashSet) SelectRowsCommand(net.sourceforge.nattable.selection.command.SelectRowsCommand)

Example 38 with IStructuredSelection

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

the class SplitXliffHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final String navegatorID = "net.heartsome.cat.common.ui.navigator.view";
    final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    IFile selectFile = null;
    XLIFFEditorImplWithNatTable xliffEditor = null;
    List<Integer> splitXlfPointsIndex = new LinkedList<Integer>();
    List<String> splitXlfPointsRowId = new LinkedList<String>();
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    // 如果是导航视图,那么就获取导航视图中选中的文件
    if (activePart instanceof IViewPart) {
        if (navegatorID.equals(activePart.getSite().getId())) {
            IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(navegatorID);
            ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
            if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
                Object object = structuredSelection.getFirstElement();
                if (object instanceof IFile) {
                    selectFile = (IFile) object;
                    String fileExtension = selectFile.getFileExtension();
                    // 如果后缀名不是xlf,那么就退出操作
                    if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                        MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
                        return null;
                    }
                    FileEditorInput fileInput = new FileEditorInput(selectFile);
                    IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                    IEditorPart editorPart = null;
                    if (editorRefer.length >= 1) {
                        editorPart = editorRefer[0].getEditor(true);
                        xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
                        if (window.getActivePage().getActiveEditor() != editorPart) {
                            window.getActivePage().activate(editorPart);
                        }
                    } else {
                        try {
                            xliffEditor = (XLIFFEditorImplWithNatTable) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                        } catch (PartInitException e) {
                            LOGGER.error("", e);
                            e.printStackTrace();
                        }
                    }
                } else {
                    MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
                    return null;
                }
            }
        }
    } else if (activePart instanceof IEditorPart) {
        if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
            xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
            selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
        }
    }
    // 根据每个tu节点的rowId获取其具体的位置,才好进行排序
    Map<Integer, String> pointIndexRowIdMap = new HashMap<Integer, String>();
    for (String rowId : xliffEditor.getSplitXliffPoints()) {
        // 获取指定tu节点所处其他结点的序列号
        int tuPostion = xliffEditor.getXLFHandler().getTUPositionByRowId(rowId);
        if (tuPostion >= 1) {
            splitXlfPointsIndex.add(tuPostion);
            pointIndexRowIdMap.put(tuPostion, rowId);
        }
    }
    if (splitXlfPointsIndex.size() <= 0) {
        MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg2"));
        return null;
    }
    // 对切割点集合进行排序
    for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
        int point1 = splitXlfPointsIndex.get(i);
        for (int j = i + 1; j < splitXlfPointsIndex.size(); j++) {
            int point2 = splitXlfPointsIndex.get(j);
            if (point1 > point2) {
                splitXlfPointsIndex.set(i, point2);
                splitXlfPointsIndex.set(j, point1);
                point1 = point2;
            }
        }
    }
    // 向存储rowId的list存放数据,这样的话,所存储的rowId就是经过排序了的。
    for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
        splitXlfPointsRowId.add(pointIndexRowIdMap.get(splitXlfPointsIndex.get(i)));
    }
    SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
    model.setSplitFile(selectFile);
    model.setSplitXlfPointsIndex(splitXlfPointsIndex);
    model.setSplitXlfPointsRowId(splitXlfPointsRowId);
    model.setXliffEditor(xliffEditor);
    model.setShell(shell);
    SplitXliffWizard wizard = new SplitXliffWizard(model);
    final TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
    dialog.open();
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) SplitOrMergeXlfModel(net.heartsome.cat.ts.handlexlf.split.SplitOrMergeXlfModel) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SplitXliffWizard(net.heartsome.cat.ts.handlexlf.wizard.SplitXliffWizard) Shell(org.eclipse.swt.widgets.Shell) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NattableWizardDialog(net.heartsome.cat.ts.handlexlf.wizard.NattableWizardDialog) IEditorPart(org.eclipse.ui.IEditorPart) LinkedList(java.util.LinkedList) FileEditorInput(org.eclipse.ui.part.FileEditorInput) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Example 39 with IStructuredSelection

use of org.eclipse.jface.viewers.IStructuredSelection in project flux by eclipse.

the class SyncDisconnectHandler method getSelectedProjects.

protected IProject[] getSelectedProjects(ISelection selection) {
    List<IProject> selectedProjects = new ArrayList<IProject>();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        Object[] selectedObjects = structuredSelection.toArray();
        for (int i = 0; i < selectedObjects.length; i++) {
            if (selectedObjects[i] instanceof IAdaptable) {
                IProject project = (IProject) ((IAdaptable) selectedObjects[i]).getAdapter(IProject.class);
                if (project != null) {
                    selectedProjects.add(project);
                }
            }
        }
    }
    return (IProject[]) selectedProjects.toArray(new IProject[selectedProjects.size()]);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 40 with IStructuredSelection

use of org.eclipse.jface.viewers.IStructuredSelection in project jop by jop-devel.

the class ToggleJOPNatureAction method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        for (Iterator it = ((IStructuredSelection) selection).iterator(); it.hasNext(); ) {
            Object element = it.next();
            IProject project = null;
            if (element instanceof IProject) {
                project = (IProject) element;
            } else if (element instanceof IAdaptable) {
                project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
            }
            if (project != null) {
                toggleNature(project);
                System.err.println(project + " > Nature");
                PropertyTester jopPropTest = new JOPNaturePropertyTester();
                jopPropTest.test(project, "hasJOPNature", null, null);
            }
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) PropertyTester(org.eclipse.core.expressions.PropertyTester) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

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