Add Tree Cell Editor _ Tree Editor « SWT « Java Tutorial
Add Tree Cell Editor _ Tree Editor « SWT « Java Tutorial
com) Search
Java Tutorial
(/Tutorial/Java/CatalogJava.htm) Add Tree cell editor : Tree
Language
(/Tutorial/Java/0020__Language/C Editor « SWT « Java Tutorial
atalog0020__Language.htm)
Data Type
(/Tutorial/Java/0040__Data-
Type/Catalog0040__Data-
Type.htm)
Operators
(/Tutorial/Java/0060__Operators/C Java Tutorial (/Tutorial/Java/CatalogJava.htm) / SWT (/Tutorial/Java/0280__SWT/Catalog0280__SWT.htm)
atalog0060__Operators.htm) / Tree Editor (/Tutorial/Java/0280__SWT/1220__Tree-Editor.htm) /
Statement Control
(/Tutorial/Java/0080__Statement-
Control/Catalog0080__Statement-
Control.htm)
Class Definition
(/Tutorial/Java/0100__Class-
Definition/Catalog0100__Class-
Definition.htm)
Development
(/Tutorial/Java/0120__Developmen
t/Catalog0120__Development.htm)
Reflection
(/Tutorial/Java/0125__Reflection/C
atalog0125__Reflection.htm)
Regular Expressions
(/Tutorial/Java/0130__Regular-
Expressions/Catalog0130__Regula
r-Expressions.htm)
Collections
(/Tutorial/Java/0140__Collections/
Catalog0140__Collections.htm)
Thread
(/Tutorial/Java/0160__Thread/Catal
og0160__Thread.htm)
File
(/Tutorial/Java/0180__File/Catalog
0180__File.htm)
Generics
/*******************************************************************************
(/Tutorial/Java/0200__Generics/Ca * Copyright (c) 2000, 2004 IBM Corporation and others.
talog0200__Generics.htm) * All rights reserved. This program and the accompanying materials
I18N * are made available under the terms of the Eclipse Public License v1.0
(/Tutorial/Java/0220__I18N/Catalo * which accompanies this distribution, and is available at
g0220__I18N.htm) * http://www.eclipse.org/legal/epl-v10.html
Swing *
(/Tutorial/Java/0240__Swing/Catal * Contributors:
og0240__Swing.htm) * IBM Corporation - initial API and implementation
Swing Event *******************************************************************************/
//package org.eclipse.swt.snippets;
(/Tutorial/Java/0260__Swing-
/*
Event/Catalog0260__Swing-
* TreeEditor example snippet: edit the text of a tree item (in place, fancy)
Event.htm)
*
2D Graphics * For a list of all SWT example snippets see
(/Tutorial/Java/0261__2D- * http://www.eclipse.org/swt/snippets/
Graphics/Catalog0261__2D- */
Graphics.htm) import org.eclipse.swt.SWT;
SWT () import org.eclipse.swt.custom.TreeEditor;
SWT 2D Graphics import org.eclipse.swt.graphics.Color;
(/Tutorial/Java/0300__SWT-2D- import org.eclipse.swt.graphics.GC;
Graphics/Catalog0300__SWT-2D- import org.eclipse.swt.graphics.Point;
Graphics.htm) import org.eclipse.swt.graphics.Rectangle;
Network import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
(/Tutorial/Java/0320__Network/Cat
import org.eclipse.swt.widgets.Display;
alog0320__Network.htm)
import org.eclipse.swt.widgets.Event;
Database
import org.eclipse.swt.widgets.Listener;
(/Tutorial/Java/0340__Database/C import org.eclipse.swt.widgets.Shell;
atalog0340__Database.htm) import org.eclipse.swt.widgets.Text;
Hibernate import org.eclipse.swt.widgets.Tree;
(/Tutorial/Java/0350__Hibernate/C import org.eclipse.swt.widgets.TreeItem;
atalog0350__Hibernate.htm)
JPA public class TreeCellEditor {
(/Tutorial/Java/0355__JPA/Catalog
0355__JPA.htm) public static void main(String[] args) {
JSP final Display display = new Display();
(/Tutorial/Java/0360__JSP/Catalog final Color black = display.getSystemColor(SWT.COLOR_BLACK);
Shell shell = new Shell(display);
0360__JSP.htm)
shell.setLayout(new FillLayout());
JSTL
final Tree tree = new Tree(shell, SWT.BORDER);
(/Tutorial/Java/0380__JSTL/Catalo
for (int i = 0; i < 16; i++) {
g0380__JSTL.htm) TreeItem itemI = new TreeItem(tree, SWT.NONE);
itemI.setText("Item " + i);
Servlet for (int j = 0; j < 16; j++) {
(/Tutorial/Java/0400__Servlet/Catal TreeItem itemJ = new TreeItem(itemI, SWT.NONE);
og0400__Servlet.htm) itemJ.setText("Item " + j);
}
Web Services SOA
}
(/Tutorial/Java/0410__Web-
final TreeItem[] lastItem = new TreeItem[1];
Services-SOA/Catalog0410__Web-
final TreeEditor editor = new TreeEditor(tree);
Services-SOA.htm)
tree.addListener(SWT.Selection, new Listener() {
EJB3 public void handleEvent(Event event) {
(/Tutorial/Java/0415__EJB3/Catalo final TreeItem item = (TreeItem) event.item;
g0415__EJB3.htm) if (item != null && item == lastItem[0]) {
Spring boolean isCarbon = SWT.getPlatform().equals("carbon");
(/Tutorial/Java/0417__Spring/Catal final Composite composite = new Composite(tree, SWT.NONE);
og0417__Spring.htm) if (!isCarbon)
PDF composite.setBackground(black);
(/Tutorial/Java/0419__PDF/Catalog final Text text = new Text(composite, SWT.NONE);
0419__PDF.htm) final int inset = isCarbon ? 0 : 1;
composite.addListener(SWT.Resize, new Listener() {
Email
public void handleEvent(Event e) {
(/Tutorial/Java/0420__Email/Catalo
Rectangle rect = composite.getClientArea();
g0420__Email.htm)
text.setBounds(rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.h
J2ME
- inset * 2);
(/Tutorial/Java/0430__J2ME/Catalo }
g0430__J2ME.htm) });
J2EE Application Listener textListener = new Listener() {
(/Tutorial/Java/0440__J2EE- public void handleEvent(final Event e) {
Application/Catalog0440__J2EE- switch (e.type) {
Application.htm) case SWT.FocusOut:
XML item.setText(text.getText());
(/Tutorial/Java/0440__XML/Catalog composite.dispose();
0440__XML.htm) break;
case SWT.Verify:
Design Pattern
String newText = text.getText();
(/Tutorial/Java/0460__Design-
String leftText = newText.substring(0, e.start);
Pattern/Catalog0460__Design-
String rightText = newText.substring(e.end, newText.length());
Pattern.htm)
GC gc = new GC(text);
Log Point size = gc.textExtent(leftText + e.text + rightText);
(/Tutorial/Java/0480__Log/Catalog gc.dispose();
0480__Log.htm) size = text.computeSize(size.x, SWT.DEFAULT);
Security editor.horizontalAlignment = SWT.LEFT;
(/Tutorial/Java/0490__Security/Cat Rectangle itemRect = item.getBounds(),
alog0490__Security.htm) rect = tree.getClientArea();
Apache Common editor.minimumWidth = Math.max(size.x, itemRect.width) + inset * 2;
(/Tutorial/Java/0500__Apache- int left = itemRect.x,
Common/Catalog0500__Apache- right = rect.x + rect.width;
Common.htm) editor.minimumWidth = Math.min(editor.minimumWidth, right - left);
Ant editor.minimumHeight = size.y + inset * 2;
editor.layout();
(/Tutorial/Java/0520__Ant/Catalog0
break;
520__Ant.htm)
case SWT.Traverse:
JUnit
switch (e.detail) {
(/Tutorial/Java/0540__JUnit/Catalo
case SWT.TRAVERSE_RETURN:
g0540__JUnit.htm) item.setText(text.getText());
// FALL THROUGH
case SWT.TRAVERSE_ESCAPE:
composite.dispose();
e.doit = false;
}
break;
}
}
};
text.addListener(SWT.FocusOut, textListener);
text.addListener(SWT.Traverse, textListener);
text.addListener(SWT.Verify, textListener);
editor.setEditor(composite, item);
text.setText(item.getText());
text.selectAll();
text.setFocus();
}
lastItem[0] = item;
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Les neuf forces de
La Physique du XX e
lhomme - récits des
siecle
confins du Tibet
17.59.Tree Editor
(http://www.java2s.com/Tutorial/Java/0280__SWT/UsingTreeEditor.htm)
17.59.2. Use Text as the Table Cell Editor
(/Tutorial/Java/0280__SWT/UseTextastheTableCellEditor.htm)
(http://www.java2s.com/Tutorial/Java/0280__SWT/UseTextastheTableCellEditor.htm
(http://www.java2s.com/Tutorial/Java/0280__SWT/ExchangingData.htm)
(http://www.java2s.com/Tutorial/Java/0280__SWT/AddTreecelleditor.htm)