Example usage for org.eclipse.jface.preference IPreferenceStore contains

List of usage examples for org.eclipse.jface.preference IPreferenceStore contains

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferenceStore contains.

Prototype

boolean contains(String name);

Source Link

Document

Returns whether the named preference is known to this preference store.

Usage

From source file:ca.uvic.chisel.javasketch.ui.internal.views.TraceNavigator.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    viewer.setUseHashlookup(true);//  w  ww.  java2s .c  om
    // TreeViewerColumn plusColumn = new TreeViewerColumn(viewer, SWT.NONE,
    // 0);
    // plusColumn.getColumn().setWidth(60);
    final TreeViewerColumn labelColumn = new TreeViewerColumn(viewer, SWT.NONE, LABEL_COLUMN);
    labelColumn.getColumn().setWidth(100);
    TreeViewerColumn activeTraceColumn = new TreeViewerColumn(viewer, SWT.NONE, ACTIVE_TRACE_COLUMN);
    activeTraceColumn.getColumn().setWidth(16);
    TreeViewerColumn visibleTraceColumn = new TreeViewerColumn(viewer, SWT.NONE, VISIBLE_TRACE_COLUMN);
    visibleTraceColumn.getColumn().setWidth(16);
    viewer.getTree().addMouseListener(treeMouseListener);

    viewer.getTree().addControlListener(new ControlAdapter() {
        /*
         * (non-Javadoc)
         * @see
         * org.eclipse.swt.events.ControlAdapter#controlResized(org.eclipse
         * .swt.events.ControlEvent)
         */
        @Override
        public void controlResized(ControlEvent e) {
            Composite composite = (Composite) e.widget;
            Rectangle b = composite.getBounds();
            ScrollBar scrollbar = composite.getVerticalBar();
            int width = b.width - 32;
            if (scrollbar != null && scrollbar.getVisible()) {
                width -= 20;
            }
            labelColumn.getColumn().setWidth(Math.max(0, width));
        }
    });
    viewer.setContentProvider(new TraceNavigatorContentProvider());
    viewer.setLabelProvider(new TraceNavigatorLabelProvider());
    viewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Object o = selection.getFirstElement();
            if (o instanceof IThread) {
                SketchPlugin.getDefault().getDOI().setThreadSelection((IThread) o);
            } else {
                SketchPlugin.getDefault().getDOI().setThreadSelection(null);
            }
            SketchUI.INSTANCE.refreshJavaUI();
        }
    });
    createContextMenu(viewer.getControl());
    getSite().setSelectionProvider(viewer);
    IMenuManager manager = getViewSite().getActionBars().getMenuManager();
    Action toggleFilterAction = new Action("Filter Empty Threads", SWT.CHECK) {
        /* (non-Javadoc)
         * @see org.eclipse.jface.action.Action#run()
         */
        @Override
        public void run() {
            IPreferenceStore store = SketchPlugin.getDefault().getPreferenceStore();
            boolean checked = store.getBoolean("tracenavigator.filter.emptythread");
            if (checked) {
                //uncheck
                viewer.removeFilter(threadFilter);
            } else {
                viewer.addFilter(threadFilter);
            }
            store.setValue("tracenavigator.filter.emptythread", !checked);
            viewer.refresh();
        }
    };
    IPreferenceStore store = SketchPlugin.getDefault().getPreferenceStore();
    boolean checked = true;
    if (!store.contains("tracenavigator.filter.emptythread")) {
        store.setValue("tracenavigator.filter.emptythread", true);
    } else {
        checked = store.getBoolean("tracenavigator.filter.emptythread");
    }
    toggleFilterAction.setChecked(checked);
    if (checked) {
        viewer.addFilter(threadFilter);
    }
    manager.add(toggleFilterAction);
}

From source file:ca.uvic.cs.tagsea.preferences.TagSEAPreferences.java

License:Open Source License

/**
 * Gets the width for the key.  If the value isn't set in the preferences
 * then the default value is returned.  
 * @param key/*  w  ww . j  ava  2 s  .  co m*/
 * @return int the width
 */
private static int getWidth(String key) {
    IPreferenceStore store = getPreferenceStore();
    if (store.contains(key)) {
        return store.getInt(key);
    } else {
        return store.getDefaultInt(key);
    }
}

