eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/ApplicationWorkbenchAdvisor.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/ApplicationWorkbenchWindowAdvisor.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/Perspective.java -text
+eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/controller/FullNamePartitionScanner.java -text
+eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/controller/FullNameTextViewerConfig.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/controller/OpenNameEditorAction.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/controller/PropertySheetContentProvider.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/controller/PropertySheetValueLabelProvider.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/view/CarduusEditorView.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/view/EditNameProperties.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/view/EmptyEditorView.java -text
+eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/view/FullNameTextViewer.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/view/MoveDialogView.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/view/MultiPageTaxonView.java -text
eclipseprojects/eu.etaxonomy.taxeditor.prototype2/src/eu/etaxonomy/taxeditor/prototype2/view/MyCompletionProcessor.java -text
--- /dev/null
+package eu.etaxonomy.taxeditor.prototype2.controller;\r
+\r
+import org.eclipse.jface.text.rules.ICharacterScanner;\r
+import org.eclipse.jface.text.rules.IPredicateRule;\r
+import org.eclipse.jface.text.rules.IToken;\r
+import org.eclipse.jface.text.rules.IWordDetector;\r
+import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;\r
+import org.eclipse.jface.text.rules.Token;\r
+import org.eclipse.jface.text.rules.WordRule;\r
+\r
+public class FullNamePartitionScanner extends RuleBasedPartitionScanner {\r
+ public final static String SINGLE_WORD = "__single_word";\r
+ public final static String[] PARTITION_TYPES = {SINGLE_WORD}; \r
+ \r
+ public FullNamePartitionScanner()\r
+ {\r
+ super();\r
+ \r
+ IPredicateRule[] rules = new IPredicateRule[1];\r
+ \r
+ IToken word = new Token(SINGLE_WORD);\r
+ rules[0] = new WordPredicateRule (word);\r
+ \r
+ setPredicateRules(rules);\r
+ }\r
+ \r
+ class WordPredicateRule extends WordRule implements IPredicateRule {\r
+\r
+ private IToken fSuccessToken;\r
+ \r
+ public WordPredicateRule(IToken successToken) {\r
+ super(new IWordDetector() {\r
+ \r
+ public boolean isWordPart(char c) {\r
+ return !Character.isWhitespace(c);\r
+ }\r
+ \r
+ public boolean isWordStart(char c) {\r
+ return !Character.isWhitespace(c);\r
+ }\r
+ \r
+ });\r
+ this.fSuccessToken = successToken;\r
+ }\r
+\r
+ public IToken evaluate(ICharacterScanner scanner, boolean resume) {\r
+ return super.evaluate(scanner);\r
+ }\r
+ \r
+ public IToken evaluate(ICharacterScanner scanner) {\r
+ \r
+ StringBuffer fBuffer= new StringBuffer();\r
+ \r
+ int c = scanner.read();\r
+ if (c != ICharacterScanner.EOF && fDetector.isWordStart((char) c)) {\r
+ if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {\r
+\r
+ fBuffer.setLength(0);\r
+ do {\r
+ fBuffer.append((char) c);\r
+ c= scanner.read();\r
+ } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));\r
+ scanner.unread();\r
+\r
+ return fSuccessToken;\r
+ }\r
+ }\r
+\r
+ scanner.unread();\r
+ return Token.UNDEFINED;\r
+ }\r
+ \r
+\r
+ public IToken getSuccessToken() {\r
+ return fSuccessToken;\r
+ }\r
+ \r
+ }\r
+}\r
--- /dev/null
+package eu.etaxonomy.taxeditor.prototype2.controller;\r
+\r
+import org.eclipse.jface.text.IDocument;\r
+import org.eclipse.jface.text.presentation.IPresentationReconciler;\r
+import org.eclipse.jface.text.presentation.PresentationReconciler;\r
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;\r
+import org.eclipse.jface.text.rules.IToken;\r
+import org.eclipse.jface.text.rules.RuleBasedScanner;\r
+import org.eclipse.jface.text.source.ISourceViewer;\r
+import org.eclipse.jface.text.source.SourceViewerConfiguration;\r
+\r
+public class FullNameTextViewerConfig extends SourceViewerConfiguration {\r
+\r
+ /** \r
+ * Whenever a change is made to the document, a notification is sent to the \r
+ * IPresentationDamager for each content type in the affected area of the document. \r
+ * The IPresentationDamager in turn returns an IRegion indicating the area of the \r
+ * document which needs to be rebuilt as a result of the change. This information is \r
+ * then passed on to the IPresentationRepairer, which is responsible for reapplying \r
+ * the textual presentation for the affected region.\r
+ * \r
+ * This all probably sounds quite complicated. Fortunately you probably won't ever need \r
+ * to implement any of these classes yourself. JFace Text provides a \r
+ * DefaultDamagerRepairer which does the job both of the IPresentationDamager and the \r
+ * IPresentationRepairer. It also provides a PresentationReconciler class which performs \r
+ * the co-ordination role we described earlier.\r
+ * \r
+ * ...\r
+ * \r
+ * If you understand document partitioning then you are in a very good position to understand \r
+ * syntax highlighting in a JFace Text application. Essentially, syntax highlighting involves \r
+ * dividing a partition into tokens, each of which has its own text display attributes. The \r
+ * standard mechanism for doing this also involves the use of the already familiar tokens, \r
+ * scanners and rules.\r
+ * \r
+ **/ \r
+ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer)\r
+ {\r
+ PresentationReconciler reconciler = new PresentationReconciler();\r
+\r
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new FullNameScanner());\r
+// reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);\r
+// reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);\r
+ reconciler.setDamager(dr, FullNamePartitionScanner.SINGLE_WORD);\r
+ reconciler.setRepairer(dr, FullNamePartitionScanner.SINGLE_WORD); \r
+ \r
+ return reconciler;\r
+ }\r
+ \r
+ class FullNameScanner extends RuleBasedScanner {\r
+ \r
+ IToken currentToken;\r
+ \r
+ int count = 0;\r
+ \r
+ public IToken nextToken()\r
+ {\r
+ IToken token = super.nextToken();\r
+// if (currentToken == CDATA_START || currentToken == CDATA_TEXT && token != CDATA_END)\r
+// {\r
+// this.currentToken = CDATA_TEXT;\r
+// return CDATA_TEXT;\r
+// }\r
+ count++;\r
+ if (token.isEOF())\r
+ System.out.println("Count: " + count);\r
+ this.currentToken = token;\r
+ return token;\r
+ } \r
+ }\r
+}\r
IObservableValue observeNodeValue = ((PropertySheetNode) element).getObserveValue();\r
if (observeNodeValue != null) {\r
\r
- Assert.isTrue(bindingContext != null,\r
+ Assert.isNotNull(bindingContext,\r
"Label provider: PropertySheetViewer's binding context must be explicitly set.");\r
\r
TreeItemColumnAsBean itemColumn = new TreeItemColumnAsBean((TreeItem) cell.getItem(),1);\r
SourceViewer sourceviewer = new SourceViewer(composite, null, SWT.WRAP | SWT.FULL_SELECTION);\r
sourceviewer.setAnnotationHover(null);\r
styledText = sourceviewer.getTextWidget();\r
- final GridData gd_styledText = new GridData(SWT.FILL, SWT.TOP, true, false);\r
- gd_styledText.heightHint = 41;\r
- gd_styledText.widthHint = 450;\r
+ final GridData gd_styledText = new GridData(SWT.FILL, SWT.FILL, true, true);\r
+// gd_styledText.heightHint = 41;\r
+// gd_styledText.widthHint = 450;\r
styledText.setLayoutData(gd_styledText);\r
sourceviewer.setDocument(doc);\r
sourceviewer.configure(new MySourceViewerConfig());\r
--- /dev/null
+package eu.etaxonomy.taxeditor.prototype2.view;\r
+\r
+import org.eclipse.jface.text.BadLocationException;\r
+import org.eclipse.jface.text.Document;\r
+import org.eclipse.jface.text.IDocument;\r
+import org.eclipse.jface.text.IDocumentPartitioner;\r
+import org.eclipse.jface.text.ITypedRegion;\r
+import org.eclipse.jface.text.rules.FastPartitioner;\r
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;\r
+import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;\r
+import org.eclipse.jface.text.source.SourceViewer;\r
+import org.eclipse.swt.widgets.Composite;\r
+\r
+import eu.etaxonomy.taxeditor.prototype2.controller.FullNamePartitionScanner;\r
+\r
+/**\r
+ * Creates zero-length partitions for Genus, Specific Epithet, etc., then fills them\r
+ * as data is added. \r
+ * \r
+ * Partitions are databound to their respective model properties.\r
+ * \r
+ * @author p.ciardelli\r
+ *\r
+ */\r
+public class FullNameTextViewer extends SourceViewer {\r
+\r
+ FullNameTextViewer(Composite parent, int styles) {\r
+ super(parent, null, styles); // null -> no vertical ruler\r
+\r
+ final Document document = new Document("word1 'asdf' {asdfn} eiuakljnp <!--- word2 ---> word3\nlkasdjflkajsdf\n");\r
+\r
+ // replacing call to FullNamePartitionScanner because all we want i\r
+ final IDocumentPartitioner partitioner = new NamePartitioner(\r
+ new FullNamePartitionScanner(), FullNamePartitionScanner.PARTITION_TYPES);\r
+// final IDocumentPartitioner partitioner = new NamePartitioner(\r
+// new RuleBasedPartitionScanner(), new String[] {}); \r
+ \r
+ partitioner.connect(document);\r
+ document.setDocumentPartitioner(partitioner);\r
+ this.setDocument(document); // put this back in nameeditorview so that it functions more like TextViewer\r
+ \r
+// this.getControl().addKeyListener(new KeyListener() {\r
+//\r
+// public void keyPressed(KeyEvent e) {\r
+// ((NamePartitioner) partitioner).printPartitions(document);\r
+// \r
+// }\r
+//\r
+// public void keyReleased(KeyEvent e) {\r
+// // TODO Auto-generated method stub\r
+// \r
+// }\r
+// \r
+// });\r
+ \r
+ };\r
+ \r
+ class NamePartitioner extends FastPartitioner {\r
+ \r
+ public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) {\r
+ \r
+ // shows that only current partition is sent to computePartitioning\r
+ System.out.println("offset:" + offset + ", length: " + length);\r
+ \r
+ // how can i detect a new partition?\r
+ // when i'm inside a token, compute partitioning does not get called\r
+ \r
+ ITypedRegion[] regions = super.computePartitioning(offset, length, includeZeroLengthPartitions);\r
+ System.out.println("partitions: " + regions.length);\r
+ System.out.println("----------------------------------");\r
+ \r
+ return regions;\r
+ }\r
+ \r
+ public NamePartitioner(IPartitionTokenScanner scanner,\r
+ String[] legalContentTypes) {\r
+ super(scanner, legalContentTypes);\r
+ }\r
+ \r
+ public void connect(IDocument document, boolean delayInitialise)\r
+ {\r
+ super.connect(document, delayInitialise);\r
+ printPartitions(document);\r
+ }\r
+\r
+ public void printPartitions(IDocument document) {\r
+ StringBuffer buffer = new StringBuffer();\r
+ \r
+ ITypedRegion[] partitions = computePartitioning(0, document.getLength());\r
+ int wordcount = 0; \r
+ for (int i = 0; i < partitions.length; i++) {\r
+ try {\r
+ if (partitions[i].getType() == FullNamePartitionScanner.SINGLE_WORD)\r
+ wordcount++;\r
+ buffer.append("Partition type: " \r
+ + partitions[i].getType() \r
+ + ", offset: " + partitions[i].getOffset()\r
+ + ", length: " + partitions[i].getLength());\r
+ buffer.append("\n");\r
+ buffer.append("Text:\n");\r
+ buffer.append(document.get(partitions[i].getOffset(), \r
+ partitions[i].getLength()));\r
+ buffer.append("\n---------------------------\n\n\n");\r
+ } catch (BadLocationException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ buffer.append("Word partitions: " + wordcount);\r
+ System.out.print(buffer); \r
+ }\r
+ \r
+ }\r
+ \r
+ \r
+}\r
taxonname = null;\r
}\r
\r
-// setPartName(taxonname.getName());\r
-\r
- bindingContext = new DataBindingContext();\r
- bindingContext.bindValue( BeansObservables.observeValue(this,"partName"),\r
- BeansObservables.observeValue(taxonname,"name"),\r
- null, null);\r
- \r
+ setPartName(taxonname.getName()); \r
setSite(site);\r
setInput(input);\r
}\r
import eu.etaxonomy.cdm.model.name.TaxonName;\r
import eu.etaxonomy.taxeditor.prototype2.model.PropertySheetNode;\r
import eu.etaxonomy.taxeditor.prototype2.view.MySourceViewerConfig;\r
+import eu.etaxonomy.taxeditor.prototype2.controller.FullNameTextViewerConfig;\r
import eu.etaxonomy.taxeditor.prototype2.controller.PropertySheetContentProvider;\r
import eu.etaxonomy.taxeditor.prototype2.controller.PropertySheetValueLabelProvider;\r
import eu.etaxonomy.taxeditor.prototype2.controller.SaveNameAction;\r
// }\r
// });\r
parent.setLayout(new GridLayout());\r
- Document doc = new Document("");\r
+ \r
\r
final Label taxonomicallyIncludedInLabel = new Label(parent, SWT.NONE);\r
taxonomicallyIncludedInLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));\r
clickHereToText.setForeground(SWTResourceManager.getColor(192, 192, 192));\r
clickHereToText.setText(clickText);\r
clickHereToText.setFont(SWTResourceManager.getFont("Georgia", 12, SWT.ITALIC));\r
- final GridData gd_clickHereToText = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
+ final GridData gd_clickHereToText = new GridData(SWT.FILL, SWT.FILL, true, true);\r
gd_clickHereToText.widthHint = 426;\r
clickHereToText.setLayoutData(gd_clickHereToText);\r
clickHereToText.addFocusListener(new FocusListener() {\r
\r
});\r
\r
+ // Construct PropertySheetViewer, with bindings to model layer\r
PropertySheetViewer propertySheetViewer = new PropertySheetViewer(composite);\r
propertySheetViewer.setBindingContext(bindingContext);\r
\r
new PropertySheetValueEditingSupport(propertySheetViewer));\r
\r
propertySheetViewer.setInput(getPropertySheetNodes(taxonname));\r
+\r
+ // Construct name field(s)\r
+ FullNameTextViewer acceptedNameViewer = new FullNameTextViewer(composite, SWT.BORDER | SWT.WRAP | SWT.FULL_SELECTION | SWT.FILL);\r
+ acceptedNameViewer.getTextWidget().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));\r
+ acceptedNameViewer.configure(new FullNameTextViewerConfig());\r
\r
\r
-// clickHereToText.addKeyListener(new KeyListener() {\r
-//\r
-// public void keyPressed(KeyEvent e) {\r
-// dirtyBoy = true;\r
-// isDirty();\r
-// \r
-// }\r
-//\r
-// public void keyReleased(KeyEvent e) {\r
-// // TODO Auto-generated method stub\r
-// \r
-// }\r
-// \r
-// });\r
-\r
- //container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));\r
-\r
- SourceViewer sourceviewer = new SourceViewer(composite, null, SWT.WRAP | SWT.FULL_SELECTION);\r
- sourceviewer.setAnnotationHover(null);\r
- styledText = sourceviewer.getTextWidget();\r
- final GridData gd_styledText = new GridData(SWT.FILL, SWT.TOP, true, false);\r
- gd_styledText.heightHint = 41;\r
- gd_styledText.widthHint = 450;\r
- styledText.setLayoutData(gd_styledText);\r
- sourceviewer.setDocument(doc);\r
- sourceviewer.configure(new MySourceViewerConfig());\r
- sourceviewer.setTabsToSpacesConverter(null);\r
+// SourceViewer sourceviewer = new SourceViewer(composite, null, SWT.BORDER | SWT.WRAP | SWT.FULL_SELECTION);\r
+// sourceviewer.setAnnotationHover(null);\r
+// styledText = sourceviewer.getTextWidget();\r
+// final GridData gd_styledText = new GridData(SWT.FILL, SWT.TOP, true, false);\r
+// gd_styledText.heightHint = 41;\r
+// gd_styledText.widthHint = 450;\r
+// styledText.setLayoutData(gd_styledText);\r
+// sourceviewer.setDocument(doc);\r
+// sourceviewer.configure(new MySourceViewerConfig());\r
+// sourceviewer.setTabsToSpacesConverter(null);\r
\r
- populateForm();\r
+ populateForm(); // will this be necessary if databinding is correctly set up?\r
\r
Text testeroo = new Text(composite, SWT.BORDER);\r
testeroo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
\r
bindingContext.bindValue( SWTObservables.observeText(testeroo, SWT.Modify),\r
BeansObservables.observeValue(taxonname,"genus"),\r
- null, null); \r
+ null, null);\r
+ \r
+ \r
+// clickHereToText.addKeyListener(new KeyListener() {\r
+ //\r
+// public void keyPressed(KeyEvent e) {\r
+// dirtyBoy = true;\r
+// isDirty();\r
+// \r
+// }\r
+ //\r
+// public void keyReleased(KeyEvent e) {\r
+// // TODO Auto-generated method stub\r
+// \r
+// }\r
+// \r
+// });\r
+\r
+ //container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); \r
+ \r
}\r
\r
-// private void populateForm() {\r
-// \r
-// String fulltext = "";\r
-// \r
-// if (taxonname.getGenus() != null) {\r
-// fulltext = taxonname.getGenus();\r
-// }\r
-//\r
-// if (taxonname.getSpecificEpithet() != null) {\r
-// fulltext += " " + taxonname.getSpecificEpithet();\r
-// }\r
-//\r
-// if (taxonname.getAuthorship() != null) {\r
-// fulltext += " " + taxonname.getAuthorship();\r
-// }\r
-// \r
-//// txtPlay.setText(fulltext);\r
-//// txtPlay.setToolTipText("Joe mama\njoe daddy\njoe gramammy");\r
-// \r
-// this.setPartName(taxonname.getName());\r
-// }\r
\r
private void populateForm() {\r
this.setPartName(taxonname.getName());\r
public boolean isSaveAsAllowed() {\r
return false;\r
}\r
-\r
- public void propertyChange(PropertyChangeEvent evt) {\r
- this.taxonname = (TaxonName)evt.getNewValue();\r
- System.out.println(((TaxonName)evt.getNewValue()).getName());\r
- populateForm();\r
- \r
- // for individual fields, do something like:\r
- // if (evt.getPropertyName().equalsIgnoreCase("genus"))\r
- // txtGenus.setText ...\r
- }\r
-\r
\r
private static void addDropDown(final ToolItem item, final Menu menu) {\r
item.addListener(SWT.Selection, new Listener() {\r
IObservableValue observeNodeValue = node.getObserveValue();\r
if (observeNodeValue != null) {\r
\r
- Assert.isTrue(bindingContext != null,\r
+ Assert.isNotNull(bindingContext,\r
"Editing support: PropertySheetViewer's binding context must be explicitly set.");\r
\r
IObservableValue observeCellValue = SWTObservables.observeText(cellEditor.getControl(), SWT.Modify);\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.layout.GridData;\r
import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.TreeColumn;\r
\r
import eu.etaxonomy.taxeditor.prototype2.model.PropertySheetNode;\r
\r
this.getTree().setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true));\r
this.getTree().setLinesVisible(true);\r
this.getTree().setHeaderVisible(false);\r
- this.getTree().setSize(200, 300);\r
+ this.getTree().getVerticalBar().setEnabled(true);\r
\r
// create a column for property fields\r
propertyFieldColumn = new TreeViewerColumn(this, SWT.NONE);\r
propertyValueColumn = new TreeViewerColumn(this, SWT.NONE);\r
propertyValueColumn.getColumn().setWidth(100);\r
propertyValueColumn.getColumn().setMoveable(true);\r
+ \r
+ this.getTree().setSize(150, 300);\r
+// propertyFieldColumn.getColumn().pack();\r
+// propertyValueColumn.getColumn().pack();\r
+// this.getTree().redraw();\r
}\r
\r
public TreeViewerColumn getPropertyFieldColumn() {\r