List of usage examples for org.eclipse.jface.preference IPreferenceStore getInt
int getInt(String name);
From source file:com.android.ddmuilib.log.event.EventLogPanel.java
License:Apache License
private void createDisplayUi() { RowLayout rowLayout = new RowLayout(); rowLayout.wrap = true;// w ww. j a v a2s. com rowLayout.pack = false; rowLayout.justify = true; rowLayout.fill = true; rowLayout.type = SWT.HORIZONTAL; mBottomPanel.setLayout(rowLayout); IPreferenceStore store = DdmUiPreferences.getStore(); int displayWidth = store.getInt(PREFS_DISPLAY_WIDTH); int displayHeight = store.getInt(PREFS_DISPLAY_HEIGHT); for (EventDisplay eventDisplay : mEventDisplays) { Control c = eventDisplay.createComposite(mBottomPanel, mCurrentEventLogParser, this); if (c != null) { RowData rd = new RowData(); rd.height = displayHeight; rd.width = displayWidth; c.setLayoutData(rd); } Table table = eventDisplay.getTable(); if (table != null) { addTableToFocusListener(table); } } mBottomPanel.layout(); mBottomParentPanel.setMinSize(mBottomPanel.computeSize(SWT.DEFAULT, SWT.DEFAULT)); mBottomParentPanel.layout(); }
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 w w w . j a v a 2 s. co 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 www .ja v a2 s. 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 w ww.ja v a 2 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 * @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 va2 s. co 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. j a v a 2s .c om * @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); } }); } }
From source file:com.android.ddmuilib.ThreadPanel.java
License:Apache License
/** * Create our control(s)./* ww w . j av a 2 s. com*/ */ @Override protected Control createControl(Composite parent) { mDisplay = parent.getDisplay(); final IPreferenceStore store = DdmUiPreferences.getStore(); mBase = new Composite(parent, SWT.NONE); mBase.setLayout(new StackLayout()); // UI for thread not enabled mNotEnabled = new Label(mBase, SWT.CENTER | SWT.WRAP); mNotEnabled.setText("Thread updates not enabled for selected client\n" + "(use toolbar button to enable)"); // UI for not client selected mNotSelected = new Label(mBase, SWT.CENTER | SWT.WRAP); mNotSelected.setText("no client is selected"); // base composite for selected client with enabled thread update. mThreadBase = new Composite(mBase, SWT.NONE); mThreadBase.setLayout(new FormLayout()); // table above the sash mThreadTable = new Table(mThreadBase, SWT.MULTI | SWT.FULL_SELECTION); mThreadTable.setHeaderVisible(true); mThreadTable.setLinesVisible(true); TableHelper.createTableColumn(mThreadTable, "ID", SWT.RIGHT, "888", //$NON-NLS-2$ PREFS_THREAD_COL_ID, store); TableHelper.createTableColumn(mThreadTable, "Tid", SWT.RIGHT, "88888", //$NON-NLS-2$ PREFS_THREAD_COL_TID, store); TableHelper.createTableColumn(mThreadTable, "Status", SWT.LEFT, "timed-wait", //$NON-NLS-2$ PREFS_THREAD_COL_STATUS, store); TableHelper.createTableColumn(mThreadTable, "utime", SWT.RIGHT, "utime", //$NON-NLS-2$ PREFS_THREAD_COL_UTIME, store); TableHelper.createTableColumn(mThreadTable, "stime", SWT.RIGHT, "utime", //$NON-NLS-2$ PREFS_THREAD_COL_STIME, store); TableHelper.createTableColumn(mThreadTable, "Name", SWT.LEFT, "android.class.ReallyLongClassName.MethodName", //$NON-NLS-1$ PREFS_THREAD_COL_NAME, store); mThreadViewer = new TableViewer(mThreadTable); mThreadViewer.setContentProvider(new ThreadContentProvider()); mThreadViewer.setLabelProvider(new ThreadLabelProvider()); mThreadViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { requestThreadStackTrace(getThreadSelection(event.getSelection())); } }); mThreadViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { requestThreadStackTrace(getThreadSelection(event.getSelection())); } }); // the separating sash final Sash sash = new Sash(mThreadBase, SWT.HORIZONTAL); Color darkGray = parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY); sash.setBackground(darkGray); // the UI below the sash mStackTraceBase = new Composite(mThreadBase, SWT.NONE); mStackTraceBase.setLayout(new GridLayout(2, false)); mRefreshStackTraceButton = new Button(mStackTraceBase, SWT.PUSH); mRefreshStackTraceButton.setText("Refresh"); mRefreshStackTraceButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { requestThreadStackTrace(getThreadSelection(null)); } }); mStackTraceTimeLabel = new Label(mStackTraceBase, SWT.NONE); mStackTraceTimeLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); mStackTracePanel = new StackTracePanel(); mStackTraceTable = mStackTracePanel.createPanel(mStackTraceBase, PREFS_STACK_COLUMN, store); GridData gd; mStackTraceTable.setLayoutData(gd = new GridData(GridData.FILL_BOTH)); gd.horizontalSpan = 2; // 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); mThreadTable.setLayoutData(data); final FormData sashData = new FormData(); if (store != null && store.contains(PREFS_THREAD_SASH)) { sashData.top = new FormAttachment(0, store.getInt(PREFS_THREAD_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); mStackTraceBase.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 = mThreadBase.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_THREAD_SASH, e.y); mThreadBase.layout(); } } }); ((StackLayout) mBase.getLayout()).topControl = mNotSelected; return mBase; }
From source file:com.android.ide.eclipse.adt.internal.editors.formatting.EclipseXmlFormatPreferences.java
License:Open Source License
/** * Returns the number of spaces used to display a single tab character * * @return the number of spaces used to display a single tab character *///from w w w .j av a 2 s. c o m @Override @SuppressWarnings("restriction") // Editor settings public int getTabWidth() { if (mTabWidth == -1) { String key = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH; try { IPreferenceStore prefs = EditorsPlugin.getDefault().getPreferenceStore(); mTabWidth = prefs.getInt(key); } catch (Throwable t) { // Pass: We'll pick a suitable default instead below } if (mTabWidth <= 0) { mTabWidth = 4; } } return mTabWidth; }
From source file:com.android.ide.eclipse.adt.internal.editors.formatting.XmlFormatPreferences.java
License:Open Source License
/** * Returns the number of spaces used to display a single tab character * * @return the number of spaces used to display a single tab character *//*from ww w.j a v a2s .c o m*/ @SuppressWarnings("restriction") // Editor settings public int getTabWidth() { if (mTabWidth == -1) { String key = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH; try { IPreferenceStore prefs = EditorsPlugin.getDefault().getPreferenceStore(); mTabWidth = prefs.getInt(key); } catch (Throwable t) { // Pass: We'll pick a suitable default instead below } if (mTabWidth <= 0) { mTabWidth = 4; } } return mTabWidth; }
From source file:com.android.ide.eclipse.adt.internal.sdk.Sdk.java
License:Open Source License
/** * Tries to fix all currently open Android legacy editors. * <p/>/*ww w . j a va2 s.c o m*/ * If an editor is found to match one of the legacy ids, we'll try to close it. * If that succeeds, we try to reopen it using the new common editor ID. * <p/> * This method must be run from the UI thread. */ private void fixOpenLegacyEditors() { AdtPlugin adt = AdtPlugin.getDefault(); if (adt == null) { return; } final IPreferenceStore store = adt.getPreferenceStore(); int currentValue = store.getInt(AdtPrefs.PREFS_FIX_LEGACY_EDITORS); // The target version we're comparing to. This must be incremented each time // we change the processing here so that a new version of the plugin would // try to fix existing editors. final int targetValue = 1; if (currentValue >= targetValue) { return; } // To be able to close and open editors we need to make sure this is done // in the UI thread, which this isn't invoked from. PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @Override public void run() { HashSet<String> legacyIds = new HashSet<String>(Arrays.asList(CommonXmlEditor.LEGACY_EDITOR_IDS)); for (IWorkbenchWindow win : PlatformUI.getWorkbench().getWorkbenchWindows()) { for (IWorkbenchPage page : win.getPages()) { for (IEditorReference ref : page.getEditorReferences()) { try { IEditorInput input = ref.getEditorInput(); if (input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) input).getFile(); IEditorPart part = ref.getEditor(true /*restore*/); if (part != null) { IWorkbenchPartSite site = part.getSite(); if (site != null) { String id = site.getId(); if (legacyIds.contains(id)) { // This editor matches one of legacy editor IDs. fixEditor(page, part, input, file, id); } } } } } catch (Exception e) { // ignore } } } } // Remember that we managed to do fix all editors store.setValue(AdtPrefs.PREFS_FIX_LEGACY_EDITORS, targetValue); } private void fixEditor(IWorkbenchPage page, IEditorPart part, IEditorInput input, IFile file, String id) { IDE.setDefaultEditor(file, CommonXmlEditor.ID); boolean ok = page.closeEditor(part, true /*save*/); AdtPlugin.log(IStatus.INFO, "Closed legacy editor ID %s for %s: %s", //$NON-NLS-1$ id, file.getFullPath(), ok ? "Success" : "Failed");//$NON-NLS-1$ //$NON-NLS-2$ if (ok) { // Try to reopen it with the new ID try { page.openEditor(input, CommonXmlEditor.ID); } catch (PartInitException e) { AdtPlugin.log(e, "Failed to reopen %s", //$NON-NLS-1$ file.getFullPath()); } } } }); }