Example usage for org.eclipse.jface.viewers IStructuredSelection size

List of usage examples for org.eclipse.jface.viewers IStructuredSelection size

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection size.

Prototype

public int size();

Source Link

Document

Returns the number of elements selected in this selection.

Usage

From source file:com.buildml.eclipse.wizards.ImportToBuildStorePage.java

License:Open Source License

/**
 * Create the widgets for this wizard's dialog box. All import dialogs require the
 * user to specify an "output" BuildML file (or select the name of a currently open
 * editor that contains such a file). However, each subclass must provide its own set of
 * input fields, depending on the goal of the import process (by overriding the 
 * createInputFields() method).//  w  ww  . j a  v  a 2s . c  o  m
 * 
 * @param parent The containing parent widget.
 */
@Override
public void createControl(Composite parent) {

    /* The top-level composite has three columns */
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout compositeLayout = new GridLayout(3, false);
    compositeLayout.marginWidth = 20;
    compositeLayout.marginHeight = 20;
    compositeLayout.verticalSpacing = 20;
    composite.setLayout(compositeLayout);

    /* page is not complete until the fields are valid */
    setPageComplete(false);

    /*
     * Show an introductory piece of text, providing instructions. This
     * label also forces the wizard box to be 33% of the screen width.
     */
    Label heading = new Label(composite, SWT.WRAP);
    GridData headingData = new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1);
    headingData.widthHint = Display.getCurrent().getClientArea().width / 3;
    heading.setLayoutData(headingData);
    heading.setText(instructions);

    /*
     * Provide a file input box, each subclass must provide its own set of input files,
     * depending on the purpose of the wizard. The createInputFields() method does
     * all of that work.
     */
    Group inputGroup = new Group(composite, SWT.NONE);
    inputGroup.setText("Import Source:");
    inputGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
    GridLayout inputGroupLayout = new GridLayout();
    inputGroupLayout.marginHeight = 10;
    inputGroupLayout.marginWidth = 10;
    inputGroup.setLayout(inputGroupLayout);
    createInputFields(inputGroup);

    /*
     * Select the destination BuildML file. Either by selecting an open editor from a combo box,
     * or by browsing for the .bml file.
     */
    Group outputGroup = new Group(composite, SWT.NONE);
    outputGroup.setText("Import Destination:");
    outputGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
    GridLayout outputGroupLayout = new GridLayout(2, false);
    outputGroupLayout.marginHeight = 10;
    outputGroupLayout.marginWidth = 10;
    outputGroup.setLayout(outputGroupLayout);

    /* Display list of open editors (if there are some) */
    final MainEditor openEditors[] = EclipsePartUtils.getOpenBmlEditors();
    boolean openEditorsExist = false;
    if ((openEditors != null) && (openEditors.length != 0)) {
        openEditorsExist = true;
        new Label(outputGroup, SWT.NONE).setText("Choose Open BuildML file:");
        bmlFileComboBox = new Combo(outputGroup, SWT.READ_ONLY | SWT.DROP_DOWN);
        bmlFileComboBox.add("");
        for (int i = 0; i < openEditors.length; i++) {
            String option = openEditors[i].getFile().toString();
            bmlFileComboBox.add(EclipsePartUtils.absoluteToWorkspaceRelativePath(option));
        }
        bmlFileComboBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

        /* 
         * When the user selects from the combo box, update the text field with the
         * workspace-relative path of the build.bml file.
         */
        bmlFileComboBox.addModifyListener(new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent e) {
                int index = bmlFileComboBox.getSelectionIndex();
                if (index > 0) {
                    String absPath = openEditors[index - 1].getFile().toString();
                    String relPath = EclipsePartUtils.absoluteToWorkspaceRelativePath(absPath);
                    if (relPath == null) {
                        relPath = "";
                    }
                    outputFile.setStringValue(relPath);
                }
            }
        });
    }

    /* Or select the BuildML file via a file browser */
    Composite outputFileComposite = new Composite(outputGroup, SWT.NONE);
    outputFileComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    outputFile = new WorkspaceFileSelectFieldEditor("outputFile",
            (openEditorsExist ? "or " : "") + "Browse BuildML Files: ", outputFileComposite,
            new String[] { "*.bml" });
    outputFile.getTextControl(outputFileComposite).addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            contentChanged();
        }
    });

    /*
     * If there was a .bml file selected when the "import" operation was initiated, select
     * that file as the default .bml file.
     */
    if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() == 1) {
            Object obj = ssel.getFirstElement();
            if (obj instanceof IFile) {
                IFile file = (IFile) obj;
                String relativePath = file.getFullPath().toString();
                if (relativePath.endsWith(".bml")) {
                    outputFile.setStringValue(relativePath);
                    if (bmlFileComboBox != null) {
                        bmlFileComboBox.setText(relativePath);
                    }
                }
            }
        }
    }

    /* done */
    setControl(composite);
}