From source file:ccw.editors.clojure.ClojureSourceViewer.java

License:Open Source License

static public RGB getRGBColor(IPreferenceStore store, String key) {
    RGB rgb = null;/* w w w.  ja v  a2s .co m*/

    if (store.contains(key)) {
        if (store.isDefault(key))
            rgb = PreferenceConverter.getDefaultColor(store, key);
        else
            rgb = PreferenceConverter.getColor(store, key);
    }

    return rgb;
}

From source file:com.amazonaws.eclipse.dynamodb.testtool.StartTestToolConfigurationWizardPage.java

License:Apache License

/**
 * Create the wizard page's controls./*from  w ww  . j a  va2  s.  c  om*/
 *
 * @param parent    the parent composite to hang the controls on
 */
public void createControl(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
    composite.setLayout(new GridLayout(2, false));

    Label label = new Label(composite, SWT.NONE);
    label.setText("Port: ");

    portInput = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(portInput);

    // TODO: Would be nice to drive this off of the manifest.xml for the
    // chosen version, in case future versions of the test tool support
    // additional options.

    bindInputs();

    IPreferenceStore preferences = DynamoDBPlugin.getDefault().getPreferenceStore();

    if (preferences.contains(TestToolPreferencePage.DEFAULT_PORT_PREFERENCE_NAME)) {

        portValue.setValue(
                Integer.toString(preferences.getInt(TestToolPreferencePage.DEFAULT_PORT_PREFERENCE_NAME)));
        context.updateTargets();
    }

    setControl(composite);
}

From source file:com.android.ddmuilib.AllocationPanel.java

License:Apache License

/**
 * Create our control(s).//from   ww  w.ja v  a  2 s .  c om
 */
