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.redhat.ceylon.eclipse.code.explorer.PackageExplorerPart.java

License:Open Source License

private boolean inputIsSelected(IEditorInput input) {
    IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
    if (selection.size() != 1)
        return false;

    IEditorInput selectionAsInput = EditorUtility.getEditorInput(selection.getFirstElement());
    return input.equals(selectionAsInput);
}

From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerPart.java

License:Open Source License

public boolean show(ShowInContext context) {
    ISelection selection = context.getSelection();
    if (selection instanceof IStructuredSelection) {
        // fix for 64634 Navigate/Show in/Package Explorer doesn't work
        IStructuredSelection structuredSelection = ((IStructuredSelection) selection);
        if (structuredSelection.size() == 1) {
            int res = tryToReveal(structuredSelection.getFirstElement());
            if (res == IStatus.OK)
                return true;
            if (res == IStatus.CANCEL)
                return false;
        } else if (structuredSelection.size() > 1) {
            selectReveal(structuredSelection);
            return true;
        }/*from   ww  w .ja v  a 2  s. co m*/
    }

    Object input = context.getInput();
    if (input instanceof IEditorInput) {
        Object elementOfInput = getInputFromEditor((IEditorInput) input);
        return elementOfInput != null && (tryToReveal(elementOfInput) == IStatus.OK);
    }

    return false;
}

From source file:com.remainsoftware.tycho.pombuilder.ui.internal.actions.EnableNatureAction.java

License:Open Source License

