Example usage for org.eclipse.jface.dialogs Dialog convertVerticalDLUsToPixels

List of usage examples for org.eclipse.jface.dialogs Dialog convertVerticalDLUsToPixels

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog convertVerticalDLUsToPixels.

Prototype

public static int convertVerticalDLUsToPixels(FontMetrics fontMetrics, int dlus) 

Source Link

Document

Returns the number of pixels corresponding to the given number of vertical dialog units.

Usage

From source file:com.microsoft.tfs.client.common.ui.editors.ConflictResolutionEditor.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);

    /* Compute metrics in pixels */
    final GC gc = new GC(composite);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();// www. j  a v a  2 s .com

    Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING);
    Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);
    final int marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_MARGIN);
    final int marginHeight = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_MARGIN);

    final GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    final Composite summaryComposite = new Composite(composite, SWT.NONE);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(summaryComposite);

    final GridLayout summaryLayout = new GridLayout(1, false);
    summaryLayout.horizontalSpacing = 0;
    summaryLayout.verticalSpacing = 0;
    summaryLayout.marginWidth = marginWidth;
    summaryLayout.marginHeight = marginHeight;
    summaryComposite.setLayout(summaryLayout);
    summaryComposite.setBackground(getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));

    summaryLabel = new Label(summaryComposite, SWT.NONE);
    summaryLabel.setBackground(getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    summaryLabel.setForeground(getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(summaryLabel);

    final Label separatorLabel = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(separatorLabel);

    final Composite toolbarComposite = new Composite(composite, SWT.NONE);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(toolbarComposite);

    final GridLayout toolbarCompositeLayout = new GridLayout(1, false);
    toolbarCompositeLayout.horizontalSpacing = 0;
    toolbarCompositeLayout.verticalSpacing = 0;
    toolbarCompositeLayout.marginWidth = marginWidth;
    toolbarCompositeLayout.marginHeight = 0;
    toolbarComposite.setLayout(toolbarCompositeLayout);

    toolbar = new ToolBar(toolbarComposite, SWT.HORIZONTAL | SWT.FLAT | SWT.RIGHT);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(toolbar);

    setupToolbar(toolbar);

    conflictTable = new ConflictTable(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    conflictTable.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            updateSelection();
        }
    });

    final MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            fillContextMenu(manager);
        }
    });
    conflictTable.setMenu(menuManager.createContextMenu(conflictTable));

    GridDataBuilder.newInstance().grab().fill().applyTo(conflictTable);

    getSite().setSelectionProvider(conflictTable);

    /*
     * Set up the resolution options control
     */

    conflictResolutionControl = new ConflictResolutionControl(composite, SWT.NONE);
    conflictResolutionControl.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent e) {
            conflictTable.setSelection(e.getSelection());
        }
    });
    conflictResolutionControl.addConflictResolutionSelectionListener(new ConflictResolutionSelectionListener() {
        @Override
        public void conflictResolutionSelected(final ConflictDescription[] conflictDescriptions,
                final ConflictResolution resolution) {
            if (conflictDescriptions.length == 1) {
                resolveConflict(conflictDescriptions[0], resolution);
            } else {
                resolveConflicts(conflictDescriptions, resolution);
            }
        }
    });
    conflictResolutionControl.addConflictResolutionCancelledListener(new ConflictResolutionCancelledListener() {
        @Override
        public void conflictResolutionCancelled(final ConflictDescription conflictDescription,
                final ConflictResolution resolution) {
            resolution.removeStatusListener(ConflictResolutionEditor.this);
            resolution.cancel();
        }
    });
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(conflictResolutionControl);

    setPartName(Messages.getString("ConflictResolutionEditor.PartName")); //$NON-NLS-1$

    if (needsPaint == true) {
        if (initialConflicts == null) {
            queryConflicts(null);
        } else {
            setConflictDescriptions(initialConflicts);
        }
    } else {
        updateSummary();
        updateSelection();
    }

    hasPainted = true;
}