@Override
protected Control createControl(Composite parent) {
    final IPreferenceStore store = DdmUiPreferences.getStore();

    Display display = parent.getDisplay();

    // get some images
    mSortUpImg = ImageLoader.getDdmUiLibLoader().loadImage("sort_up.png", display);
    mSortDownImg = ImageLoader.getDdmUiLibLoader().loadImage("sort_down.png", display);

    // base composite for selected client with enabled thread update.
    mAllocationBase = new Composite(parent, SWT.NONE);
    mAllocationBase.setLayout(new FormLayout());

    // table above the sash
    Composite topParent = new Composite(mAllocationBase, SWT.NONE);
    topParent.setLayout(new GridLayout(6, false));

    mEnableButton = new Button(topParent, SWT.PUSH);
    mEnableButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Client current = getCurrentClient();
            AllocationTrackingStatus status = current.getClientData().getAllocationStatus();
            if (status == AllocationTrackingStatus.ON) {
                current.enableAllocationTracker(false);
            } else {
                current.enableAllocationTracker(true);
            }
            current.requestAllocationStatus();
        }
    });

    mRequestButton = new Button(topParent, SWT.PUSH);
    mRequestButton.setText("Get Allocations");
    mRequestButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            getCurrentClient().requestAllocationDetails();
        }
    });

    setUpButtons(false /* enabled */, AllocationTrackingStatus.OFF);

    GridData gridData;

    Composite spacer = new Composite(topParent, SWT.NONE);
    spacer.setLayoutData(gridData = new GridData(GridData.FILL_HORIZONTAL));

    new Label(topParent, SWT.NONE).setText("Filter:");

    final Text filterText = new Text(topParent, SWT.BORDER);
    filterText.setLayoutData(gridData = new GridData(GridData.FILL_HORIZONTAL));
    gridData.widthHint = 200;

    filterText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent arg0) {
            mFilterText = filterText.getText().trim();
            mAllocationViewer.refresh();
        }
    });

    mTraceFilterCheck = new Button(topParent, SWT.CHECK);
    mTraceFilterCheck.setText("Inc. trace");
    mTraceFilterCheck.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            mAllocationViewer.refresh();
        }
    });

    mAllocationTable = new Table(topParent, SWT.MULTI | SWT.FULL_SELECTION);
    mAllocationTable.setLayoutData(gridData = new GridData(GridData.FILL_BOTH));
    gridData.horizontalSpan = 6;
    mAllocationTable.setHeaderVisible(true);
    mAllocationTable.setLinesVisible(true);

    final TableColumn numberCol = TableHelper.createTableColumn(mAllocationTable, "Alloc Order", SWT.RIGHT,
            "Alloc Order", //$NON-NLS-1$
            PREFS_ALLOC_COL_NUMBER, store);
    numberCol.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            setSortColumn(numberCol, SortMode.NUMBER);
        }
    });

    final TableColumn sizeCol = TableHelper.createTableColumn(mAllocationTable, "Allocation Size", SWT.RIGHT,
            "888", //$NON-NLS-1$
            PREFS_ALLOC_COL_SIZE, store);
    sizeCol.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            setSortColumn(sizeCol, SortMode.SIZE);
        }
    });

    final TableColumn classCol = TableHelper.createTableColumn(mAllocationTable, "Allocated Class", SWT.LEFT,
            "Allocated Class", //$NON-NLS-1$
            PREFS_ALLOC_COL_CLASS, store);
    classCol.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            setSortColumn(classCol, SortMode.CLASS);
        }
    });

    final TableColumn threadCol = TableHelper.createTableColumn(mAllocationTable, "Thread Id", SWT.LEFT, "999", //$NON-NLS-2$
            PREFS_ALLOC_COL_THREAD, store);
    threadCol.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            setSortColumn(threadCol, SortMode.THREAD);
        }
    });

    final TableColumn inClassCol = TableHelper.createTableColumn(mAllocationTable, "Allocated in", SWT.LEFT,
            "utime", //$NON-NLS-1$
            PREFS_ALLOC_COL_TRACE_CLASS, store);
    inClassCol.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            setSortColumn(inClassCol, SortMode.IN_CLASS);
        }
    });

    final TableColumn inMethodCol = TableHelper.createTableColumn(mAllocationTable, "Allocated in", SWT.LEFT,
            "utime", //$NON-NLS-1$
            PREFS_ALLOC_COL_TRACE_METHOD, store);
    inMethodCol.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            setSortColumn(inMethodCol, SortMode.IN_METHOD);
        }
    });

    // init the default sort colum
    switch (mSorter.getSortMode()) {
    case SIZE:
        mSortColumn = sizeCol;
        break;
    case CLASS:
        mSortColumn = classCol;
        break;
    case THREAD:
        mSortColumn = threadCol;
        break;
    case IN_CLASS:
        mSortColumn = inClassCol;
        break;
    case IN_METHOD:
        mSortColumn = inMethodCol;
        break;
    }

    mSortColumn.setImage(mSorter.isDescending() ? mSortDownImg : mSortUpImg);

    mAllocationViewer = new TableViewer(mAllocationTable);
    mAllocationViewer.setContentProvider(new AllocationContentProvider());
    mAllocationViewer.setLabelProvider(new AllocationLabelProvider());

    mAllocationViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            AllocationInfo selectedAlloc = getAllocationSelection(event.getSelection());
            updateAllocationStackTrace(selectedAlloc);
        }
    });

    // the separating sash
    final Sash sash = new Sash(mAllocationBase, SWT.HORIZONTAL);
    Color darkGray = parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
    sash.setBackground(darkGray);

    // the UI below the sash
    mStackTracePanel = new StackTracePanel();
    mStackTraceTable = mStackTracePanel.createPanel(mAllocationBase, PREFS_STACK_COLUMN, store);

    // now setup the sash.
    // form layout data
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(sash, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    topParent.setLayoutData(data);

    final FormData sashData = new FormData();
    if (store != null && store.contains(PREFS_ALLOC_SASH)) {
        sashData.top = new FormAttachment(0, store.getInt(PREFS_ALLOC_SASH));
    } else {
        sashData.top = new FormAttachment(50, 0); // 50% across
    }
    sashData.left = new FormAttachment(0, 0);
    sashData.right = new FormAttachment(100, 0);
    sash.setLayoutData(sashData);

    data = new FormData();
    data.top = new FormAttachment(sash, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    mStackTraceTable.setLayoutData(data);

    // allow resizes, but cap at minPanelWidth
    sash.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            Rectangle sashRect = sash.getBounds();
            Rectangle panelRect = mAllocationBase.getClientArea();
            int bottom = panelRect.height - sashRect.height - 100;
            e.y = Math.max(Math.min(e.y, bottom), 100);
            if (e.y != sashRect.y) {
                sashData.top = new FormAttachment(0, e.y);
                store.setValue(PREFS_ALLOC_SASH, e.y);
                mAllocationBase.layout();
            }
        }
    });

    return mAllocationBase;
}

