Search in sources :

Example 1 with PixelConverter

use of org.eclipse.jface.layout.PixelConverter in project ow by vtst.

the class SWTFactory method getButtonWidthHint.

/**
   * Returns a width hint for a button control.
   */
public static int getButtonWidthHint(Button button) {
    button.setFont(JFaceResources.getDialogFont());
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}
Also used : PixelConverter(org.eclipse.jface.layout.PixelConverter)

Example 2 with PixelConverter

use of org.eclipse.jface.layout.PixelConverter in project bndtools by bndtools.

the class SWTUtil method getButtonWidthHint.

// Shamelessly stolen from JDT
public static int getButtonWidthHint(Button button) {
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}
Also used : PixelConverter(org.eclipse.jface.layout.PixelConverter)

Example 3 with PixelConverter

use of org.eclipse.jface.layout.PixelConverter in project translationstudio8 by heartsome.

the class SelectGrantFileDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 10;
    layout.marginTop = 10;
    tparent.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tparent);
    Composite compNav = new Composite(tparent, SWT.NONE);
    GridLayout navLayout = new GridLayout();
    compNav.setLayout(navLayout);
    createNavigation(compNav);
    Group groupFile = new Group(tparent, SWT.NONE);
    groupFile.setText(Messages.getString("license.SelectGrantFileDialog.grantfile"));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(groupFile);
    GridLayout layoutGroup = new GridLayout(3, false);
    layoutGroup.marginWidth = 5;
    layoutGroup.marginHeight = 100;
    groupFile.setLayout(layoutGroup);
    Label label = new Label(groupFile, SWT.NONE);
    label.setText(Messages.getString("license.SelectGrantFileDialog.grantfile1"));
    textPath = new Text(groupFile, SWT.BORDER);
    textPath.setEditable(false);
    GridData pathData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    pathData.widthHint = new PixelConverter(textPath).convertWidthInCharsToPixels(25);
    textPath.setLayoutData(pathData);
    // browse button
    btnScan = new Button(groupFile, SWT.PUSH);
    btnScan.setText(Messages.getString("license.SelectGrantFileDialog.scan"));
    setButtonLayoutData(btnScan);
    btnScan.addSelectionListener(new SelectionAdapter() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse .swt.events.SelectionEvent)
			 */
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(textPath.getShell(), SWT.SHEET);
            dialog.setFilterExtensions(FILE_IMPORT_MASK);
            dialog.setText(Messages.getString("license.SelectGrantFileDialog.selectgrantfile"));
            String fileName = textPath.getText().trim();
            if (fileName.length() != 0) {
                File path = new File(fileName).getParentFile();
                if (path != null && path.exists()) {
                    dialog.setFilterPath(path.toString());
                }
            }
            String path = dialog.open();
            if (path != null) {
                textPath.setText(path);
            }
        }
    });
    return tparent;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 4 with PixelConverter

use of org.eclipse.jface.layout.PixelConverter in project translationstudio8 by heartsome.

the class ImportProjectWizardPage method createProjectsList.

/**
	 * Create the checkbox list for the found projects.
	 * 
	 * @param workArea
	 */
private void createProjectsList(Composite workArea) {
    Label title = new Label(workArea, SWT.NONE);
    title.setText(DataTransferMessages.WizardProjectsImportPage_ProjectsListTitle);
    Composite listComposite = new Composite(workArea, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 0;
    layout.makeColumnsEqualWidth = false;
    listComposite.setLayout(layout);
    listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
    projectsList = new CheckboxTreeViewer(listComposite, SWT.BORDER);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.widthHint = new PixelConverter(projectsList.getControl()).convertWidthInCharsToPixels(25);
    gridData.heightHint = new PixelConverter(projectsList.getControl()).convertHeightInCharsToPixels(10);
    projectsList.getControl().setLayoutData(gridData);
    projectsList.setContentProvider(new ITreeContentProvider() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java
			 * .lang.Object)
			 */
        public Object[] getChildren(Object parentElement) {
            return null;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.IStructuredContentProvider#getElements
			 * (java.lang.Object)
			 */
        public Object[] getElements(Object inputElement) {
            return getProjectRecords();
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java
			 * .lang.Object)
			 */
        public boolean hasChildren(Object element) {
            return false;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java
			 * .lang.Object)
			 */
        public Object getParent(Object element) {
            return null;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
			 */
        public void dispose() {
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
			 * .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
			 */
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    projectsList.setLabelProvider(new ProjectLabelProvider());
    projectsList.addCheckStateListener(new ICheckStateListener() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
			 * (org.eclipse.jface.viewers.CheckStateChangedEvent)
			 */
        public void checkStateChanged(CheckStateChangedEvent event) {
            ProjectRecord element = (ProjectRecord) event.getElement();
            if (element.hasConflicts) {
                projectsList.setChecked(element, false);
            }
            setPageComplete(projectsList.getCheckedElements().length > 0);
        }
    });
    projectsList.setInput(this);
    projectsList.setComparator(new ViewerComparator());
    createSelectionButtons(listComposite);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Composite(org.eclipse.swt.widgets.Composite) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 5 with PixelConverter

use of org.eclipse.jface.layout.PixelConverter in project translationstudio8 by heartsome.

the class ImportProjectWizardPage method createProjectsRoot.

/**
	 * Create the area where you select the root directory for the projects.
	 * 
	 * @param workArea
	 * 		Composite
	 */
private void createProjectsRoot(Composite workArea) {
    // project specification group
    Composite projectGroup = new Composite(workArea, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.makeColumnsEqualWidth = false;
    layout.marginWidth = 0;
    projectGroup.setLayout(layout);
    projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // new project from archive radio button
    projectFromArchiveRadio = new Label(projectGroup, SWT.None);
    projectFromArchiveRadio.setText(DataTransferMessages.WizardProjectsImportPage_ArchiveSelectTitle);
    // project location entry field
    archivePathField = new Text(projectGroup, SWT.BORDER);
    GridData archivePathData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    archivePathData.widthHint = new PixelConverter(archivePathField).convertWidthInCharsToPixels(25);
    // browse button
    archivePathField.setLayoutData(archivePathData);
    browseArchivesButton = new Button(projectGroup, SWT.PUSH);
    browseArchivesButton.setText(DataTransferMessages.DataTransfer_browse);
    setButtonLayoutData(browseArchivesButton);
    browseArchivesButton.addSelectionListener(new SelectionAdapter() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
			 * .swt.events.SelectionEvent)
			 */
        public void widgetSelected(SelectionEvent e) {
            handleLocationArchiveButtonPressed();
        }
    });
    archivePathField.addTraverseListener(new TraverseListener() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse
			 * .swt.events.TraverseEvent)
			 */
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
                e.doit = false;
                updateProjectsList(archivePathField.getText().trim());
            }
        }
    });
    archivePathField.addFocusListener(new FocusAdapter() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
			 * .events.FocusEvent)
			 */
        public void focusLost(org.eclipse.swt.events.FocusEvent e) {
            updateProjectsList(archivePathField.getText().trim());
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) TraverseEvent(org.eclipse.swt.events.TraverseEvent) Composite(org.eclipse.swt.widgets.Composite) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

PixelConverter (org.eclipse.jface.layout.PixelConverter)6 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Button (org.eclipse.swt.widgets.Button)2 Text (org.eclipse.swt.widgets.Text)2 File (java.io.File)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 FocusAdapter (org.eclipse.swt.events.FocusAdapter)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1