From source file:com.microsoft.tfs.client.common.ui.editors.HistoryEditor.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);

    /* Compute metrics in pixels */
    final GC gc = new GC(composite);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();//w  w  w  .  j  a v  a  2s  .co m

    final int horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_SPACING);
    final int verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_SPACING);
    final int marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_MARGIN);
    final int marginHeight = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_MARGIN);

    final GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = horizontalSpacing;
    layout.verticalSpacing = verticalSpacing;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    final Composite locationComposite = new Composite(composite, SWT.NONE);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(locationComposite);

    final GridLayout locationLayout = new GridLayout(3, false);
    locationLayout.horizontalSpacing = horizontalSpacing;
    locationLayout.verticalSpacing = verticalSpacing;
    locationLayout.marginWidth = marginWidth;
    locationLayout.marginHeight = marginHeight;
    locationComposite.setLayout(locationLayout);

    final Label locationLabel = new Label(locationComposite, SWT.NONE);
    locationLabel.setText(Messages.getString("HistoryEditor.SourceLocationLabel")); //$NON-NLS-1$

    locationText = new Text(locationComposite, SWT.BORDER | SWT.READ_ONLY);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(locationText);

    final Button refreshButton = new Button(locationComposite, SWT.PUSH);

    /* Icons in buttons look good on Windows, strange elsewhere. */
    if (Platform.isCurrentPlatform(Platform.WINDOWS)) {
        refreshButton.setImage(
                imageHelper.getImage(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_REFRESH)));
    }

    refreshButton.setText(Messages.getString("HistoryEditor.RefreshActionText")); //$NON-NLS-1$
    GridDataBuilder.newInstance().applyTo(refreshButton);

    historyControl = new HistoryCombinedControl(composite, SWT.FULL_SELECTION | SWT.MULTI);
    GridDataBuilder.newInstance().grab().fill().hSpan(3).applyTo(historyControl);

    historyControl.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            updateStatusLine((IStructuredSelection) event.getSelection());
        }
    });

    getSite().setSelectionProvider(historyControl);

    createActions();

    // getEditorSite().getActionBars().setGlobalActionHandler(
    // ActionFactory.COPY.getId(),
    // historyControl.getCopyAction());
    // getEditorSite().getActionBars().updateActionBars();
    refreshButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            refresh();

        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            refresh();
        }
    });

    setPartName(Messages.getString("HistoryEditor.PartName")); //$NON-NLS-1$
    contributeActions();

    TFSCommonUIClientPlugin.getDefault().getProductPlugin().getRepositoryManager()
            .addListener(repositoryManagerListener);
}

From source file:com.microsoft.tfs.client.common.ui.framework.table.tooltip.TableTooltipManager.java

License:Open Source License

protected Point getTooltipSize(final Shell tooltipShell) {
    if (maxTooltipSize == null) {
        final GC gc = new GC(tooltipShell);

        final int max = Dialog.convertVerticalDLUsToPixels(gc.getFontMetrics(),
                IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
        maxTooltipSize = new Point(max, max);

        gc.dispose();//from   w  ww .ja v a  2s.c  om
    }

    Point tooltipSize = tooltipShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    if (tooltipSize.x > maxTooltipSize.x) {
        tooltipSize = tooltipShell.computeSize(maxTooltipSize.x, SWT.DEFAULT);
    }
    if (tooltipSize.y > maxTooltipSize.y) {
        tooltipSize = tooltipShell.computeSize(maxTooltipSize.x, maxTooltipSize.y);
    }

    return tooltipSize;
}

From source file:com.microsoft.tfs.client.common.ui.framework.wizard.BaseWizardPage.java

License:Open Source License

private final void computeMetrics() {
    Control control = getControl();

    if (control == null && Display.getCurrent() != null) {
        control = Display.getCurrent().getActiveShell();
    }//from   w w w .  j  a va2s  .c o m

    if (control == null) {
        return;
    }

    /* Compute metrics in pixels */
    final GC gc = new GC(control);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING);
    verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);

    spacing = Math.max(horizontalSpacing, verticalSpacing);

    horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN);
    verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);

    initializedMetrics = true;
}

From source file:com.microsoft.tfs.client.common.ui.prefs.BasePreferencePage.java

License:Open Source License

private void computeMetrics() {
    Control control = getControl();

    if (control == null && Display.getCurrent() != null) {
        control = Display.getCurrent().getActiveShell();
    }//from w  ww. j  a  v a2  s .  co  m

    if (control == null) {
        return;
    }

    /* Compute metrics in pixels */
    final GC gc = new GC(control);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING);
    verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);

    spacing = Math.max(horizontalSpacing, verticalSpacing);

    horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN);
    verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);
}

From source file:com.microsoft.tfs.client.common.ui.teambuild.editors.BuildEditorPage.java

License:Open Source License