From source file:com.android.ddmuilib.NativeHeapPanel.java

License:Apache License

/**
 * Create the Table display. This includes a "detail" Table in the bottom
 * half and 2 modes in the top half: allocation Table and
 * library+allocations Tables.//from   ww  w  .  j a va  2  s .  c  o m
 *
 * @param base the top parent to create the display into
 */
private void createTableDisplay(Composite base) {
    final int minPanelWidth = 60;

    final IPreferenceStore prefs = DdmUiPreferences.getStore();

    // top level composite for mode 1 & 2
    mTableModeControl = new Composite(base, SWT.NONE);
    GridLayout gl = new GridLayout(1, false);
    gl.marginLeft = gl.marginRight = gl.marginTop = gl.marginBottom = 0;
    mTableModeControl.setLayout(gl);
    mTableModeControl.setLayoutData(new GridData(GridData.FILL_BOTH));

    mTotalMemoryLabel = new Label(mTableModeControl, SWT.NONE);
    mTotalMemoryLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    mTotalMemoryLabel.setText("Total Memory: 0 Bytes");

    // the top half of these modes is dynamic

    final Composite sash_composite = new Composite(mTableModeControl, SWT.NONE);
    sash_composite.setLayout(new FormLayout());
    sash_composite.setLayoutData(new GridData(GridData.FILL_BOTH));

    // create the stacked composite
    mAllocationStackComposite = new Composite(sash_composite, SWT.NONE);
    mAllocationStackLayout = new StackLayout();
    mAllocationStackComposite.setLayout(mAllocationStackLayout);
    mAllocationStackComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

    // create the top half for mode 1
    createAllocationTopHalf(mAllocationStackComposite);

    // create the top half for mode 2
    createLibraryTopHalf(mAllocationStackComposite);

    final Sash sash = new Sash(sash_composite, SWT.HORIZONTAL);

    // bottom half of these modes is the same: detail table
    createDetailTable(sash_composite);

    // init value for stack
    mAllocationStackLayout.topControl = mAllocationModeTop;

    // form layout data
    FormData data = new FormData();
    data.top = new FormAttachment(mTotalMemoryLabel, 0);
    data.bottom = new FormAttachment(sash, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    mAllocationStackComposite.setLayoutData(data);

    final FormData sashData = new FormData();
    if (prefs != null && prefs.contains(PREFS_ALLOCATION_SASH)) {
        sashData.top = new FormAttachment(0, prefs.getInt(PREFS_ALLOCATION_SASH));
    } else {
        sashData.top = new FormAttachment(50, 0); // 50% across
    }
    sashData.left = new FormAttachment(0, 0);
    sashData.right = new FormAttachment(100, 0);
    sash.setLayoutData(sashData);

    data = new FormData();
    data.top = new FormAttachment(sash, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    mDetailTable.setLayoutData(data);

    // allow resizes, but cap at minPanelWidth
    sash.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            Rectangle sashRect = sash.getBounds();
            Rectangle panelRect = sash_composite.getClientArea();
            int bottom = panelRect.height - sashRect.height - minPanelWidth;
            e.y = Math.max(Math.min(e.y, bottom), minPanelWidth);
            if (e.y != sashRect.y) {
                sashData.top = new FormAttachment(0, e.y);
                prefs.setValue(PREFS_ALLOCATION_SASH, e.y);
                sash_composite.layout();
            }
        }
    });
}

From source file:com.android.ddmuilib.NativeHeapPanel.java

License:Apache License