@Override
public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        for (Iterator<?> it = structuredSelection.iterator(); it.hasNext();) {
            Object element = it.next();
            IProject project = null;//from   w w  w  .j a  v  a  2s.c om
            if (element instanceof IProject) {
                project = (IProject) element;
            } else if (element instanceof IAdaptable) {
                project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
            }
            if (project != null) {
                try {
                    enableNature(project, structuredSelection.size() == 1);
                } catch (CoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}

From source file:com.rinke.solutions.pinball.PinDmdEditor.java

/**
 * Create contents of the window./*w w w.j a va 2s  .  c  o m*/
 */
void createContents(Shell shell) {
    shell.setSize(1238, 657);
    shell.setText("Pin2dmd - Editor");
    shell.setLayout(new GridLayout(4, false));

    createMenu(shell);

    recentProjectsMenuManager = new RecentMenuManager("recentProject", 4, menuPopRecentProjects,
            e -> loadProject((String) e.widget.getData()));
    recentProjectsMenuManager.loadRecent();

    recentPalettesMenuManager = new RecentMenuManager("recentPalettes", 4, mntmRecentPalettes,
            e -> paletteHandler.loadPalette((String) e.widget.getData()));
    recentPalettesMenuManager.loadRecent();

    recentAnimationsMenuManager = new RecentMenuManager("recentAnimations", 4, mntmRecentAnimations,
            e -> aniAction.loadAni(((String) e.widget.getData()), true, false));
    recentAnimationsMenuManager.loadRecent();

    resManager = new LocalResourceManager(JFaceResources.getResources(), shell);

    Label lblAnimations = new Label(shell, SWT.NONE);
    lblAnimations.setText("Animations");

    Label lblKeyframes = new Label(shell, SWT.NONE);
    lblKeyframes.setText("KeyFrames");

    Label lblPreview = new Label(shell, SWT.NONE);
    lblPreview.setText("Preview");
    new Label(shell, SWT.NONE);

    aniListViewer = new TableViewer(shell, SWT.BORDER | SWT.V_SCROLL);
    Table aniList = aniListViewer.getTable();
    GridData gd_aniList = new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1);
    gd_aniList.widthHint = 189;
    aniList.setLayoutData(gd_aniList);
    aniList.setLinesVisible(true);
    aniList.addKeyListener(new EscUnselect(aniListViewer));
    aniListViewer.setContentProvider(ArrayContentProvider.getInstance());
    aniListViewer.setLabelProvider(new LabelProviderAdapter(o -> ((Animation) o).getDesc()));
    aniListViewer.setInput(animations.values());
    aniListViewer.addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        onAnimationSelectionChanged(selection.size() > 0 ? (Animation) selection.getFirstElement() : null);
    });
    TableViewerColumn viewerCol1 = new TableViewerColumn(aniListViewer, SWT.LEFT);
    viewerCol1.setEditingSupport(
            new GenericTextCellEditor(aniListViewer, e -> ((Animation) e).getDesc(), (e, v) -> {
                Animation ani = (Animation) e;
                updateAnimationMapKey(ani.getDesc(), v);
                ani.setDesc(v);
                frameSeqViewer.refresh();
            }));

    viewerCol1.getColumn().setWidth(220);
    viewerCol1.setLabelProvider(new ColumnLabelProviderAdapter(o -> ((Animation) o).getDesc()));

    keyframeTableViewer = new TableViewer(shell, SWT.SINGLE | SWT.V_SCROLL);
    Table keyframeList = keyframeTableViewer.getTable();
    GridData gd_keyframeList = new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1);
    gd_keyframeList.widthHint = 137;
    keyframeList.setLinesVisible(true);
    keyframeList.setLayoutData(gd_keyframeList);
    keyframeList.addKeyListener(new EscUnselect(keyframeTableViewer));

    //keyframeTableViewer.setLabelProvider(new KeyframeLabelProvider(shell));
    keyframeTableViewer.setContentProvider(ArrayContentProvider.getInstance());
    keyframeTableViewer.setInput(project.palMappings);
    keyframeTableViewer.addSelectionChangedListener(event -> keyFrameChanged(event));

    TableViewerColumn viewerColumn = new TableViewerColumn(keyframeTableViewer, SWT.LEFT);
    viewerColumn.setEditingSupport(
            new GenericTextCellEditor(keyframeTableViewer, e -> ((PalMapping) e).name, (e, v) -> {
                ((PalMapping) e).name = v;
            }));

    viewerColumn.getColumn().setWidth(200);
    viewerColumn.setLabelProvider(new KeyframeLabelProvider(shell));

    dmdWidget = new DMDWidget(shell, SWT.DOUBLE_BUFFERED, this.dmd, true);
    // dmdWidget.setBounds(0, 0, 700, 240);
    GridData gd_dmdWidget = new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1);
    gd_dmdWidget.heightHint = 231;
    gd_dmdWidget.widthHint = 826;
    dmdWidget.setLayoutData(gd_dmdWidget);
    dmdWidget.setPalette(activePalette);
    dmdWidget.addListeners(l -> frameChanged(l));

    Composite composite_1 = new Composite(shell, SWT.NONE);
    composite_1.setLayout(new GridLayout(2, false));
    GridData gd_composite_1 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_composite_1.heightHint = 35;
    gd_composite_1.widthHint = 206;
    composite_1.setLayoutData(gd_composite_1);

    btnRemoveAni = new Button(composite_1, SWT.NONE);
    btnRemoveAni.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    btnRemoveAni.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
        }
    });
    btnRemoveAni.setText("Remove");
    btnRemoveAni.setEnabled(false);
    btnRemoveAni.addListener(SWT.Selection, e -> {
        if (selectedAnimation.isPresent()) {
            String key = selectedAnimation.get().getDesc();
            animations.remove(key);
            playingAnis.clear();
            animationHandler.setAnimations(playingAnis);
            animationHandler.setClockActive(true);
        }
    });

    btnSortAni = new Button(composite_1, SWT.NONE);
    btnSortAni.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    btnSortAni.setText("Sort");
    btnSortAni.addListener(SWT.Selection, e -> sortAnimations());

    Composite composite_2 = new Composite(shell, SWT.NONE);
    composite_2.setLayout(new GridLayout(3, false));
    GridData gd_composite_2 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_composite_2.heightHint = 35;
    gd_composite_2.widthHint = 157;
    composite_2.setLayoutData(gd_composite_2);

    btnDeleteKeyframe = new Button(composite_2, SWT.NONE);
    GridData gd_btnDeleteKeyframe = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_btnDeleteKeyframe.widthHint = 88;
    btnDeleteKeyframe.setLayoutData(gd_btnDeleteKeyframe);
    btnDeleteKeyframe.setText("Remove");
    btnDeleteKeyframe.setEnabled(false);
    btnDeleteKeyframe.addListener(SWT.Selection, e -> {
        if (selectedPalMapping != null) {
            project.palMappings.remove(selectedPalMapping);
            keyframeTableViewer.refresh();
            checkReleaseMask();
        }
    });

    Button btnSortKeyFrames = new Button(composite_2, SWT.NONE);
    btnSortKeyFrames.setText("Sort");
    btnSortKeyFrames.addListener(SWT.Selection, e -> sortKeyFrames());
    new Label(composite_2, SWT.NONE);

    scale = new Scale(shell, SWT.NONE);
    scale.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    scale.addListener(SWT.Selection, e -> animationHandler.setPos(scale.getSelection()));

    Group grpKeyframe = new Group(shell, SWT.NONE);
    grpKeyframe.setLayout(new GridLayout(3, false));
    GridData gd_grpKeyframe = new GridData(SWT.FILL, SWT.TOP, false, false, 2, 4);
    gd_grpKeyframe.heightHint = 191;
    gd_grpKeyframe.widthHint = 350;
    grpKeyframe.setLayoutData(gd_grpKeyframe);
    grpKeyframe.setText("KeyFrames");

    Composite composite_hash = new Composite(grpKeyframe, SWT.NONE);
    //gd_composite_hash.widthHint = 105;
    GridData gd_composite_hash = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
    gd_composite_hash.widthHint = 148;
    composite_hash.setLayoutData(gd_composite_hash);
    createHashButtons(composite_hash, 10, 0);

    previewDmd = new DMDWidget(grpKeyframe, SWT.DOUBLE_BUFFERED, dmd, false);
    GridData gd_dmdPreWidget = new GridData(SWT.CENTER, SWT.TOP, false, false, 1, 1);
    gd_dmdPreWidget.heightHint = 40;
    gd_dmdPreWidget.widthHint = 132;
    previewDmd.setLayoutData(gd_dmdPreWidget);
    previewDmd.setDrawingEnabled(false);
    previewDmd.setPalette(previewPalettes.get(0));

    new Label(grpKeyframe, SWT.NONE);

    btnAddColormaskKeyFrame = new Button(grpKeyframe, SWT.NONE);
    btnAddColormaskKeyFrame
            .setToolTipText("Adds a key frame that trigger a color masking scene to be overlayed");
    btnAddColormaskKeyFrame.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    btnAddColormaskKeyFrame.setText("Add ColorMask");
    btnAddColormaskKeyFrame.setEnabled(false);
    btnAddColormaskKeyFrame.addListener(SWT.Selection, e -> addFrameSeq(SwitchMode.ADD));

    btnAddKeyframe = new Button(grpKeyframe, SWT.NONE);
    btnAddKeyframe.setToolTipText("Adds a key frame that switches palette");
    btnAddKeyframe.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1));
    btnAddKeyframe.setText("Add PalSwitch");
    btnAddKeyframe.setEnabled(false);
    btnAddKeyframe.addListener(SWT.Selection, e -> addKeyFrame(SwitchMode.PALETTE));

    Label lblDuration = new Label(grpKeyframe, SWT.NONE);
    lblDuration.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblDuration.setText("Duration:");

    txtDuration = new Text(grpKeyframe, SWT.BORDER);
    GridData gd_txtDuration = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_txtDuration.widthHint = 93;
    txtDuration.setLayoutData(gd_txtDuration);
    txtDuration.setText("0");
    txtDuration.addListener(SWT.Verify, e -> e.doit = Pattern.matches("^[0-9]*$", e.text));
    txtDuration.addListener(SWT.Modify, e -> {
        if (selectedPalMapping != null) {
            selectedPalMapping.durationInMillis = Integer.parseInt(txtDuration.getText());
            selectedPalMapping.durationInFrames = (int) selectedPalMapping.durationInMillis / 40;
        }
    });

    btnFetchDuration = new Button(grpKeyframe, SWT.NONE);
    btnFetchDuration.setToolTipText(
            "Fetches duration for palette switches by calculating the difference between actual timestamp and keyframe timestamp");
    btnFetchDuration.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    btnFetchDuration.setText("Fetch Duration");
    btnFetchDuration.setEnabled(false);
    btnFetchDuration.addListener(SWT.Selection, e -> {
        if (selectedPalMapping != null) {
            selectedPalMapping.durationInMillis = lastTimeCode - saveTimeCode;
            selectedPalMapping.durationInFrames = (int) selectedPalMapping.durationInMillis / FRAME_RATE;
            txtDuration.setText(selectedPalMapping.durationInMillis + "");
        }
    });

    Label lblNewLabel = new Label(grpKeyframe, SWT.NONE);
    lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblNewLabel.setText("FrameSeq:");

    frameSeqViewer = new ComboViewer(grpKeyframe, SWT.NONE);
    Combo frameSeqCombo = frameSeqViewer.getCombo();
    frameSeqCombo.setToolTipText("Choose frame sequence to use with key frame");
    GridData gd_frameSeqCombo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_frameSeqCombo.widthHint = 100;
    frameSeqCombo.setLayoutData(gd_frameSeqCombo);
    frameSeqViewer.setLabelProvider(new LabelProviderAdapter(o -> ((Animation) o).getDesc()));
    frameSeqViewer.setContentProvider(ArrayContentProvider.getInstance());
    frameSeqViewer.setInput(frameSeqList);
    frameSeqViewer.addSelectionChangedListener(event -> frameSeqChanged(event));

    btnAddFrameSeq = new Button(grpKeyframe, SWT.NONE);
    btnAddFrameSeq.setToolTipText("Adds a keyframe that triggers playback of a replacement scene");
    btnAddFrameSeq.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    btnAddFrameSeq.setText("Add FrameSeq");
    btnAddFrameSeq.addListener(SWT.Selection, e -> addFrameSeq(SwitchMode.REPLACE));
    btnAddFrameSeq.setEnabled(false);

    Group grpDetails = new Group(shell, SWT.NONE);
    grpDetails.setLayout(new GridLayout(10, false));
    GridData gd_grpDetails = new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1);
    gd_grpDetails.heightHint = 21;
    gd_grpDetails.widthHint = 776;
    grpDetails.setLayoutData(gd_grpDetails);
    grpDetails.setText("Details");

    Label lblFrame = new Label(grpDetails, SWT.NONE);
    lblFrame.setText("Frame:");

    lblFrameNo = new Label(grpDetails, SWT.NONE);
    GridData gd_lblFrameNo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_lblFrameNo.widthHint = 66;
    gd_lblFrameNo.minimumWidth = 60;
    lblFrameNo.setLayoutData(gd_lblFrameNo);
    lblFrameNo.setText("---");

    Label lblTimecode = new Label(grpDetails, SWT.NONE);
    lblTimecode.setText("Timecode:");

    lblTcval = new Label(grpDetails, SWT.NONE);
    GridData gd_lblTcval = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_lblTcval.widthHint = 62;
    gd_lblTcval.minimumWidth = 80;
    lblTcval.setLayoutData(gd_lblTcval);
    lblTcval.setText("---");

    Label lblDelay = new Label(grpDetails, SWT.NONE);
    lblDelay.setText("Delay:");

    lblDelayVal = new Label(grpDetails, SWT.NONE);
    GridData gd_lblDelayVal = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_lblDelayVal.widthHint = 53;
    lblDelayVal.setLayoutData(gd_lblDelayVal);
    lblDelayVal.setText("---");

    Label lblPlanes = new Label(grpDetails, SWT.NONE);
    lblPlanes.setText("Planes:");

    lblPlanesVal = new Label(grpDetails, SWT.NONE);
    lblPlanesVal.setText("---");
    new Label(grpDetails, SWT.NONE);

    btnLivePreview = new Button(grpDetails, SWT.CHECK);
    btnLivePreview.setToolTipText("controls live preview to real display device");
    btnLivePreview.setText("Live Preview");
    btnLivePreview.addListener(SWT.Selection, e -> switchLivePreview(e));

    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayout(new GridLayout(9, false));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));

    btnStartStop = new Button(composite, SWT.NONE);
    btnStartStop.setText("Start");
    btnStartStop.addListener(SWT.Selection, e -> startStop(animationHandler.isStopped()));

    btnPrev = new Button(composite, SWT.NONE);
    btnPrev.setText("<");
    btnPrev.addListener(SWT.Selection, e -> prevFrame());

    btnNext = new Button(composite, SWT.NONE);
    btnNext.setText(">");
    btnNext.addListener(SWT.Selection, e -> nextFrame());

    btnMarkStart = new Button(composite, SWT.NONE);
    btnMarkStart.setToolTipText("Marks start of scene for cutting");
    btnMarkEnd = new Button(composite, SWT.NONE);
    btnCut = new Button(composite, SWT.NONE);
    btnCut.setToolTipText("Cuts out a new scene for editing and use a replacement or color mask");

    btnMarkStart.setText("Mark Start");
    btnMarkStart.addListener(SWT.Selection, e -> {
        cutInfo.setStart(selectedAnimation.get().actFrame);
    });

    btnMarkEnd.setText("Mark End");
    btnMarkEnd.addListener(SWT.Selection, e -> {
        cutInfo.setEnd(selectedAnimation.get().actFrame);
    });

    btnCut.setText("Cut");
    btnCut.addListener(SWT.Selection, e -> {
        // respect number of planes while cutting / copying
        Animation ani = cutScene(selectedAnimation.get(), cutInfo.getStart(), cutInfo.getEnd(),
                "Scene " + animations.size());
        log.info("cutting out scene from {} to {}", cutInfo);
        cutInfo.reset();

        // TODO mark such a scene somehow, to copy it to the
        // projects frames sequence for later export
        // alternatively introduce a dedicated flag for scenes that
        // should be exported
        // also define a way that a keyframe triggers a replacement
        // sequence instead of switching
        // the palette only
        // TODO NEED TO ADD a reference to the animation in the list
        // / map
        project.scenes.add(new Scene(ani.getDesc(), ani.start, ani.end, activePalette.index));
    });

    new Label(composite, SWT.NONE);

    Button btnIncPitch = new Button(composite, SWT.NONE);
    btnIncPitch.setText("+");
    btnIncPitch.addListener(SWT.Selection, e -> dmdWidget.incPitch());

    Button btnDecPitch = new Button(composite, SWT.NONE);
    btnDecPitch.setText("-");
    btnDecPitch.addListener(SWT.Selection, e -> dmdWidget.decPitch());

    Group grpPalettes = new Group(shell, SWT.NONE);
    grpPalettes.setLayout(new GridLayout(4, false));
    GridData gd_grpPalettes = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
    gd_grpPalettes.widthHint = 479;
    gd_grpPalettes.heightHint = 71;
    grpPalettes.setLayoutData(gd_grpPalettes);
    grpPalettes.setText("Palettes");

    paletteComboViewer = new ComboViewer(grpPalettes, SWT.NONE);
    Combo combo = paletteComboViewer.getCombo();
    GridData gd_combo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_combo.widthHint = 166;
    combo.setLayoutData(gd_combo);
    paletteComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    paletteComboViewer
            .setLabelProvider(new LabelProviderAdapter(o -> ((Palette) o).index + " - " + ((Palette) o).name));
    paletteComboViewer.setInput(project.palettes);
    paletteComboViewer.addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        if (selection.size() > 0) {
            paletteChanged((Palette) selection.getFirstElement());
        }
    });

    paletteTypeComboViewer = new ComboViewer(grpPalettes, SWT.READ_ONLY);
    Combo combo_1 = paletteTypeComboViewer.getCombo();
    combo_1.setToolTipText(
            "Type of palette. Default palette is choosen at start and after timed switch is expired");
    GridData gd_combo_1 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_combo_1.widthHint = 85;
    combo_1.setLayoutData(gd_combo_1);
    paletteTypeComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    paletteTypeComboViewer.setInput(PaletteType.values());
    paletteTypeComboViewer.setSelection(new StructuredSelection(activePalette.type));
    paletteTypeComboViewer.addSelectionChangedListener(e -> paletteTypeChanged(e));

    btnNewPalette = new Button(grpPalettes, SWT.NONE);
    btnNewPalette.setToolTipText("Creates a new palette by copying the actual colors");
    btnNewPalette.setText("New");
    btnNewPalette.addListener(SWT.Selection, e -> paletteHandler.newPalette());

    btnRenamePalette = new Button(grpPalettes, SWT.NONE);
    btnRenamePalette.setToolTipText("Confirms the new palette name");
    btnRenamePalette.setText("Rename");
    btnRenamePalette.addListener(SWT.Selection, e -> {
        String newName = paletteComboViewer.getCombo().getText();
        if (newName.contains(" - ")) {
            activePalette.name = newName.split(" - ")[1];
            paletteComboViewer.setSelection(new StructuredSelection(activePalette));
            paletteComboViewer.refresh();
        } else {
            warn("Illegal palette name",
                    "Palette names must consist of palette index and name.\nName format therefore must be '<idx> - <name>'");
            paletteComboViewer.getCombo().setText(activePalette.index + " - " + activePalette.name);
        }

    });

    Composite grpPal = new Composite(grpPalettes, SWT.NONE);
    grpPal.setLayout(new GridLayout(1, false));
    GridData gd_grpPal = new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1);
    gd_grpPal.widthHint = 313;
    gd_grpPal.heightHint = 22;
    grpPal.setLayoutData(gd_grpPal);
    // GridData gd_grpPal = new GridData(SWT.LEFT, SWT.CENTER, false, false,
    // 1, 1);
    // gd_grpPal.widthHint = 223;
    // gd_grpPal.heightHint = 61;
    // grpPal.setLayoutData(gd_grpPal);
    //
    paletteTool = new PaletteTool(shell, grpPal, SWT.FLAT | SWT.RIGHT, activePalette);

    paletteTool.addListener(dmdWidget);

    Label lblCtrlclickToEdit = new Label(grpPalettes, SWT.NONE);
    GridData gd_lblCtrlclickToEdit = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
    gd_lblCtrlclickToEdit.widthHint = 139;
    lblCtrlclickToEdit.setLayoutData(gd_lblCtrlclickToEdit);
    lblCtrlclickToEdit.setText("Ctrl-Click to edit color");

    Composite composite_3 = new Composite(shell, SWT.NONE);
    GridLayout gl_composite_3 = new GridLayout(1, false);
    gl_composite_3.marginWidth = 0;
    gl_composite_3.marginHeight = 0;
    composite_3.setLayout(gl_composite_3);
    GridData gd_composite_3 = new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 2);
    gd_composite_3.heightHint = 190;
    gd_composite_3.widthHint = 338;
    composite_3.setLayoutData(gd_composite_3);
    goDmdGroup = new GoDmdGroup(composite_3);

    Group grpDrawing = new Group(shell, SWT.NONE);
    grpDrawing.setLayout(new GridLayout(6, false));
    GridData gd_grpDrawing = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
    gd_grpDrawing.heightHint = 63;
    gd_grpDrawing.widthHint = 479;
    grpDrawing.setLayoutData(gd_grpDrawing);
    grpDrawing.setText("Drawing");

    drawToolBar = new ToolBar(grpDrawing, SWT.FLAT | SWT.RIGHT);
    drawToolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));

    ToolItem tltmPen = new ToolItem(drawToolBar, SWT.RADIO);
    tltmPen.setImage(
            resManager.createImage(ImageDescriptor.createFromFile(PinDmdEditor.class, "/icons/pencil.png")));
    tltmPen.addListener(SWT.Selection, e -> dmdWidget.setDrawTool(drawTools.get("pencil")));

    ToolItem tltmFill = new ToolItem(drawToolBar, SWT.RADIO);
    tltmFill.setImage(resManager
            .createImage(ImageDescriptor.createFromFile(PinDmdEditor.class, "/icons/color-fill.png")));
    tltmFill.addListener(SWT.Selection, e -> dmdWidget.setDrawTool(drawTools.get("fill")));

    ToolItem tltmRect = new ToolItem(drawToolBar, SWT.RADIO);
    tltmRect.setImage(
            resManager.createImage(ImageDescriptor.createFromFile(PinDmdEditor.class, "/icons/rect.png")));
    tltmRect.addListener(SWT.Selection, e -> dmdWidget.setDrawTool(drawTools.get("rect")));

    ToolItem tltmLine = new ToolItem(drawToolBar, SWT.RADIO);
    tltmLine.setImage(
            resManager.createImage(ImageDescriptor.createFromFile(PinDmdEditor.class, "/icons/line.png")));
    tltmLine.addListener(SWT.Selection, e -> dmdWidget.setDrawTool(drawTools.get("line")));

    ToolItem tltmCircle = new ToolItem(drawToolBar, SWT.RADIO);
    tltmCircle.setImage(
            resManager.createImage(ImageDescriptor.createFromFile(PinDmdEditor.class, "/icons/oval.png")));
    tltmCircle.addListener(SWT.Selection, e -> dmdWidget.setDrawTool(drawTools.get("circle")));

    ToolItem tltmColorize = new ToolItem(drawToolBar, SWT.RADIO);
    tltmColorize.setImage(
            resManager.createImage(ImageDescriptor.createFromFile(PinDmdEditor.class, "/icons/colorize.png")));
    tltmColorize.addListener(SWT.Selection, e -> dmdWidget.setDrawTool(drawTools.get("colorize")));
    drawTools.put("pencil", new SetPixelTool(paletteTool.getSelectedColor()));
    drawTools.put("fill", new FloodFillTool(paletteTool.getSelectedColor()));
    drawTools.put("rect", new RectTool(paletteTool.getSelectedColor()));
    drawTools.put("line", new LineTool(paletteTool.getSelectedColor()));
    drawTools.put("circle", new CircleTool(paletteTool.getSelectedColor()));
    drawTools.put("colorize", new ColorizeTool(paletteTool.getSelectedColor()));
    drawTools.values().forEach(d -> paletteTool.addIndexListener(d));
    paletteTool.addListener(palette -> {
        if (livePreviewActive) {
            connector.upload(activePalette, handle);
        }
    });
    new Label(grpDrawing, SWT.NONE);

    btnColorMask = new Button(grpDrawing, SWT.CHECK);
    btnColorMask.setToolTipText("limits drawing to upper planes, so that this will just add coloring layers");
    btnColorMask.setText("ColMask");
    btnColorMask.addListener(SWT.Selection, e -> switchColorMask(btnColorMask.getSelection()));

    Label lblMaskNo = new Label(grpDrawing, SWT.NONE);
    lblMaskNo.setText("Mask No:");

    maskSpinner = new Spinner(grpDrawing, SWT.BORDER);
    maskSpinner.setToolTipText("select the mask to use");
    maskSpinner.setMinimum(0);
    maskSpinner.setMaximum(9);
    maskSpinner.addListener(SWT.Selection, e -> maskNumberChanged(e));

    btnMask = new Button(grpDrawing, SWT.CHECK);
    btnMask.setText("Show Mask");
    btnMask.addListener(SWT.Selection, e -> switchMask(btnMask.getSelection()));

    btnCopyToPrev = new Button(grpDrawing, SWT.NONE);
    btnCopyToPrev.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnCopyToPrev.setText("CopyToPrev");
    btnCopyToPrev.addListener(SWT.Selection, e -> copyAndMoveToPrevFrame());

    new Label(grpDrawing, SWT.NONE);

    btnCopyToNext = new Button(grpDrawing, SWT.NONE);
    btnCopyToNext.setToolTipText("copy the actual scene / color mask to next frame and move forward");
    btnCopyToNext.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    btnCopyToNext.setText("CopyToNext");
    btnCopyToNext.addListener(SWT.Selection, e -> copyAndMoveToNextFrame());

    btnUndo = new Button(grpDrawing, SWT.NONE);
    btnUndo.setText("&Undo");
    btnUndo.addListener(SWT.Selection, e -> undo());

    btnRedo = new Button(grpDrawing, SWT.NONE);
    btnRedo.setText("&Redo");
    btnRedo.addListener(SWT.Selection, e -> redo());

    ObserverManager.bind(maskDmdObserver, e -> btnUndo.setEnabled(e), () -> maskDmdObserver.canUndo());
    ObserverManager.bind(maskDmdObserver, e -> btnRedo.setEnabled(e), () -> maskDmdObserver.canRedo());

}

