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 36093 Details for
Bug 131435
[DataBinding] Support for StyledText
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
StyledText patch
patch.txt (text/plain), 7.00 KB, created by
Aaron Digulla
on 2006-03-11 14:52:37 EST
(
hide
)
Description:
StyledText patch
Filename:
MIME Type:
Creator:
Aaron Digulla
Created:
2006-03-11 14:52:37 EST
Size:
7.00 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface.databinding >Index: src/org/eclipse/jface/internal/provisional/databinding/swt/SWTUpdatableFactory.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/provisional/databinding/swt/SWTUpdatableFactory.java,v >retrieving revision 1.2 >diff -u -r1.2 SWTUpdatableFactory.java >--- src/org/eclipse/jface/internal/provisional/databinding/swt/SWTUpdatableFactory.java 24 Feb 2006 17:03:19 -0000 1.2 >+++ src/org/eclipse/jface/internal/provisional/databinding/swt/SWTUpdatableFactory.java 11 Mar 2006 19:54:38 -0000 >@@ -22,6 +22,7 @@ > import org.eclipse.jface.internal.databinding.swt.ListUpdatableCollection; > import org.eclipse.jface.internal.databinding.swt.ListUpdatableValue; > import org.eclipse.jface.internal.databinding.swt.SpinnerUpdatableValue; >+import org.eclipse.jface.internal.databinding.swt.StyledTextUpdatableValue; > import org.eclipse.jface.internal.databinding.swt.TableUpdatableValue; > import org.eclipse.jface.internal.databinding.swt.TextUpdatableValue; > import org.eclipse.jface.internal.databinding.viewers.StructuredViewerUpdatableValue; >@@ -37,6 +38,7 @@ > import org.eclipse.jface.viewers.TableViewer; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.CCombo; >+import org.eclipse.swt.custom.StyledText; > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Combo; > import org.eclipse.swt.widgets.Control; >@@ -210,6 +212,8 @@ > } else if (description instanceof List) { > return new ListUpdatableCollection((List) description, > ViewersProperties.CONTENT); >+ } else if (description instanceof StyledText) { >+ return new StyledTextUpdatableValue((StyledText) description,SWT.FocusOut); > } > return null; > } >Index: src/org/eclipse/jface/internal/databinding/swt/StyledTextUpdatableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/StyledTextUpdatableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/StyledTextUpdatableValue.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/StyledTextUpdatableValue.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,159 @@ >+/******************************************************************************* >+ * Copyright (c) 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.jface.internal.provisional.databinding.ChangeEvent; >+import org.eclipse.jface.internal.provisional.databinding.UpdatableValue; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.KeyListener; >+import org.eclipse.swt.events.VerifyEvent; >+import org.eclipse.swt.events.VerifyListener; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public class StyledTextUpdatableValue extends UpdatableValue { >+ >+ private final StyledText text; >+ >+ private boolean updating = false; >+ >+ private int updatePolicy; >+ >+ private String bufferedValue; >+ >+ private Listener validateListener = new Listener() { >+ public void handleEvent(Event event) { >+ if (!updating) { >+ fireChangeEvent(ChangeEvent.CHANGE, null, text.getText()); >+ } >+ } >+ }; >+ >+ private Listener updateListener = new Listener() { >+ public void handleEvent(Event event) { >+ if (!updating) { >+ String oldValue = bufferedValue; >+ String newValue = text.getText(); >+ >+ // If we are updating on focus lost then when we fire the change event change the buffered value >+ if (updatePolicy == SWT.FocusOut){ >+ bufferedValue = text.getText(); >+ if (!oldValue.equals(newValue)) { >+ fireChangeEvent(ChangeEvent.CHANGE, null, text.getText()); >+ } >+ } else { >+ fireChangeEvent(ChangeEvent.CHANGE, null, text.getText()); >+ } >+ } >+ } >+ }; >+ >+ private VerifyListener verifyListener; >+ >+ private KeyListener keyListener; >+ >+ /** >+ * @param text >+ * @param updatePolicy >+ */ >+ public StyledTextUpdatableValue(final StyledText text, int updatePolicy) { >+ this.text = text; >+ this.updatePolicy = updatePolicy; >+ if (updatePolicy != SWT.None) { >+ text.addListener(updatePolicy, updateListener); >+ } >+ // If the update policy is TIME_EARLY then the model is notified of changed on key stroke by key stroke >+ // When escape is pressed we need to rollback to the previous value which is done with a key listener, however >+ // the bufferedValue (the last remembered change value) must be changed on focus lost >+ if(updatePolicy == SWT.Modify){ >+ text.addListener(SWT.FocusOut, new Listener(){ >+ public void handleEvent(Event event){ >+ if(!updating){ >+ bufferedValue = text.getText(); >+ } >+ } >+ }); >+ } >+ verifyListener = new VerifyListener() { >+ public void verifyText(VerifyEvent e) { >+ if (!updating) { >+ String currentText = StyledTextUpdatableValue.this.text.getText(); >+ String newText = currentText.substring(0, e.start) + e.text >+ + currentText.substring(e.end); >+ ChangeEvent changeEvent = fireChangeEvent( >+ ChangeEvent.VERIFY, currentText, newText); >+ if (changeEvent.getVeto()) { >+ e.doit = false; >+ } >+ } >+ } >+ }; >+ text.addVerifyListener(verifyListener); >+ keyListener = new KeyListener(){ >+ public void keyPressed(KeyEvent e) { >+ if(e.character == SWT.ESC && bufferedValue != null){ >+ // Revert the value in the text field to the model value >+ text.setText(bufferedValue); >+ } >+ } >+ public void keyReleased(KeyEvent e) { >+ } >+ }; >+ text.addKeyListener(keyListener); >+ } >+ >+ public void setValue(final Object value) { >+ >+ AsyncRunnable runnable = new AsyncRunnable(){ >+ public void run(){ >+ String oldValue = text.getText(); >+ try { >+ updating = true; >+ bufferedValue = (String)value; >+ text.setText(value == null ? "" : value.toString()); //$NON-NLS-1$ >+ } finally { >+ updating = false; >+ } >+ fireChangeEvent(ChangeEvent.CHANGE, oldValue, text.getText()); >+ } >+ }; >+ runnable.runOn(text.getDisplay()); >+ } >+ >+ public Object computeValue() { >+ SyncRunnable runnable = new SyncRunnable(){ >+ public Object run() { >+ return text.getText(); >+ } >+ }; >+ return runnable.runOn(text.getDisplay()); >+ } >+ >+ public Class getValueType() { >+ return String.class; >+ } >+ >+ public void dispose() { >+ if (!text.isDisposed()) { >+ if (updatePolicy != SWT.None) { >+ text.removeListener(updatePolicy, updateListener); >+ } >+ text.removeVerifyListener(verifyListener); >+ } >+ super.dispose(); >+ } >+}
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 131435
: 36093 |
111875
|
111876