private void createLibraryTopHalf(Composite base) {
    final int minPanelWidth = 60;

    final IPreferenceStore prefs = DdmUiPreferences.getStore();

    // create a composite that'll contain 2 tables horizontally
    final Composite top = new Composite(base, SWT.NONE);
    mLibraryModeTopControl = top;/*from w  w  w.j a va2s .  c o  m*/
    top.setLayout(new FormLayout());
    top.setLayoutData(new GridData(GridData.FILL_BOTH));

    // first table: library
    mLibraryTable = new Table(top, SWT.MULTI | SWT.FULL_SELECTION);
    mLibraryTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    mLibraryTable.setHeaderVisible(true);
    mLibraryTable.setLinesVisible(true);

    TableHelper.createTableColumn(mLibraryTable, "Library", SWT.LEFT, "abcdefghijklmnopqrstuvwxyz", //$NON-NLS-2$
            PREFS_LIB_LIBRARY, prefs);
    TableHelper.createTableColumn(mLibraryTable, "Size", SWT.RIGHT, "9,999,999", PREFS_LIB_SIZE, prefs); //$NON-NLS-2$
    TableHelper.createTableColumn(mLibraryTable, "Count", SWT.RIGHT, "9,999", PREFS_LIB_COUNT, prefs); //$NON-NLS-2$

    mLibraryTable.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            fillLibraryAllocationTable();
        }
    });

    final Sash sash = new Sash(top, SWT.VERTICAL);

    // 2nd table: allocation per library
    mLibraryAllocationTable = new Table(top, SWT.MULTI | SWT.FULL_SELECTION);
    mLibraryAllocationTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    mLibraryAllocationTable.setHeaderVisible(true);
    mLibraryAllocationTable.setLinesVisible(true);

    TableHelper.createTableColumn(mLibraryAllocationTable, "Total", SWT.RIGHT, "9,999,999", //$NON-NLS-2$
            PREFS_LIBALLOC_TOTAL, prefs);
    TableHelper.createTableColumn(mLibraryAllocationTable, "Count", SWT.RIGHT, "9,999", PREFS_LIBALLOC_COUNT, //$NON-NLS-2$
            prefs);
    TableHelper.createTableColumn(mLibraryAllocationTable, "Size", SWT.RIGHT, "999,999", PREFS_LIBALLOC_SIZE, //$NON-NLS-2$
            prefs);
    TableHelper.createTableColumn(mLibraryAllocationTable, "Method", SWT.LEFT, "abcdefghijklmnopqrst", //$NON-NLS-2$
            PREFS_LIBALLOC_METHOD, prefs);

    mLibraryAllocationTable.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // get the index of the selection in the library table
            int index1 = mLibraryTable.getSelectionIndex();
            // get the index in the library allocation table
            int index2 = mLibraryAllocationTable.getSelectionIndex();
            // get the MallocInfo object
            if (index1 != -1 && index2 != -1) {
                LibraryAllocations liballoc = mLibraryAllocations.get(index1);
                NativeAllocationInfo info = liballoc.getAllocation(index2);
                fillDetailTable(info);
            }
        }
    });

    // form layout data
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(sash, 0);
    mLibraryTable.setLayoutData(data);

    final FormData sashData = new FormData();
    if (prefs != null && prefs.contains(PREFS_LIBRARY_SASH)) {
        sashData.left = new FormAttachment(0, prefs.getInt(PREFS_LIBRARY_SASH));
    } else {
        sashData.left = new FormAttachment(50, 0);
    }
    sashData.bottom = new FormAttachment(100, 0);
    sashData.top = new FormAttachment(0, 0); // 50% across
    sash.setLayoutData(sashData);

    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(sash, 0);
    data.right = new FormAttachment(100, 0);
    mLibraryAllocationTable.setLayoutData(data);

    // allow resizes, but cap at minPanelWidth
    sash.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            Rectangle sashRect = sash.getBounds();
            Rectangle panelRect = top.getClientArea();
            int right = panelRect.width - sashRect.width - minPanelWidth;
            e.x = Math.max(Math.min(e.x, right), minPanelWidth);
            if (e.x != sashRect.x) {
                sashData.left = new FormAttachment(0, e.x);
                prefs.setValue(PREFS_LIBRARY_SASH, e.y);
                top.layout();
            }
        }
    });
}

From source file:com.android.ddmuilib.TableHelper.java

License:Apache License

/**
 * Create a TableColumn with the specified parameters. If a
 * <code>PreferenceStore</code> object and a preference entry name String
 * object are provided then the column will listen to change in its width
 * and update the preference store accordingly.
 *
 * @param parent The Table parent object
 * @param header The header string/*from ww w  .j av  a  2  s. com*/
 * @param style The column style
 * @param sample_text A sample text to figure out column width if preference
 *            value is missing
 * @param pref_name The preference entry name for column width
 * @param prefs The preference store
 * @return The TableColumn object that was created
 */