From source file:com.buildml.eclipse.wizards.NewBmlFilePage.java

License:Open Source License

/**
 * Tests if the current workbench selection is a suitable container (project/folder) 
 * to use.//from   w  w  w .j a v  a 2 s.  c o  m
 */
private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1) {
            return;
        }
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            containerText.setText(container.getFullPath().toString());
        }
    }
    fileText.setText("build.bml");
}

From source file:com.byterefinery.rmbench.actions.ForeignKeyAction.java

License:Open Source License

protected boolean calculateEnabled() {

    selectedColumnGroup = null;// ww w  . j a v a 2s  .  c om
    groupTable = null;

    ISelection sel = (ISelection) getSelection();
    if (!(sel instanceof IStructuredSelection))
        return false;

    IStructuredSelection selection = (IStructuredSelection) sel;
    List<Column> columnGroup = new ArrayList<Column>(selection.size());

    for (Iterator<?> it = selection.iterator(); it.hasNext();) {
        Object selected = it.next();
        if (!(selected instanceof ColumnEditPart)) {
            return false;
        } else {
            Column column = ((ColumnEditPart) selected).getColumn();
            if (groupTable == null)
                groupTable = column.getTable();
            else if (groupTable != column.getTable()) {
                return false;
            }
            columnGroup.add(column);
        }
    }
    selectedColumnGroup = (Column[]) columnGroup.toArray(new Column[columnGroup.size()]);
    return true;
}

From source file:com.cea.papyrus.views.cpp.views.CppPanelView.java

License:Open Source License

public void selectionChanged(IWorkbenchPart part, ISelection selection) {

    IStructuredSelection sSelection = null;
    if (selection instanceof IStructuredSelection) {
        sSelection = (IStructuredSelection) selection;
    }//w  w w .  ja v a  2 s  . c  o m

    // exclude case of an empty selection which is not a Tree selection, since changing views provokes an
    // empty selection (selection gets lost, although same element remains selected)
    if ((selection != null) && (sSelection != null) && sSelection.isEmpty()) {
        return;
    }
    currentTarget = null;

    // No available selection: switch to default panel
    if ((sSelection == null) || (sSelection.size() != 1)) {
        switchUI();
        return;
    }

    // Retrieve selected object
    Object currentObject = sSelection.getFirstElement();
    // If the object is an edit part, try to get semantic bridge
    if (currentObject instanceof GraphicalEditPart) {
        GraphicalEditPart editPart = (GraphicalEditPart) currentObject;
        if (editPart.getModel() instanceof View) {
            View view = (View) editPart.getModel();
            if (view.getElement() instanceof Element) {
                currentObject = (Element) view.getElement();
            }
        }
    } else if (currentObject instanceof IAdaptable) {
        // modisco ModelElementItem supports IAdaptable (cleaner than cast / dependency with modisco)
        currentObject = ((IAdaptable) currentObject).getAdapter(EObject.class);
    }

    if (currentObject instanceof Element) {
        currentTarget = (Element) currentObject;
        switchUI();
    }
}

From source file:com.centurylink.mdw.plugin.designer.views.AutomatedTestActionGroup.java

License:Apache License