private void createControls(final Composite composite) {
    final GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;/*  www .ja v  a  2s  .c  o  m*/
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    final Composite header = new Composite(composite, SWT.NONE);
    GridDataBuilder.newInstance().hFill().hGrab().applyTo(header);

    /* Compute metrics in pixels */
    final GC gc = new GC(header);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    final GridLayout headerLayout = new GridLayout(3, false);
    headerLayout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_SPACING);
    headerLayout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_SPACING);
    headerLayout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_MARGIN);
    headerLayout.marginHeight = Dialog.convertVerticalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_MARGIN);
    header.setLayout(headerLayout);

    SWTUtil.createLabel(header, Messages.getString("BuildEditorPage.BuildDefinitionLabelText")); //$NON-NLS-1$
    SWTUtil.createLabel(header, Messages.getString("BuildEditorPage.QualityFilterLabelText")); //$NON-NLS-1$
    SWTUtil.createLabel(header, Messages.getString("BuildEditorPage.DateFilterLabelText")); //$NON-NLS-1$

    buildDefinitionFilterCombo = new Combo(header, SWT.READ_ONLY);
    GridDataBuilder.newInstance().fill().hGrab().applyTo(buildDefinitionFilterCombo);

    qualityFilterCombo = new Combo(header, SWT.READ_ONLY);
    GridDataBuilder.newInstance().fill().applyTo(qualityFilterCombo);
    ControlSize.setCharWidthHint(qualityFilterCombo, 30);

    dateFilterCombo = new Combo(header, SWT.READ_ONLY);
    GridDataBuilder.newInstance().fill().applyTo(dateFilterCombo);
    ControlSize.setCharWidthHint(dateFilterCombo, 25);

    onlyMyBuildsCheck = new Button(header, SWT.CHECK);
    onlyMyBuildsCheck.setText(Messages.getString("BuildEditorPage.OnlyMyBuilds")); //$NON-NLS-1$
    onlyMyBuildsCheck.setEnabled(buildServer.getBuildServerVersion().isV3OrGreater());
    GridDataBuilder.newInstance().fill().hSpan(3).applyTo(onlyMyBuildsCheck);

    final Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(separator);

    buildsTableControl = new BuildsTableControl(composite,
            SWT.MULTI | SWT.FULL_SELECTION | TableControl.NO_BORDER, buildServer, teamProject);
    GridDataBuilder.newInstance().grab().fill().applyTo(buildsTableControl);

    buildsTableControl.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(final DoubleClickEvent event) {
            onDoubleClick(event);
        }
    });
    buildsTableControl.getContextMenu().addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            fillMenu(manager);
        }
    });

    // Add listener to be informed when build details are changed and our
    // copy might become stale. Remove the listener on dispose.
    BuildHelpers.getBuildManager().addBuildManagerListener(buildManagerListener);

    buildsTableControl.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(final DisposeEvent e) {
            BuildHelpers.getBuildManager().removeBuildManagerListener(buildManagerListener);
        }
    });

    populateCombos(false);

    buildDefinitionFilterCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            filterChanged();
        }
    });
    dateFilterCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            filterChanged();
        }
    });
    qualityFilterCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            filterChanged();
        }
    });
    onlyMyBuildsCheck.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            filterChanged();
        }
    });

    getSite().setSelectionProvider(this);

    if (buildServer.getBuildServerVersion().isV1()) {
        dateFilterCombo.setText(Messages.getString("BuildEditorPage.AnyTimeChoice")); //$NON-NLS-1$
        dateFilterCombo.setEnabled(false);
        qualityFilterCombo.setEnabled(false);
    }
}

From source file:com.microsoft.tfs.client.common.ui.teambuild.editors.QueueEditorPage.java

License:Open Source License