From source file:com.rinke.solutions.pinball.PinDmdEditor.java

void frameSeqChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    btnAddFrameSeq.setEnabled(selection.size() > 0);
    btnAddColormaskKeyFrame.setEnabled(selection.size() > 0);
}

From source file:com.rinke.solutions.pinball.PinDmdEditor.java

void keyFrameChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (selection.size() > 0) {
        if (((PalMapping) selection.getFirstElement()).equals(selectedPalMapping)) {
            keyframeTableViewer.setSelection(StructuredSelection.EMPTY);
            selectedPalMapping = null;//  w w  w  . j  ava2 s  .  com
            return;
        }
        // set new mapping
        selectedPalMapping = (PalMapping) selection.getFirstElement();

        log.debug("selected new palMapping {}", selectedPalMapping);

        selectedHashIndex = selectedPalMapping.hashIndex;

        // current firmware always checks with and w/o mask
        // btnMask.setSelection(selectedPalMapping.withMask);
        // btnMask.notifyListeners(SWT.Selection, new Event());

        txtDuration.setText(selectedPalMapping.durationInMillis + "");
        paletteComboViewer
                .setSelection(new StructuredSelection(project.palettes.get(selectedPalMapping.palIndex)));
        for (int j = 0; j < numberOfHashes; j++) {
            btnHash[j].setSelection(j == selectedHashIndex);
        }

        selectedAnimation = Optional.of(animations.get(selectedPalMapping.animationName));
        aniListViewer.setSelection(new StructuredSelection(selectedAnimation.get()));

        if (selectedPalMapping.frameSeqName != null)
            frameSeqViewer
                    .setSelection(new StructuredSelection(animations.get(selectedPalMapping.frameSeqName)));

        animationHandler.setPos(selectedPalMapping.frameIndex);

        if (selectedPalMapping.withMask) {
            String txt = btnHash[selectedHashIndex].getText();
            btnHash[selectedHashIndex].setText("M" + selectedPalMapping.maskNumber + " " + txt);
        }

        saveTimeCode = (int) selectedAnimation.get().getTimeCode(selectedPalMapping.frameIndex);
    } else {
        selectedPalMapping = null;
    }
    btnDeleteKeyframe.setEnabled(selection.size() > 0);
    btnFetchDuration.setEnabled(selection.size() > 0);
}

