锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 鍘熸潵鍦ㄩ潤鎬佷唬鐮佸潡涓婂嚭鐜頒簡Exception,閫犳垚鍦ㄨ繍琛宮ain鍑芥暟涔嬪墠灝遍鍑轟簡銆傛墍浠ユ墠璇存病鏈塵ain鍑芥暟銆?br>鎴戜滑鐭ラ亾classload鍦ㄥ姞杞戒竴涓被鐨勬椂鍊欙紝瀵逛簬闈欐佷唬鐮佸潡浼氶愯鎵ц錛屾寜鐓у嚭鐜扮殑鍏堝悗欏哄簭銆傚悓鏃剁埗綾葷殑闈欐佷唬鐮佸潡涓瀹氭瘮瀛愮被鐨勫厛鎵ц銆傚洜涓?br>鍦╨oad瀛愮被涔嬪墠浼氬厛load鐖剁被銆傝繖灝辨槸涓轟粈涔坔ello world涓笉浼氬嚭鐜伴棶棰橈紝榪欓噷浼氬嚭鐜伴棶棰樼殑鍘熷洜銆傚洜涓篋ialog姣擜pplicationWindow澶氫簡榪欐闈欐佷唬鐮併?/p>
緇х畫榪戒笅鍘諱負浠涔堣繖孌典唬鐮佷細鍑虹幇絀烘寚閽堝紓甯稿憿錛屽師鏉ヨ繖孌典唬鐮佷緷璧栦簬new Shell()蹇呴』鍏堣繍琛屻傝屾垜浠殑new Shell()鍐欏湪main鏂規硶閲岃竟錛岃偗瀹氭槸鍦ㄥ姞杞界被瀹屾垚鍚庢墠鑳借繍琛岀殑銆傛墍浠ュ湪綾誨唴閮ㄧ洿鎺ュ啓涓猰ain鏂規硶鏄笉琛岀殑銆傚彧鑳藉崟鐙啓涓被鏉ヨ皟鐢ㄣ?br>鏂規硶浜岋細 2錛岃繖鍥涗釜鐨勪笉鍚屼箣澶勬湁涓夌偣錛?br> 鎻愮ず鐨勫浘鏍囥?nbsp; 鏄劇ず鐨勬寜閽?nbsp; 榪斿洖鍊?br>openInfomation 綾諱技i鐨勫浘鏍?nbsp; 涓涓‘瀹?nbsp; void 鏈鍚庤涓涓嬶紝MessageDialog鐨勫ぇ灝忎笉鑳芥牴鎹唴瀹硅嚜鍔ㄨ皟鏁達紝瀵逛簬灝戦噺鎻愮ず淇℃伅鐨勬椂鍊欐樉寰楀ぇ浜嗕簺銆?br>3錛孖nputDialog杈撳叆鐨刣ialog 鍋氳繃SWT寮鍙戠殑浜哄榪欑鏍煎紡搴旇涓嶉檶鐢燂紝鍒板閮芥槸銆?br> 鎸夐挳鐨勭粍鍚堬細
http://m.tkk7.com/Files/dreamstone/eclipse1.part2.rar
http://m.tkk7.com/Files/dreamstone/eclipse1.part3.rar
http://m.tkk7.com/Files/dreamstone/eclipse1.part4.rar
http://m.tkk7.com/Files/dreamstone/eclipse1.part5.rar
http://m.tkk7.com/Files/dreamstone/eclipse1.part6.rar
璋冪敤榪欎釜鎺ュ彛鐨剅efreshLocal鏂規硶鍗沖彲銆備緥濡俽efreshLocal(IResource.DEPTH_INFINITE, null)
2銆佸埌搴曟湁鍝簺綾誨疄鐜頒簡榪欎釜鎺ュ彛鍛?
鏉ョ湅涓涓嬬戶鎵跨粨鏋?br>棣栧厛緇ф壙鑷狪Resource鐨勬帴鍙f湁IContainer銆両Folder銆両Project銆両WorkspaceRoot銆両File涓鍏?涓?br>鍔犱笂IResource 6涓紝鍑℃槸瀹炵幇榪欎簺鎺ュ彛鐨勯兘鍙互銆?br>3銆佹帴鍙g殑緇ф壙緇撴瀯
鎺ュ彛 extends
IResource 鏃?nbsp;
IContainer IResource
IFile IResource
IFolder IContainer
IProject IContainer
IWorkspaceRoot IContainer
4銆佺被鐨勭戶鎵跨粨鏋?/span>
綾?nbsp; extends implements
Resource 鏃?nbsp; IResource
Container Resource IContainer
File Resource IFile
Folder Container IFolder
Project Container IProject
WorkspaceRoot Container IWorkspaceRoot
浜屻佸疄鐜伴噸緙栬瘧(涔熷氨鏄痗lean)
clean all:
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD,
monitor);
clean one project
((IProject) selection[i]).build(IncrementalProjectBuilder.CLEAN_BUILD, new
SubProgressMonitor(monitor, 1));
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TestProgress
{
static boolean stopflg = false;
/** *//**
* Launch the application
* @param args
*/
public static void main(String[] args) throws Exception
{
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
//
IRunnableWithProgress runnable = new IRunnableWithProgress()
{
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
monitor.beginTask("generate", 30);
for(int i=0;i<100;i++)
{
if(monitor.isCanceled())
{
return;
}
monitor.worked(1);
Thread.sleep(50);
}
monitor.done();
}
};
new ProgressMonitorDialog(shell).run(true, true, runnable);
shell.open();
shell.layout();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
}
}
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TestProgress
{
static boolean stopflg = false;
/** *//**
* Launch the application
* @param args
*/
public static void main(String[] args) throws Exception
{
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
//
IRunnableWithProgress runnable = new IRunnableWithProgress()
{
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
monitor.beginTask("generate", 30);
int i=0;
while(true)
{
if(stopflg)
{
break;
}
i++;
if(i==30)
{
i=0;
monitor.beginTask("generate", 30);
}
monitor.worked(1);
Thread.sleep(100);
}
monitor.done();
}
};
new ProgressMonitorDialog(shell).run(true, true, runnable);
shell.open();
shell.layout();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
}
}
public void saveState()
{
if (text.getText() == null || text.getText().equals(""))
{
return ;
}
IDialogSettings topSettings = getTopSettings();
IDialogSettings settings = topSettings.getSection("TestDialog");
if(settings == null)settings = topSettings.addNewSection("TestDialog");
settings.put("value", text.getText());
try
{
topSettings.save("content/system.xml");
}catch(IOException e)
{
System.out.println(e.getMessage());
}
}
public void restoreState()
{
IDialogSettings topSettings = getTopSettings();
IDialogSettings settings = topSettings.getSection("TestDialog");
if(settings == null) return;
if (text.getText() == null || text.getText().equals(""))
{
text.setText(settings.get("value"));
}
}
public IDialogSettings getTopSettings()
{
IDialogSettings topSettings = new DialogSettings("system");
try
{
topSettings.load("content/system.xml");
}catch(IOException e)
{
System.out.println(e.getMessage());
}
return topSettings;
}
鐒跺悗鍦ㄨ鍐欑殑buttonPressed鍑芥暟涓皟鐢╯ave
protected void buttonPressed(int button)
{
saveState();
}
protected Control createDialogArea(Composite parent)
{
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new RowLayout());
text = new Text(container, SWT.BORDER);
text.setLayoutData(new RowData(100,-1));
//鍔犲叆榪欎竴鍙?/span>
if (text.getText() == null || text.getText().equals(""))
{
restoreState();
}
return container;
}
source涓嬭澆:http://m.tkk7.com/Files/dreamstone/jface-record.rar
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Shell;
public class TestDialog extends Dialog
{
public TestDialog(Shell parentShell)
{
super(parentShell);
}
}
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Test
{
public static void main(String[] args)
{
Shell shell = new Shell();
TestDialog td = new TestDialog(shell);
td.setBlockOnOpen(true);
td.open();
Display.getCurrent().dispose();
}
}
浜屻佺湅鍒頒笂杈圭殑浠g爜鏄惁浼氭兂鍒板埆鐨勫憿錛熶負浠涔堣鍐嶅啓涓涓被鏉ヨ繍琛孌ialog,涓嶈兘鍦ㄥ唴閮ㄥ啓涓猰ain鏂規硶鍚楋紵
鎴戜滑鏉ヨ瘯涓涓嬶細
鏂規硶涓錛氬弬鑰僇face hello world鐨勭殑鍐欐硶:
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TestDialog extends Dialog
{
public TestDialog(Shell parentShell)
{
super(parentShell);
}
public static void main(String[] args)
{
TestDialog td = new TestDialog(new Shell());
td.setBlockOnOpen(true);
td.open();
Display.getCurrent().dispose();
}
}
榪愯涓涓嬬湅鐪嬩粈涔堟晥鏋滐紝鎻愮ず鎵句笉鍒癿ain鏂規硶銆備笖鎵撳嵃鍑哄涓婨xception
java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:184)
at org.eclipse.jface.resource.JFaceResources.getImageRegistry(JFaceResources.java:310)
at org.eclipse.jface.dialogs.Dialog.<clinit>(Dialog.java:211)
Exception in thread "main"
涓轟粈涔堝憿錛熸垜浠槸鏈塵ain鏂規硶鐨勶紝璺熻繘Exception鍘葷湅鐪嬪惂銆?br>鍙戠幇闂鍑虹幇鍦―ialog綾葷殑榪欐浠g爜涓?
static
{
ImageRegistry reg = JFaceResources.getImageRegistry();
reg.put(DLG_IMG_MESSAGE_INFO, ImageDescriptor.createFromFile(
Dialog.class, "images/message_info.gif")); //$NON-NLS-1$
reg.put(DLG_IMG_MESSAGE_WARNING, ImageDescriptor.createFromFile(
Dialog.class, "images/message_warning.gif")); //$NON-NLS-1$
reg.put(DLG_IMG_MESSAGE_ERROR, ImageDescriptor.createFromFile(
Dialog.class, "images/message_error.gif")); //$NON-NLS-1$
}
鍗曠嫭鍐欎釜綾誨涓嬶細import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Test
{
public static void main(String[] args)
{
TestDialog td = new TestDialog(new Shell());
td.setBlockOnOpen(true);
td.open();
Display.getCurrent().dispose();
}
}
涓夈佸幓鎺変袱涓寜閽?br>铏界劧Dialog澶╃敓甯︾殑涓や釜鎸夐挳涓嶉敊錛屼絾鎴戜滑鏈夌殑鏃跺欏茍涓嶆兂瑕佽繖涓や釜鎸夐挳錛屾庝箞鍔烇紝濡備綍鍘繪帀瀹冿紵
綆鍗曪紝鍙鎴戜滑瑕嗙洊鐖剁被鐨刢reateButtonsForButtonBar榪欎釜鏂規硶灝卞彲浠ヤ簡錛岃鍐欒繖涓柟娉曪紝閲岃竟浠涔堜篃涓嶅啓
protected void createButtonsForButtonBar(Composite parent)
{
}
鐪嬩竴涓嬫寜閽秷澶變簡銆?br>鍥涖佸姞鍏ュ彸涓婅鐨勬渶澶у寲鍜屽叧闂?br>瑕嗗啓鐖剁被鐨勮繖涓柟娉曪細
protected int getShellStyle()
{
return super.getShellStyle()|SWT.RESIZE|SWT.MAX;
}
浜斻佹敼鍙楧ialog鐨勫ぇ灝?br>瑕嗗啓榪欎釜鏂規硶錛?br>
protected Point getInitialSize()
{
return new Point(300,400);//300鏄400鏄珮
}
瑕嗗啓createDialogArea鏂規硶
protected Control createDialogArea(Composite parent)
{
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new RowLayout());
text = new Text(container, SWT.BORDER);
text.setLayoutData(new RowData(100,-1));
return container;
}
榪欓噷浣跨敤浜哛owLayout
涓冦佸姞鍏ヨ嚜宸辯殑鎸夐挳
瑕嗗啓initializeBounds
protected void initializeBounds()
{
Composite comp = (Composite)getButtonBar();
super.createButton(comp, IDialogConstants.OK_ID, "瀹屾垚", true);
}
浣跨敤鏂規硶鍜屽墠杈圭浉鍚岋紝涓嶅悓鐨勬槸涓嶆槸緇ф壙鑷狣ialog鑰屾槸緇ф壙鑷猅itleAreaDialog錛岀劧鍚庡湪createDialogArea涓姞鍏ヤ袱琛?br>
setTitle("鏍囬");
setMessage("鎻愮ず淇℃伅")
//setMessage鍙互鍔犱笂鍥劇墖錛屽姞鍏ョ殑鍔炴硶鏄痵etMessage("鎻愮ず淇℃伅",IMessageProvider.WARNING);濡傛灉鎯沖姞鍏ュ叾浠栫殑鍥劇墖錛岃皟鐢ㄧ浉搴旂殑甯擱噺銆?/span>
source涓嬭澆:http://m.tkk7.com/Files/dreamstone/jface-dialog.rar
涓銆丮essageDialog
1,MessageDialog鐨勭敤娉曞緢綆鍗曪紝鍙渶瑕佷竴鍙ヨ瘽.
MessageDialog.openInfomation(shell,title,message);
MessageDialog.openConfirm(shell,title,message);
MessageDialog.openQuestion(shell,title,message);
MessageDialog.openError(shell,title,message);
openConfirm 闂彿鍥炬爣 紜畾鍜屽彇娑?nbsp; boolean
openQuestion 闂彿鍥炬爣 鏄拰鍚?nbsp; boolean
openError 涓涓猉鐨勫浘鏍?nbsp; 紜畾 void
浣跨敤鏂規硶錛?/p>
InputDialog inputDialog = new InputDialog(shell,"鏍囬","鎻愮ず淇℃伅","榛樿鍊?/span>",null);
if(inputDialog.open() == InputDialog.OK)
{
String value = dialog.getValue();
}
public class MyValidator implements IInputValidaor
{
public String isValid(String newText)
{
float value = 0;
try
{
value = Float.valueOf(newText).floatValue();
}catch(NumberFormatException e)
{
return "閿欒:璇瘋緭鍏ユ暟鍊?/span>";
}
if(value>0 && value<100)
{
return null;
}else
{
return "閿欒錛氳杈撳叆澶т簬0錛屽皬浜?00鐨勬暟";
}
}
}
鐒跺悗鏀瑰啓瀹氫箟璇彞涓?br>
InputDialog inputDialog = new InputDialog(shell,"鏍囬","鎻愮ず淇℃伅","榛樿鍊?/span>",new MyValidator());
鍚屾牱緇ф壙鑷狣ialog.
1,浣跨敤鏂規硶錛歁essageBox鐨勪嬌鐢ㄦ柟娉曠◢寰鏉傦紝闇瑕?鍙?
MessageBox mb = new MessageBox(shell);
mb.setMessage("鎻愮ず淇℃伅");
mb.open();
鏄氳繃new鐨勬椂鍊欏姞鍏ュ紡鏍鋒潵瀹炵幇鐨勶紝渚嬪
MessageBox mb = new MessageBox(shell,SWT._ICON_QUEST|SWT.YES|SWT.NO);
鍥炬爣鐨勭綾伙細
SWT.ICON_ERROR
SWT.ICON_INFORMATION
SWT.ICON_QUESTION
SWT.ICON_WARNING
SWT.OK
SWT.OK|SWT.CANCEL
SWT.YES|SWT.NO
SWT.YES|SWT.NO|SWT.CANCEL
SWT.RETRY|SWT.CANCEL
SWT.ABORT|SWT.RETRY|SWT.IGNORE
浠旂粏鐪嬩竴涓嬪氨鏄垜浠鉤鏃剁粡甯哥湅鍒扮殑鍚勭瀵硅瘽妗嗐?br>涓夈侀鑹查夋嫨瀵硅瘽妗?br>涓嶅璇達紝浣跨敤鏂規硶鍑犱箮鍦╯wt涓亶鍦伴兘鏄殑鐢ㄦ硶銆?br>ColorDialog dialog = new ColorDialog(shell);
RGB rgb = dialog.open();
if(rgb != null)
{
Color color = new Color(shell.getDisplay(),rgb);
}
娉ㄦ剰color浣跨敤榪囧悗瑕乨ispose();
鍥涖佸瓧浣撻夋嫨瀵硅瘽妗?br>鏈変簡涓婅竟鐨勪竴浜涚粡楠屽叾瀹炲湪鏈塭clipse榪欑緙栬緫鍣ㄧ殑甯姪涓嬬寽鐫灝卞彲浠ュ啓浜?br>
FontDialog dialog = new FontDialog(shell);
FontData fontData = dialog.open();
if (fontDate != null)
{
Font font = new Font(shell.getDisplay(),fontData);
}
鍚屾牱鍦ㄧ粨鏉熷悗font.dispose();
浜斻佹墦鍗板璇濇錛屽悓涓婄殑浣跨敤鏂規硶錛屽悓涓婄殑闇瑕乨ispose
PrintDialog dialog = new PrintDialog(shell);
PrintData printData = dialog.open();
if (printDate != null)
{
Printer printer = new Printer(printerData);
}
鍏佹枃浠墮夋嫨瀵硅瘽妗嗭細鍚屼笂
1錛屽疄鐜版柟娉?br>
FileDialog dialog = new FileDialog(shell,SWT.OPEN);
dialog.setFilterPath("c:\windows");//璁劇疆鍒濆璺緞
String fileName = dialog.open();//榪斿洖鐨勫叏璺緞(璺緞+鏂囦歡鍚?
FileDialog dialog = new FileDialog(shell,SWT.OPEN|SWT.MULTI);
String fileName = dialog.open();//榪斿洖鏈鍚庝竴涓夋嫨鏂囦歡鐨勫叏璺緞
String[] fileNames = dialog.getFileNames();//榪斿洖鎵鏈夐夋嫨鐨勬枃浠跺悕錛屼笉鍖呮嫭璺緞
String path = dialog.getFilterPath();榪斿洖閫夋嫨鐨勮礬寰勶紝榪欎釜鍜宖ileNames閰嶅悎鍙互寰楀埌鎵鏈夌殑鏂囦歡鐨勫叏璺緞
FileDialog dialog = new FileDialog(shell,SWT.OPEN|SWT.NULTI);
dialog.setFilterNames(new String[]
{"鍙墽琛屾枃浠?*.exe),"Excel(*.xls),"鎵鏈夋枃浠?/span>""});
dialog.setFilterExtensions(new String[]
{"*.exe","*.xls","*.*"});
//鎺ュ彈鏂規硶鍚?涓殑鍐欐硶錛屼笉鍚屽氨鏄姞鍏ヤ簡榪囨護鍣ㄣ?/span>
FileDialog dialog = new FileDialog(shell,SWT.SAVE);
String fileName = dialog.open();
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TestListViewer
{
static class ListLabelProvider extends LabelProvider
{
public String getText(Object element)
{
Country country = (Country)element;
return country.getName();
}
public Image getImage(Object element)
{
return null;
}
}
static class ContentProvider implements IStructuredContentProvider
{
public Object[] getElements(Object inputElement)
{
if(inputElement instanceof List)
{
List list = (List)inputElement;
return list.toArray();
}
return new Object[0];
}
public void dispose()
{
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
{
}
}
static class Country
{
private String name;
public Country()
{
}
public Country(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public static List getCountryList()
{
List list = new ArrayList();
list.add(new Country("涓浗"));
list.add(new Country("緹庡浗"));
list.add(new Country("鏃ユ湰"));
return list;
}
}
private static org.eclipse.swt.widgets.List list;
/** *//**
* Launch the application
* @param args
*/
public static void main(String[] args)
{
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
//
shell.open();
final ListViewer listViewer = new ListViewer(shell, SWT.BORDER);
listViewer.setLabelProvider(new ListLabelProvider());
listViewer.setContentProvider(new ContentProvider());
listViewer.setInput(new Object());
list = listViewer.getList();
list.setBounds(122, 63, 100, 100);
listViewer.setContentProvider(new ContentProvider());
listViewer.setLabelProvider(new ListLabelProvider());
listViewer.setInput(Country.getCountryList());
//鍙互鐩存帴娣誨姞
listViewer.add(new Country("鑻卞浗"));
shell.setLayout(new FillLayout());
shell.layout();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
}
}
浜屻佹敞鎰忎唬鐮佺殑娉ㄩ噴閮ㄥ垎錛屽彲浠ョ洿鎺ユ坊鍔犲拰縐婚櫎銆?
閿欒浜岋細
鎸夌収鏁欑▼鐨勬搷浣滐紝緇撴灉鍑虹幇閿欒
org.eclipse.ui.PartInitException: Unable to open editor, unknown editor ID:
媯鏌ヤ綘鐨刾lugin.xml涓殑榪欎竴孌?br><extension
point="org.eclipse.ui.editors">
<editor
class="gef.tutorial.step.ui.DiagramEditor"
default="false"
icon="icons/alt_about.gif"
id="gef.tutorial.step.ui.DiagramEditor"
name="Diagram Editor"/>
</extension>
鏄惁鏈塱con=""錛屾垜寮濮嬩互涓烘病鏈塱con娌′粈涔堟墍浠ユ病閰嶇疆錛岀粨鏋滀竴鐩村嚭閿欙紝閰嶄笂灝卞ソ浜嗐傛劅瑙夎繖涓仛鐨勭湡
璁╀漢閮侀椃錛岃繕蹇呴』鏈塱con
1,Ctrl+D 鍒犻櫎閫変腑鐨勫嚑琛?br>2,Alt+涓婁笅綆ご 縐誨姩閫変腑鐨勪唬鐮佸潡
3,Alt+宸﹀彸綆ご 鍥為 鍓嶈繘
4,Alt+Shift+涓婁笅綆ご 澶嶅埗閫変腑鐨勪唬鐮佸潡
5,sysout+Ctrl space 鐢熸垚System.out.println();
6,main + Ctrl space 鐢熸垚鏈綆鍗曠殑main鍑芥暟
7,Ctrl+Shift+X 鍒囨崲鎴愬ぇ鍐?br>8,Ctrl+Shift+Y 鍒囨崲鎴愬皬鍐?br>9,Ctrl+Z 鍙栨秷undo
10,Ctrl+Y redo
11,Ctrl+S 淇濆瓨
12,Tab 鍧楃緝榪?br>13,Shift+Tab 鍙嶅悜鍧楃緝榪?br>14,Ctrl+Shif+F 鏍煎紡鍖栦唬鐮?br>15,Ctrl+O 鏄劇ず鎴愬憳鏂規硶 ,鎴愬憳瀵硅薄
16,Ctrl+Shift+I 璋冭瘯鐨勬椂鍊欐樉紺哄璞$殑鍊?br>17,Ctrl+M 鍏ㄥ睆
18,Ctrl+N 鏂板緩
19,Ctrl+L 榪涘叆鍒扮N琛?br>20,Ctrl+/ 娉ㄩ噴鎵撳紑浠g爜
21,Ctrl+Shift+/ 鍧楁敞閲?br>22,Ctrl+Shift+\ 鍧楁敞閲婂彇娑?br>23,Ctrl+1 綰犳浠g爜
24,F3 鏄劇ず緇ф壙鏍?br>25,Ctrl+F 鏌ユ壘鏇挎崲
26,Ctrl+H 鏇村ぇ鑼冨洿鐨勬煡鎵炬浛鎹?br>27,F5 Step into
28,F6 Step over
29,F7 Step return
30,F8 resume
public Image getImage(Object obj) {
// String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
if (obj instanceof Kind) {
String imageKey = ISharedImages.IMG_OBJ_FOLDER;
PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
}
return null;
}
}
class KindContentProvider implements IStructuredContentProvider,
ITreeContentProvider {
public Object[] getElements(Object parent) {
if(parent instanceof Kind){
return getChildren(parent);
}
return null;
}
public Object getParent(Object child) {
if (child instanceof Node) {
return ((Node) child).getParent();
}
return null;
}
public Object[] getChildren(Object parent) {
if (parent instanceof Kind) {
ArrayList children = ((Kind) parent).getChildren();
return children.toArray(new Node[children.size()]);
}
return new Object[0];
}
public boolean hasChildren(Object parent) {
if (parent instanceof Kind)
return ((Kind) parent).hasChildren();
return false;
}
public void dispose() {
// TODO Auto-generated method stub
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// TODO Auto-generated method stub
}
}
涓錛屾坊鍔犱竴涓璇濇紿楀彛錛氭坊鍔犱竴涓被濡備笅錛岀劧寰屽湪欏昏鏄捐鐨勫湴鏂硅皟鐢ㄤ竴涓媜pen()鏂規硶
涓嶄竴瀹氶潪瑕佺戶鎵胯嚜Dialog,榪欓噷涓轟簡娓愬皯涓浜涗唬鐮?鑰屼笖鎴戜嬌鐢ㄤ腑涔熷緇ф壙鑷狣ialog
package hellorcp;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class HelloDialog extends Dialog {
protected Object result;
protected Shell shell;
public HelloDialog(Shell parent, int style) {
super(parent, style);
}
public HelloDialog(Shell parent) {
this(parent, SWT.NONE);
}
public Object open() {
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
return result;
}
protected void createContents() {
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setSize(500, 375);
shell.setText("SWT Dialog");
//
}
}
浜岋紝娣誨姞涓涓獀iewer錛岄鍏堝緩绔嬩竴涓獀iewer,涓嬭竟鏄疍esigner錛堜竴涓緢濂界敤鐨勬彃浠訛級鑷姩鐢熸垚鐨勪竴涓獀iewer錛?br>涔熷氨鏄竴涓猇iewer鐨勫ぇ姒傜粨鏋?br>package hellorcp;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
public class HelloView extends ViewPart {
public static final String ID = "hellorcp.HelloView"; //$NON-NLS-1$
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
//
createActions();
initializeToolBar();
initializeMenu();
}
private void createActions() {
// Create the actions
}
private void initializeToolBar() {
IToolBarManager toolbarManager = getViewSite().getActionBars()
.getToolBarManager();
}
private void initializeMenu() {
IMenuManager menuManager = getViewSite().getActionBars()
.getMenuManager();
}
public void setFocus() {
// Set the focus
}
}
鏄捐榪欎釜viewer,姣忎釜viewer欏昏鍔犺澆鍒皃erspective涓婃墠鑳芥樉瑙嗭紝鎵浠ュ湪Perspective.java涓姞鍏ュ涓嬩唬鐮?br>public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(false);//涓嶆樉瑙唀dit紿楀彛
String editorArea = layout.getEditorArea();
//涓嬭竟涓ゅ彞鐨勪笉鍚屾槸錛屼竴涓樉瑙嗙殑鏄崟欏電獥鍙o紝涓涓樉瑙嗙殑鏄欏電獥鍙?br> layout.addStandaloneView(HelloViewer.ID,false, IPageLayout.LEFT, 0.25f, editorArea);
layout.addView(HelloViewer.ID, IPageLayout.RIGHT, 0.75f, editorArea);
锝?/p>
涓夛紝鍦╲iewer鎴栬卍ialog涓婃坊鍔犳帶浠訛紝濡傛灉瑁呮湁Designer鍙互鐩存帴鎷栨斁錛屽鏋滄病鏈夌紪紼嬪疄鐜頒篃鍙互
澶ч儴浠芥坊鍔犲埌涓嬭竟榪欐牱鐨勫嚱鏁頒腑
viewer:
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
//娣誨姞涓涓猙utton
final Button delBtn = new Button(container, SWT.NONE);
delBtn.setText("鍒犻櫎");
delBtn.setBounds(10, 83, 44, 22);
addListener2DelBtn(delBtn);
createActions();
initializeToolBar();
initializeMenu();
}
dialog:
protected void createContents() {
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setSize(500, 375);
shell.setText("SWT Dialog");
}
鍥涳紝鍝嶅簲浜嬩歡,SWT鐨勪簨浠跺搷搴斿拰Swing鏄竴鏍風殑錛屾坊鍔爈istener
delBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
//鍔犲叆浣犲搷搴斾簨浠惰鍋氱殑浜嬫儏
}
});
浜旓紝甯冨眬
甯冨眬鏂歸潰swt娌℃湁浠涔堟柊鐨勫湴鏂癸紝鍙戜釜綆鍗曚嬌鐢ㄥ竷灞鐨勪緥瀛愶紝鍙傝冨惂.鍙﹀甯冨眬榪樻湁寰堝鎼厤錛屼絾涓嶆槸鏈枃鐨?br>閲嶇偣錛屾殏鏃跺甫榪?br>import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class TableDemo {
/**
* @param args
*/
public static void main(String[] args) {
Display dispMain = new Display ();
final Shell shellMain = new Shell (dispMain, SWT.TITLE | SWT.MIN | SWT.BORDER);
shellMain.setText("Table Demo");
FormLayout formLayout = new FormLayout();
formLayout.marginLeft = 10;
formLayout.marginRight = 10;
formLayout.marginTop = 10;
formLayout.marginBottom = 10;
formLayout.spacing = 10;
shellMain.setLayout(formLayout);
shellMain.setSize(800, 600);
Point size = shellMain.getSize();
Rectangle rect = dispMain.getBounds();
shellMain.setLocation(rect.x + (rect.width-size.x)/2, rect.y + (rect.height-size.y)/2);
Table demoTable = (Table)createContents(shellMain);
FormData formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.top = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.bottom = new FormAttachment(100, -34);
demoTable.setLayoutData(formData);
Button btnClose = new Button(shellMain, SWT.PUSH | SWT.FLAT);
btnClose.setText("close");
formData = new FormData();
formData.right = new FormAttachment(100, 0);
formData.top = new FormAttachment(demoTable, 0);
formData.width = 100;
formData.bottom = new FormAttachment(100, 0);
btnClose.setLayoutData(formData);
btnClose.addSelectionListener(
new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
this.widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
shellMain.close();
}
}
);
shellMain.open ();
while (!shellMain.isDisposed ()) {
if (!dispMain.readAndDispatch ()) {
dispMain.sleep ();
}
}
dispMain.dispose ();
dispMain = null;
}
/**
*
* @param shellMain
* @return
*/
private static Table createContents(Shell shellMain) {
Table table = new Table(shellMain, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setFont(new Font(shellMain.getDisplay(), "Arial", 11, SWT.BOLD));
TableColumn colNumber = new TableColumn(table, SWT.NONE);
TableColumn colMedName = new TableColumn(table, SWT.CENTER);
TableColumn colPrice = new TableColumn(table, SWT.CENTER);
TableColumn colUnit = new TableColumn(table, SWT.CENTER);
TableColumn colCount = new TableColumn(table, SWT.CENTER);
colNumber.setWidth(25);
colMedName.setWidth(150);
colMedName.setText("Medicine Name");
colPrice.setWidth(150);
colPrice.setText("Medicine Price");
colUnit.setWidth(150);
colUnit.setText("Medicine Unit");
colCount.setWidth(150);
colCount.setText("Medicine Count");
for(int i=0; i<10; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[]{i+1+"","4/2","4/3","4/4","4/5","4/6","4/7","4/8","4/9"});
}
return table;
}
}
浜旓紝鍔犲叆 鍙抽敭 錛屽弻鍑?br>鍔犲叆涓や釜listener
//鍙抽敭
private void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
HelloView.this.fillContextMenu(manager);
}
});
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, viewer);
}
private void fillContextMenu(IMenuManager manager) {
manager.add(addAction);
manager.add(modifyAction);
manager.add(deleteAction);
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
//鍙屽嚮
private void hookDoubleClickAction() {
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
//doubleClickAction.run();
}
});
}
鍏紝浣跨敤TableViewer
Jface涓皝瑁呬簡talbeViewer TreeViewer絳夋帶浠訛紝鑳界畝鍗曠殑瀹炵幇寰堝鍔熻兘錛岄鍏堣璇碩ableView
//SWT.FULL_SELECTION 鍙互閫変腑涓鏁磋
//SWT.MULTI 鍙互閫変腑澶氳
viewer = new TableViewer(wareListGroup, SWT.BORDER | SWT.FULL_SELECTION
| SWT.MULTI);
final Table table = viewer.getTable();
table.setHeaderVisible(true);//鏄捐琛ㄥご
table.setLinesVisible(true);//鏄捐琛ㄦ牸
//瀹炵幇鐐瑰嚮琛ㄥご鑷姩閲嶆柊鎺掑簭
final TableColumn num = new TableColumn(table, SWT.NONE);
num.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
resetSort(WareViewerSort.NUM);
//resetSort鏄嚜宸卞疄鐜扮殑閲嶆柊鎺掑簭鐨勫嚱鏁幫紝鍙』瑕佹妸涓嶉氱殑ViewerSort閲嶆柊璁劇疆緇?br> TableViewer錛屽茍鍒鋒柊
}
});
num.setAlignment(SWT.CENTER);
num.setWidth(50);
//榪欎釜鍦版柟浣跨敤浜唌essage錛屽彧瑕佸仛榪囧浗闄呰瘽鐨勫ぇ姒傞兘鑳芥槑鐧?br> num.setText(Messages.getString("HelloView.warenum")); //$NON-NLS-1$
final TableColumn name = new TableColumn(table, SWT.NONE);
name.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
resetSort(WareViewerSort.NAME);//鍚屼笂
}
});
name.setWidth(80);
name.setText(Messages.getString("WareView.warename")); //$NON-NLS-1$
name.setAlignment(SWT.CENTER);
final TableColumn desc = new TableColumn(table, SWT.NONE);
desc.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
resetSort(WareViewerSort.DESC);
}
});
desc.setWidth(110);
desc.setText(Messages.getString("WareView.waredesc")); //$NON-NLS-1$
final TableColumn price = new TableColumn(table, SWT.NONE);
price.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
resetSort(WareViewerSort.PRICE);
}
});
price.setWidth(70);
price.setText(Messages.getString("WareView.wareprice")); //$NON-NLS-1$
price.setAlignment(SWT.RIGHT);
final TableColumn updDate = new TableColumn(table, SWT.NONE);
updDate.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
resetSort(WareViewerSort.UPDDATE);
}
});
updDate.setWidth(150);
updDate.setText(Messages.getString("WareView.wareupddate")); //$NON-NLS-1$
updDate.setAlignment(SWT.CENTER);
//涓涓猅ableViewer閲岃竟鐨勬暟鎹彉鍔ㄤ富瑕佸彇鍐充簬涓嬭竟鍥涘彞
viewer.setContentProvider(new WareContentProvider()); //琛ㄧ殑鏄捐
viewer.setLabelProvider(new WareLabelProvider()); //琛ㄧ殑鏁版嵁鎻愪緵鑰?/p>
viewer.setInput(//鐪熷疄鐨勬暟鎹潵婧?; //鏁版嵁鏉ユ簮渚嬪ArrayList絳?br> viewer.setSorter(new WareViewerSort()); //鎺掑簭
涓や釜provider鐨勫疄鐜扮被浼間笅杈圭殑鎯呭喌
class WareContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
if (inputElement instanceof Node) {
ArrayList list = new ArrayList();
makeWareList(((Node) inputElement), list);
return list.toArray();
}
if (inputElement instanceof List) {
return ((List) inputElement).toArray();
}
return null;
}
public void dispose() {
// TODO Auto-generated method stub
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// TODO Auto-generated method stub
}
}
class WareLabelProvider extends LabelProvider implements
ITableLabelProvider {
public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}
public String getColumnText(Object element, int columnIndex) {
if (element instanceof Ware) {
switch (columnIndex) {
case 0:
return ((Ware) element).getDisplayNum();
case 1:
return ((Ware) element).getDisplayName();
case 2:
return ((Ware) element).getDisplayDesc();
case 3:
return ((Ware) element).getDisplayPrice();
case 4:
return ((Ware) element).getDisplayUpdDate();
default:
break;
}
}
return null;
}
}
鏂板緩 ->project->plug-in Development->plug-in project
鐐瑰嚮 next
杈撳叆宸ョ▼鍚?/span> HelloRcp à next
閫夋嫨 Hello Rcp à Finish
宸ョ▼寤虹珛瀹屾瘯錛屼笅杈歸夋嫨 MANIFEST.MF
鐐瑰嚮涓嬭竟鐨?/span> overview 榪涘叆 overview 瑙嗗浘錛岀偣鍑?/span> Launch an Eclipse application
灝卞彲浠ョ湅鍒拌繍琛岃搗鏉ョ殑鐣岄潰浜嗐傚氨浣夸竴涓畝鍗曠殑紿楀彛銆?/span>
濂斤紝涓嬭竟濡備綍瀵煎嚭鑳界被浼?/span> Eclipse 鐨勭▼搴?/span>
鍦?/span> HelloRcp 宸ョ▼涓婄偣鍑誨彸閿?/span> à new à other
閫夋嫨 Product Configuration
鍦ㄤ笁澶勫垎杈ㄥ~鍏ュ搴旂殑鍐呭錛岀劧寰岀偣鍑?/span> Configuration 榪涘叆 configuration 瑙嗗浘
add à 閫夋嫨 HelloRcp
鐐瑰嚮 Add Required Plug-ins
鐒跺緦鐐瑰嚮鍒掔嚎閮ㄥ垎錛屾寜鐓у悜瀵鹼紝瀵煎嚭鎴愪竴涓?/span> Exe 宸ョ▼銆傚弻鍑昏繍琛屼竴涓嬬湅鐪嬪惂銆?/span>
鍙﹀瀵煎嚭鐨勮繖涓伐紼嬪拰 eclipse 涓鏍鳳紝姣斿璇█鍟?/span> -nl 鍙傛暟錛屾瘮濡?/span> jre 鐨勮緗暒 -vm
鏈澶ф渶灝忓唴瀛樹簡錛岄兘鍜?/span> eclipse 鏄竴鏍風殑銆?/span>
濂戒簡錛岃繖涓氨鏄竴涓伐紼嬬殑榪囩▼銆傚墠涓ょ瘒鏂囩珷鍐呭寰堝皯錛岄兘鏄厤鍒舵柟闈㈢殑錛屼笅杈圭殑鏂囩珷寮濮嬬湡鐨勫涓浜涘唴瀹逛簡銆?/span>
濂戒簡錛屽紑濮嬬涓涓▼搴?浠嶩ello world寮濮嬨傚啓鍒拌繖涓湴鏂癸紝鍐嶆宕囨嫓涓涓嬬涓涓啓Hello world鐨勪漢銆?br>鐪熷簲鏀圭粰浠栨惉涓粈涔堟櫘鍙婃暀鑲蹭箣綾葷殑濂栭」銆?br>import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class HelloSWT {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Label label = new Label(shell, SWT.CENTER);
label.setText("Hello, World");
label.setBounds(shell.getClientArea());
shell.open();
while (!shell.isDisposed()){
if (!display.readAndDispatch()){
display.sleep();
}
}
display.dispose();
}
}
棣栧厛浠嬬粛Display錛屾墦瀹墮兘鐭ュ埌Swt鏄熀浜庢搷鍋氱郴緇熺殑錛屽澶ч儴鍒嗙殑鎺с?紿楀彛閮芥槸璋冪敤緋葷粺鐨勶紝鎵浠ュ緱鏈変竴涓笢瑗?br>璐熻矗鎶妀ava鐨勬秷鎭漿鍙樻垚緋葷粺娑堟伅錛孌isplay灝辨槸銆?/p>
Shell鍙互綆鍗曠悊瑙f垚灝辨槸紿楀彛
Label灝辨槸涓涓爣絳句簡銆?/p>
shell.open()鏄捐紿楀彛
while (!shell.isDisposed()){
if (!display.readAndDispatch()){
display.sleep();
}
}
鐔熸倝Windows涓嬬紪紼嬬殑浜哄ぇ姒傞兘鐭ュ埌錛學indows鐨勬秷鎭驚鐜満鍒躲?/p>
濂戒簡璇曠潃榪愯涓涓嬭繖涓▼搴忥紝淇敼涓涓嬶紝鎵炬壘鎰熻鍚с?/p>
鍐欏埌榪欓噷蹇界劧鎯寵搗鑷繁娌℃湁鍐欏浣曢厤鍒禨WT鐨勫紑鍙戠幆澧冿紝瀵逛簬鏂版墜鏉ヨ榪欎釜鏄噸瑕佺殑銆?br>榪欓噷鏈変竴綃囨枃绔?a >http://dev.yesky.com/409/2620409.shtml
濡傛灉閾炬帴澶辨晥鐨勮瘽google涓涓嬪惂
璇存槑錛?br>榪欎釜緋誨垪鐨勬枃绔犳槸鍩轟簬eclipse 3.2.1鐨勶紝鍙﹀鎺ㄨ崘涓浜涘涔犵殑璧勬枡鎴栬呯綉绔?br>棣栧厛錛?a >http://www.eclipseworld.org/bbs/
鐒跺緦錛氬湪涓婅竟鐨勮鍧涢噷杈規湁涓浜涘墠杈堜滑鍐欑殑鏁欑▼錛屾湁浜涗笉閿欏煎緱涓鐪?br>鏈鍚庯細褰撶劧涓嶅彲灝戠殑鏄痠bm鐨勭綉绔欏拰eclipse鐨勫畼鏂圭綉绔?/p>