private void createControls(final Composite composite) {
    final GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;/*from w  w  w. j av  a2  s.  co  m*/
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    final Composite header = new Composite(composite, SWT.NONE);
    GridDataBuilder.newInstance().hFill().hGrab().applyTo(header);

    /* Compute metrics in pixels */
    final GC gc = new GC(header);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    final GridLayout headerLayout = new GridLayout(3, false);
    headerLayout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_SPACING);
    headerLayout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_SPACING);
    headerLayout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_MARGIN);
    headerLayout.marginHeight = Dialog.convertVerticalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_MARGIN);
    header.setLayout(headerLayout);

    SWTUtil.createLabel(header, Messages.getString("QueueEditorPage.BuildDefinitionLabelText")); //$NON-NLS-1$
    SWTUtil.createLabel(header, Messages.getString("QueueEditorPage.StatusFilterLabelText")); //$NON-NLS-1$
    SWTUtil.createLabel(header,
            buildServer.getBuildServerVersion().isV3OrGreater()
                    ? Messages.getString("QueueEditorPage.ControlFilterLabelText") //$NON-NLS-1$
                    : Messages.getString("QueueEditorPage.AgentFilterLabelText")); //$NON-NLS-1$

    buildDefinitionFilterCombo = new Combo(header, SWT.READ_ONLY);
    GridDataBuilder.newInstance().fill().hGrab().applyTo(buildDefinitionFilterCombo);

    statusFilterCombo = new Combo(header, SWT.READ_ONLY);
    GridDataBuilder.newInstance().fill().applyTo(statusFilterCombo);
    ControlSize.setCharWidthHint(statusFilterCombo, 25);

    controllerFilterCombo = new Combo(header, SWT.READ_ONLY);
    GridDataBuilder.newInstance().fill().applyTo(controllerFilterCombo);
    ControlSize.setCharWidthHint(controllerFilterCombo, 30);

    onlyMyBuildsCheck = new Button(header, SWT.CHECK);
    onlyMyBuildsCheck.setText(Messages.getString("BuildEditorPage.OnlyMyBuilds")); //$NON-NLS-1$
    onlyMyBuildsCheck.setEnabled(buildServer.getBuildServerVersion().isV3OrGreater());
    GridDataBuilder.newInstance().fill().hSpan(3).applyTo(onlyMyBuildsCheck);

    final Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(separator);

    queuedBuildsTable = new QueuedBuildsTableControl(composite,
            SWT.MULTI | SWT.FULL_SELECTION | TableControl.NO_BORDER, buildServer);
    GridDataBuilder.newInstance().hSpan(layout).grab().fill().applyTo(queuedBuildsTable);
    queuedBuildsTable.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(final DoubleClickEvent event) {
            onDoubleClick(event);
        }
    });
    queuedBuildsTable.getContextMenu().addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            fillMenu(manager);
        }
    });

    populateCombos(false);

    getSite().setSelectionProvider(this);

    buildDefinitionFilterCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            filterChanged();
        }
    });
    statusFilterCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            filterChanged();
        }
    });
    controllerFilterCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            filterChanged();
        }
    });
    onlyMyBuildsCheck.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            filterChanged();
        }
    });
}

From source file:com.microsoft.tfs.client.common.ui.vcexplorer.versioncontrol.FindInSourceControlEditor.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    final IEditorInput editorInput = getEditorInput();
    repository = getEditorInput().getRepository();

    setPartName(editorInput.getName());//from  w  w w  .j a va  2  s  .  c  o m
    setTitleToolTip(editorInput.getToolTipText());

    final Composite partComposite = new Composite(parent, SWT.NONE);

    final GridLayout layout = new GridLayout(1, true);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    partComposite.setLayout(layout);

    final Composite labelComposite = new Composite(partComposite, SWT.NONE);

    /* Compute metrics in pixels */
    final GC gc = new GC(labelComposite);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    final FillLayout labelCompositeLayout = new FillLayout();
    labelCompositeLayout.marginWidth = Dialog.convertVerticalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_MARGIN) / 2;
    labelCompositeLayout.marginHeight = Dialog.convertVerticalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_MARGIN) / 2;

    labelComposite.setLayout(labelCompositeLayout);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(labelComposite);

    resultsLabel = new Label(labelComposite, SWT.NONE);

    tableComposite = new Composite(partComposite, SWT.NONE);
    GridDataBuilder.newInstance().grab().fill().applyTo(tableComposite);

    tableStack = new StackLayout();
    tableComposite.setLayout(tableStack);

    pendingChangesTable = new FindInSourceControlPendingChangesTable(tableComposite,
            SWT.FULL_SELECTION | SWT.MULTI);

    createActions();

    menuManager = new MenuManager("menu"); //$NON-NLS-1$
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            fillContextMenu(manager);
        }
    });

    pendingChangesTable.getTable().setMenu(menuManager.createContextMenu(pendingChangesTable));

    /*
     * Proxy selection changes in both tables to listeners.
     */
    final ISelectionChangedListener selectionChangedListener = new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            ((ISelectionChangedListener) selectionChangedListeners.getListener()).selectionChanged(event);
        }
    };

    pendingChangesTable.addSelectionChangedListener(selectionChangedListener);

    pendingChangesTable.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(final DoubleClickEvent event) {
            openInSCEAction.run();
        }

    });

    TFSCommonUIClientPlugin.getDefault().getProductPlugin().getRepositoryManager()
            .addListener(repositoryManagerListener);

}