From source file:com.runwaysdk.manager.view.EditRelationshipAction.java

License:Open Source License

public void run() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();

    if (selection.size() != 1) {
        return;//from   w  w w  .j a  v  a 2s  . c  o m
    }

    BusinessObject component = (BusinessObject) selection.getFirstElement();

    List<RelationshipDAOIF> parents = strategy.getInverse(component, relationshipType);

    if (parents.size() > 0) {
        IEntityObject relationship = new RelationshipObject(parents.get(0));

        IAdminEvent event = new AdminEvent(IAdminEvent.EDIT);
        event.setData(IAdminEvent.OBJECT, relationship);

        module.edit(relationship, new ViewConfig());
    }
}

From source file:com.runwaysdk.manager.view.ObservableAction.java

License:Open Source License

public void run() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();

    if (selection.size() != 1) {
        return;//from   w  w  w  .  j  a  v  a  2s.  c  om
    }

    Object element = selection.getFirstElement();

    if (element instanceof IEntityObject) {
        strategy.execute(module, (IEntityObject) element);
    } else if (element instanceof EntityDAOIF) {
        strategy.execute(module, EntityObject.get((EntityDAOIF) element));
    }
}

From source file:com.runwaysdk.manager.view.TransactionRecordView.java

License:Open Source License

