Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 76347 Details for
Bug 51580
[RCP][Views] Need the ability to resize views programmatically
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Modified example view to the o.e.ui.tests plugin
51580_ui_tests_ct_patch.txt (text/plain), 9.71 KB, created by
Chris Torrence
on 2007-08-17 17:47:40 EDT
(
hide
)
Description:
Modified example view to the o.e.ui.tests plugin
Filename:
MIME Type:
Creator:
Chris Torrence
Created:
2007-08-17 17:47:40 EDT
Size:
9.71 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.tests >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/plugin.xml,v >retrieving revision 1.233 >diff -u -r1.233 plugin.xml >--- plugin.xml 12 Jul 2007 18:38:28 -0000 1.233 >+++ plugin.xml 17 Aug 2007 20:02:50 -0000 >@@ -453,6 +453,12 @@ > id="org.eclipse.ui.tests.manual.ViewWithSaveables" > name="View Owning Saveables"> > </view> >+ <view >+ allowMultiple="true" >+ class="org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView" >+ id="org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView" >+ name="Layout Constraints Test"> >+ </view> > > </extension> > <extension >Index: Eclipse UI Tests/org/eclipse/ui/tests/layout/constraints/LayoutConstraintsView.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/layout/constraints/LayoutConstraintsView.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/layout/constraints/LayoutConstraintsView.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/layout/constraints/LayoutConstraintsView.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,278 @@ >+package org.eclipse.ui.tests.layout.constraints; >+ >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.layout.GridDataFactory; >+import org.eclipse.jface.layout.GridLayoutFactory; >+import org.eclipse.jface.layout.LayoutConstants; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Text; >+import org.eclipse.ui.ISizeProvider; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchPartConstants; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.part.ViewPart; >+ >+public class LayoutConstraintsView extends ViewPart implements ISizeProvider { >+ >+ private Control control; >+ >+ private int minWidth = ISizeProvider.INFINITE; >+ private int maxWidth = ISizeProvider.INFINITE; >+ private int minHeight = ISizeProvider.INFINITE; >+ private int maxHeight = ISizeProvider.INFINITE; >+ private int quantizedWidth = ISizeProvider.INFINITE; >+ private int quantizedHeight = ISizeProvider.INFINITE; >+ private int fixedArea = ISizeProvider.INFINITE; >+ private Text minWidthText; >+ private Text maxWidthText; >+ private Text quantizedWidthText; >+ private Text minHeightText; >+ private Text maxHeightText; >+ private Text quantizedHeightText; >+ private Text fixedAreaText; >+ >+ public void createPartControl(Composite parent) { >+ control = parent; >+ >+ Composite buttonBar = new Composite(parent, SWT.NONE); >+ { >+ GridDataFactory buttonData = GridDataFactory.fillDefaults().grab(true, false); >+ >+ Button applyButton = new Button(buttonBar, SWT.PUSH); >+ applyButton.setText("Apply"); >+ applyButton.addSelectionListener(new SelectionAdapter() { >+ /* (non-Javadoc) >+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) >+ */ >+ public void widgetSelected(SelectionEvent e) { >+ applyPressed(); >+ } >+ }); >+ buttonData.applyTo(applyButton); >+ >+ Button clearButton = new Button(buttonBar, SWT.PUSH); >+ clearButton.setText("Reset"); >+ clearButton.addSelectionListener(new SelectionAdapter() { >+ /* (non-Javadoc) >+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) >+ */ >+ public void widgetSelected(SelectionEvent e) { >+ minWidthText.setText(""); >+ maxWidthText.setText(""); >+ quantizedWidthText.setText(""); >+ minHeightText.setText(""); >+ maxHeightText.setText(""); >+ quantizedHeightText.setText(""); >+ fixedAreaText.setText(""); >+ applyPressed(); >+ } >+ }); >+ buttonData.applyTo(clearButton); >+ >+ Button newViewButton = new Button(buttonBar, SWT.PUSH); >+ newViewButton.setText("New View"); >+ newViewButton.addSelectionListener(new SelectionAdapter() { >+ /* (non-Javadoc) >+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) >+ */ >+ public void widgetSelected(SelectionEvent e) { >+ try { >+ getSite().getPage().showView("org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView", >+ "" + System.currentTimeMillis(), IWorkbenchPage.VIEW_ACTIVATE); >+ } catch (PartInitException e1) { >+ MessageDialog.openError(getSite().getShell(), "Error opening view", "Unable to open view."); >+ } >+ } >+ }); >+ buttonData.applyTo(newViewButton); >+ >+ GridLayoutFactory.fillDefaults().equalWidth(true).numColumns(3).applyTo(buttonBar); >+ } >+ GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(buttonBar); >+ >+ new Label(parent, SWT.NONE).setText("Min Width"); >+ minWidthText = createText(parent); >+ >+ new Label(parent, SWT.NONE).setText("Max Width (blank = unbounded)"); >+ maxWidthText = createText(parent); >+ >+ new Label(parent, SWT.NONE).setText("Quantized Width (blank = none)"); >+ quantizedWidthText = createText(parent); >+ >+ new Label(parent, SWT.NONE).setText("Min Height"); >+ minHeightText = createText(parent); >+ >+ new Label(parent, SWT.NONE).setText("Max Height (blank = unbounded)"); >+ maxHeightText = createText(parent); >+ >+ new Label(parent, SWT.NONE).setText("Quantized Height (blank = none)"); >+ quantizedHeightText = createText(parent); >+ >+ new Label(parent, SWT.NONE).setText("Fixed Area (blank = none"); >+ fixedAreaText = createText(parent); >+ >+ >+ GridLayoutFactory.fillDefaults().numColumns(2).margins(LayoutConstants.getMargins()).generateLayout(parent); >+ } >+ >+ /** >+ * >+ */ >+ protected void applyPressed() { >+ // Copy the values from the text boxes >+ minWidth = getInt(minWidthText); >+ maxWidth = getInt(maxWidthText); >+ quantizedWidth = getInt(quantizedWidthText); >+ minHeight = getInt(minHeightText); >+ maxHeight = getInt(maxHeightText); >+ quantizedHeight = getInt(quantizedHeightText); >+ fixedArea = getInt(fixedAreaText); >+ >+ // Trigger a workbench layout >+ updateLayout(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.ISizeProvider#getSizeFlags(boolean) >+ */ >+ public int getSizeFlags(boolean width) { >+ int flags = 0; >+ if (width) { >+ if (minWidth != ISizeProvider.INFINITE) { >+ flags |= SWT.MIN; >+ } >+ if (maxWidth != ISizeProvider.INFINITE) { >+ flags |= SWT.MAX; >+ } >+ if (quantizedWidth != ISizeProvider.INFINITE || fixedArea != ISizeProvider.INFINITE) { >+ flags |= SWT.FILL; >+ } >+ if (fixedArea != ISizeProvider.INFINITE) { >+ flags |= SWT.WRAP; >+ } >+ } else { >+ if (minHeight != ISizeProvider.INFINITE) { >+ flags |= SWT.MIN; >+ } >+ if (maxHeight != ISizeProvider.INFINITE) { >+ flags |= SWT.MAX; >+ } >+ if (quantizedHeight != ISizeProvider.INFINITE || fixedArea != ISizeProvider.INFINITE) { >+ flags |= SWT.FILL; >+ } >+ if (fixedArea != ISizeProvider.INFINITE) { >+ flags |= SWT.WRAP; >+ } >+ } >+ >+ return flags; >+ } >+ >+ /** >+ * @param minWidth2 >+ * @return >+ */ >+ private int getInt(Text text) { >+ if (text.getText().equals("")) { >+ return ISizeProvider.INFINITE; >+ } >+ >+ try { >+ return Integer.parseInt(text.getText()); >+ } catch (NumberFormatException e) { >+ return ISizeProvider.INFINITE; >+ } >+ } >+ >+ /** >+ * >+ */ >+ protected void updateLayout() { >+ firePropertyChange(IWorkbenchPartConstants.PROP_PREFERRED_SIZE); >+ } >+ >+ /** >+ * @param parent >+ */ >+ private Text createText(Composite parent) { >+ return new Text(parent, SWT.BORDER); >+ } >+ >+ public void setFocus() { >+ control.setFocus(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.ISizeProvider#computePreferredSize(boolean, int, int, int) >+ */ >+ public int computePreferredSize(boolean width, int availableParallel, >+ int availablePerpendicular, int preferredResult) { >+ >+ int area = fixedArea; >+ int result = preferredResult; >+ // If we're trying to maintain a fixed area, compute the preferred width in terms >+ // of the available height or vise-versa. A view that is trying to exactly fit a wrapping >+ // widget would use similar logic >+ if (area != ISizeProvider.INFINITE) { >+ if (availablePerpendicular == 0) { >+ result = 0; >+ } else { >+ result = area / availablePerpendicular; >+ } >+ >+ if (result < 30) { >+ result = 30; >+ } >+ } >+ >+ // Get the user-entered minimum, maximum, and quantized sizes for this dimension >+ int min; >+ int max; >+ int quant; >+ >+ if (width) { >+ min = minWidth; >+ max = maxWidth; >+ quant = quantizedWidth; >+ } else { >+ min = minHeight; >+ max = maxHeight; >+ quant = quantizedHeight; >+ } >+ >+ // If we're using quantized sizes, jump to the nearest multiple >+ // of the quantized size >+ if (quant != ISizeProvider.INFINITE && quant != 0) { >+ result = Math.min(result + quant / 2, availableParallel); >+ result = result - (result % quant); >+ } >+ >+ // Ensure we go no smaller than the minimum size >+ if (min != ISizeProvider.INFINITE && result < min) { >+ result = min; >+ } >+ >+ // Ensure we go no larger than the maximum size >+ if (result > max) { >+ result = max; >+ } >+ >+ // Ensure that we don't use more than the available space >+ if (result > availableParallel) { >+ result = availableParallel; >+ } >+ >+ if (result < 0) { >+ result = 0; >+ } >+ >+ return result; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 51580
:
8564
|
8565
|
59221
|
59222
|
76344
|
76347
|
76462
|
76508