public static TableColumn createTableColumn(Table parent, String header, int style, String sample_text,
        final String pref_name, final IPreferenceStore prefs) {

    // create the column
    TableColumn col = new TableColumn(parent, style);

    // if there is no pref store or the entry is missing, we use the sample
    // text and pack the column.
    // Otherwise we just read the width from the prefs and apply it.
    if (prefs == null || prefs.contains(pref_name) == false) {
        col.setText(sample_text);
        col.pack();

        // init the prefs store with the current value
        if (prefs != null) {
            prefs.setValue(pref_name, col.getWidth());
        }
    } else {
        col.setWidth(prefs.getInt(pref_name));
    }

    // set the header
    col.setText(header);

    // if there is a pref store and a pref entry name, then we setup a
    // listener to catch column resize to put store the new width value.
    if (prefs != null && pref_name != null) {
        col.addControlListener(new ControlListener() {
            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                // get the new width
                int w = ((TableColumn) e.widget).getWidth();

                // store in pref store
                prefs.setValue(pref_name, w);
            }
        });
    }

    return col;
}

From source file:com.android.ddmuilib.TableHelper.java

License:Apache License

/**
 * Create a TreeColumn with the specified parameters. If a
 * <code>PreferenceStore</code> object and a preference entry name String
 * object are provided then the column will listen to change in its width
 * and update the preference store accordingly.
 *
 * @param parent The Table parent object
 * @param header The header string//from w w  w  .j a  v  a2 s. c  o  m
 * @param style The column style
 * @param sample_text A sample text to figure out column width if preference
 *            value is missing
 * @param pref_name The preference entry name for column width
 * @param prefs The preference store
 */
public static void createTreeColumn(Tree parent, String header, int style, String sample_text,
        final String pref_name, final IPreferenceStore prefs) {

    // create the column
    TreeColumn col = new TreeColumn(parent, style);

    // if there is no pref store or the entry is missing, we use the sample
    // text and pack the column.
    // Otherwise we just read the width from the prefs and apply it.
    if (prefs == null || prefs.contains(pref_name) == false) {
        col.setText(sample_text);
        col.pack();

        // init the prefs store with the current value
        if (prefs != null) {
            prefs.setValue(pref_name, col.getWidth());
        }
    } else {
        col.setWidth(prefs.getInt(pref_name));
    }

    // set the header
    col.setText(header);

    // if there is a pref store and a pref entry name, then we setup a
    // listener to catch column resize to put store the new width value.
    if (prefs != null && pref_name != null) {
        col.addControlListener(new ControlListener() {
            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                // get the new width
                int w = ((TreeColumn) e.widget).getWidth();

                // store in pref store
                prefs.setValue(pref_name, w);
            }
        });
    }
}

From source file:com.android.ddmuilib.TableHelper.java

License:Apache License

/**
 * Create a TreeColumn with the specified parameters. If a
 * <code>PreferenceStore</code> object and a preference entry name String
 * object are provided then the column will listen to change in its width
 * and update the preference store accordingly.
 *
 * @param parent The Table parent object
 * @param header The header string//from   w  w w.  java 2s .  co  m
 * @param style The column style
 * @param width the width of the column if the preference value is missing
 * @param pref_name The preference entry name for column width
 * @param prefs The preference store
 */
public static void createTreeColumn(Tree parent, String header, int style, int width, final String pref_name,
        final IPreferenceStore prefs) {

    // create the column
    TreeColumn col = new TreeColumn(parent, style);

    // if there is no pref store or the entry is missing, we use the sample
    // text and pack the column.
    // Otherwise we just read the width from the prefs and apply it.
    if (prefs == null || prefs.contains(pref_name) == false) {
        col.setWidth(width);

        // init the prefs store with the current value
        if (prefs != null) {
            prefs.setValue(pref_name, width);
        }
    } else {
        col.setWidth(prefs.getInt(pref_name));
    }

    // set the header
    col.setText(header);

    // if there is a pref store and a pref entry name, then we setup a
    // listener to catch column resize to put store the new width value.
    if (prefs != null && pref_name != null) {
        col.addControlListener(new ControlListener() {
            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                // get the new width
                int w = ((TreeColumn) e.widget).getWidth();

                // store in pref store
                prefs.setValue(pref_name, w);
            }
        });
    }
}