public void createPartControl(Composite parent) {
    form = new SashForm(parent, SWT.VERTICAL | SWT.FILL);

    super.createPartControl(form);

    IComponentObject item = SearchObject.newInstance(TransactionItemInfo.CLASS);

    this.table = new PaginatedTableView(item);

    table.createPartControl(form);/*w ww.ja v a  2  s  . c o m*/

    table.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            TableViewer viewer = table.getTableViewer();
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();

            if (selection.size() != 1) {
                return;
            }

            ComponentIF component = (ComponentIF) selection.getFirstElement();

            final IComponentObject item = EntityObject.get(component.getId());

            manager.openTab(new IViewStrategy() {
                public IViewPart getContent() {
                    return new DetailView(item);
                }

                public String getTitle() {
                    return item.getMdClassDAO().getDisplayLabel(Localizer.getLocale());
                }

                public String getKey() {
                    return item.getId();
                }

                @Override
                public boolean isClosable() {
                    return true;
                }
            });
        }
    });

    EntityQuery query = item.getQuery();
    query.WHERE(query.aReference(TransactionItemInfo.TRANSACTION_RECORD).EQ(getEntity().getId()));

    table.setInput(query);

    form.setWeights(new int[] { 5, 5, 1 });
}

From source file:com.runwaysdk.manager.view.TransactionResultView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    form = new SashForm(parent, SWT.VERTICAL | SWT.FILL);

    table.createPartControl(form);/*from  www  .  j  ava 2 s. c o  m*/

    table.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            TableViewer viewer = table.getTableViewer();

            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();

            if (selection.size() != 1) {
                return;
            }

            ComponentIF component = (ComponentIF) selection.getFirstElement();

            final IComponentObject record = EntityObject.get(component.getId());
            final Display display = viewer.getTable().getDisplay();

            manager.openTab(new IViewStrategy() {
                public IViewPart getContent() {
                    return new TransactionRecordView(record, display, manager, controller);
                }

                public String getTitle() {
                    return record.getMdClassDAO().getDisplayLabel(Localizer.getLocale());
                }

                public String getKey() {
                    return record.getId();
                }

                @Override
                public boolean isClosable() {
                    return true;
                }
            });
        }
    });

    table.setInput(entity.getQuery());

    form.setWeights(new int[] { 10, 1 });
}