eclipse插件练习二----Diglog的使用

DiglogSample类:
package com.example.myhello.actions;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class DialogSample extends Dialog{
   
    private String textValue = "我爱JAVA";
    //将Text设为类变量,否则buttonPressed方法无法访问 private Text text;
    private Text text;

    protected DialogSample(Shell parentShell) {
        super(parentShell);
        // TODO Auto-generated constructor stub
    }
   
    protected Control createDialogArea(Composite parent) {
        getShell().setText("标题");
        //设置Dialog的标头
        Text text = new Text(parent, SWT.BORDER);
        //设置一个Text控件
        text.setText("我爱JAVA");
        //设置text中的内容
        return parent;
    }
   
    protected int getShellStyle() {
        return super.getShellStyle() | SWT.RESIZE | SWT.MAX;
    }

}


SimpleAction类:
package com.example.myhello.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;

/**
 * Our sample action implements workbench action delegate.
 * The action proxy will be created by the workbench and
 * shown in the UI. When the user tries to use the action,
 * this delegate will be created and execution will be
 * delegated to it.
 * @see IWorkbenchWindowActionDelegate
 */
public class SampleAction implements IWorkbenchWindowActionDelegate {
    private IWorkbenchWindow window;
    /**
     * The constructor.
     */
    public SampleAction() {
    }

    /**
     * The action has been activated. The argument of the
     * method represents the 'real' action sitting
     * in the workbench UI.
     * @see IWorkbenchWindowActionDelegate#run
     */
    public void run(IAction action) {
        DialogSample dialog = new DialogSample(window.getShell());
        dialog.open();
    }
   
   


    /**
     * Selection in the workbench has been changed. We
     * can change the state of the 'real' action here
     * if we want, but this can only happen after
     * the delegate has been created.
     * @see IWorkbenchWindowActionDelegate#selectionChanged
     */
    public void selectionChanged(IAction action, ISelection selection) {
    }

    /**
     * We can use this method to dispose of any system
     * resources we previously allocated.
     * @see IWorkbenchWindowActionDelegate#dispose
     */
    public void dispose() {
    }

    /**
     * We will cache window object in order to
     * be able to provide parent shell for the message dialog.
     * @see IWorkbenchWindowActionDelegate#init
     */
    public void init(IWorkbenchWindow window) {
        this.window = window;
    }
}




这是一个关于用Diglog类的例子,各个方面已经讲解得很清楚了,大家可以参考一下.有不明白的地方,可以留言给我

你可能感兴趣的:(eclipse,职场,插件,休闲,Diglog)