public boolean compareResultsApplies(IStructuredSelection selection) {
    if (selection.size() == 1) {
        if (selection.getFirstElement() instanceof AutomatedTestResults) {
            AutomatedTestResults expectedResults = (AutomatedTestResults) selection.getFirstElement();
            return expectedResults.getActualResults().exists();
        } else if (selection.getFirstElement() instanceof LegacyExpectedResults) {
            LegacyExpectedResults expectedResult = (LegacyExpectedResults) selection.getFirstElement();
            return !expectedResult.getTestCase().isRunning() && expectedResult.getActualResult().exists();
        }//from  ww w .  j av  a  2 s.  c om
    }
    return false;
}

From source file:com.centurylink.mdw.plugin.designer.views.AutomatedTestActionGroup.java

License:Apache License

public boolean formatMenuApplies(IStructuredSelection selection) {
    return selection.size() == 1 && selection.getFirstElement() instanceof AutomatedTestSuite;
}

From source file:com.centurylink.mdw.plugin.designer.views.AutomatedTestView.java

License:Apache License

public void handleSelectionChanged(IStructuredSelection selection) {
    String output = "";
    if (selection.size() == 1 && selection.getFirstElement() instanceof WorkflowElement) {
        selectedItem = (WorkflowElement) selection.getFirstElement();
        if (selectedItem instanceof AutomatedTestCase) {
            AutomatedTestCase testCase = (AutomatedTestCase) selectedItem;
            output = readFile(testCase.getOutputFile());
        } else if (selectedItem instanceof AutomatedTestResults) {
            AutomatedTestResults expectedResults = (AutomatedTestResults) selectedItem;
            output = "Results:\n-----------\n" + readFile(expectedResults.getActualResults());
        } else if (selectedItem instanceof LegacyExpectedResults) {
            LegacyExpectedResults expectedResult = (LegacyExpectedResults) selectedItem;
            output = "Results:\n-----------\n" + readFile(expectedResult.getActualResultFile());
        }//w  w  w  .j a  v a 2 s  . co m
    } else {
        selectedItem = null;
    }

    outputText.setText(output);
}

From source file:com.centurylink.mdw.plugin.designer.views.ProcessExplorerActionGroup.java

License:Apache License

public boolean showPropertiesApplies(IStructuredSelection selection) {
    if (selection.size() != 1)
        return false;

    Object element = selection.getFirstElement();
    if (!(element instanceof WorkflowElement))
        return false;
    if (element instanceof AutomatedTestCase)
        return !((AutomatedTestCase) element).isLegacy();
    if (element instanceof WorkflowProject || element instanceof WorkflowPackage
            || element instanceof WorkflowProcess || element instanceof ExternalEvent
            || element instanceof WorkflowAsset || element instanceof AutomatedTestCase) {
        return true;
    }//from  w ww. j  ava 2  s .c  om

    return false;
}

From source file:com.centurylink.mdw.plugin.designer.views.ProcessExplorerActionGroup.java

License:Apache License

public boolean incrementVersionApplies(IStructuredSelection selection) {
    if (selection.size() != 1)
        return false;
    if (!(selection.getFirstElement() instanceof WorkflowPackage))
        return false;

    WorkflowPackage packageVersion = (WorkflowPackage) selection.getFirstElement();
    if (packageVersion.isDefaultPackage() || packageVersion.isArchived()
            || !packageVersion.isUserAuthorized(UserRoleVO.ASSET_DESIGN))
        return false;

    return true;/*from  ww  w . ja  va 2s  . c  om*/
}

From source file:com.centurylink.mdw.plugin.designer.views.ProcessExplorerActionGroup.java

License:Apache License

public boolean setVersionApplies(IStructuredSelection selection) {
    if (selection.size() != 1)
        return false;
    if (!(selection.getFirstElement() instanceof WorkflowPackage))
        return false;

    WorkflowPackage packageVersion = (WorkflowPackage) selection.getFirstElement();
    if (packageVersion.isDefaultPackage() || packageVersion.isArchived()
            || !packageVersion.isUserAuthorized(UserRoleVO.ASSET_DESIGN))
        return false;

    return true;// w  w w. j a  v a 2s  .  c om
}