From source file:com.microsoft.tfs.client.common.ui.views.DeprecatedByTeamExplorerView.java

License:Open Source License

@Override
public final void createPartControl(final Composite parent) {
    /* Compute metrics in pixels */
    final GC gc = new GC(parent);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();/*from w w  w.  ja  v  a  2  s  . c  om*/

    final GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_SPACING) * 2;
    layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);
    layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN);
    layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);
    parent.setLayout(layout);

    final Label imageLabel = new Label(parent, SWT.NONE);
    imageLabel.setImage(Display.getCurrent().getSystemImage(SWT.ICON_INFORMATION));

    final Link textLabel = new Link(parent, SWT.READ_ONLY | SWT.WRAP);
    textLabel.setText(Messages.getString("DeprecatedByTeamExplorerView.DeprecatedText")); //$NON-NLS-1$
    textLabel.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            try {
                final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                        .getActivePage();
                page.showView(TeamExplorerView.ID);
            } catch (final Exception f) {
                log.warn("Could not open Team Explorer View", f); //$NON-NLS-1$

                MessageDialog.openError(getSite().getShell(),
                        Messages.getString("DeprecatedByTeamExplorerView.OpenViewFailedTitle"), //$NON-NLS-1$
                        Messages.getString("DeprecatedByTeamExplorerView.OpenViewFailedMessage")); //$NON-NLS-1$
            }
        }
    });
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(textLabel);
}

From source file:com.nokia.carbide.remoteconnections.internal.ui.ClientServiceSiteUI2.java

License:Open Source License

public void createComposite(Composite parent) {
    initializeDialogUnits(parent);/*from  ww  w.j  a  va2 s.c  om*/
    Group group = new Group(parent, SWT.NONE);
    group.setText(Messages.getString("ClientServiceSiteUI2.UseConnectionGroupLabel")); //$NON-NLS-1$
    group.setLayout(new GridLayout());
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$

    viewer = new ComboViewer(group, SWT.READ_ONLY);
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Check.checkContract(element instanceof String);
            String id = (String) element;
            return connectionNames.get(id);
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    viewer.getCombo().setLayoutData(gd);
    viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            String connection = (String) selection.getFirstElement();
            if (connection != null && !connection.equals(ClientServiceSiteUI2.this.connection)) {
                ClientServiceSiteUI2.this.connection = connection;
                fireConnectionSelected();
            }
        }
    });

    final Composite composite = new Composite(group, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
    layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
    layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
    layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
    composite.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER);
    composite.setLayoutData(gd);
    composite.setFont(parent.getFont());

    newButton = new Button(composite, SWT.PUSH);
    newButton.setText(Messages.getString("ClientServiceSiteUI2.NewButtonLabel")); //$NON-NLS-1$
    newButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    newButton.setLayoutData(gd);
    newButton.setData(UID, "newButton"); //$NON-NLS-1$
    newButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SettingsWizard wizard = new SettingsWizard(null, service);
            wizard.open(composite.getShell());
            IConnection connection = wizard.getConnectionToEdit();
            // note: refresh ASAP so the selection will be valid; but endure a listener event
            // which will redo this
            refreshUI();
            setViewerInput(connection);
        }
    });

    editButton = new Button(composite, SWT.PUSH);
    editButton.setText(Messages.getString("ClientServiceSiteUI2.EditButtonLabel")); //$NON-NLS-1$
    editButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    editButton.setLayoutData(gd);
    editButton.setData(UID, "editButton"); //$NON-NLS-1$
    editButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object value = selection.getFirstElement();
            if (value instanceof String) {
                IConnection editConnection = getActualConnection((String) value);
                SettingsWizard wizard = new SettingsWizard(editConnection, service);
                wizard.open(composite.getShell());

                // leave the viewer the same, callback will refresh anything needed
            }
        }
    });

    // attach listeners
    RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(this);
    RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(this);

    // remove listeners on dispose
    group.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            RemoteConnectionsActivator.getConnectionsManager()
                    .removeConnectionListener(ClientServiceSiteUI2.this);
            RemoteConnectionsActivator.getConnectionsManager()
                    .removeConnectionStoreChangedListener(ClientServiceSiteUI2.this);
        }
    });

    setViewerInput(null);
}