⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogsview.java

📁 用java 实现的IE browser适合于学者
💻 JAVA
字号:
/*
 * Created on 2005-1-5
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.hnjchina.dialogs;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

/**
 * @author limeiyong
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class dialogsView   extends ViewPart{

	/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
	public void createPartControl(Composite parent) {
		Composite composite = new Composite(parent, SWT.NONE);
	    composite.setLayout(new GridLayout(1, false));

	    Button showerror1 = new Button(composite, SWT.PUSH);
	    showerror1.setText("show error1");
	    showerror1.addSelectionListener(new SelectionAdapter() {
		      public void widgetSelected(SelectionEvent event) {
		      	Status status = new Status(IStatus.ERROR, "Will display", 0, "Error", null);
		      	ErrorDialog dlg = new ErrorDialog(Display.getCurrent().getActiveShell(), "Title", "Message......", status,IStatus.ERROR);
		      	dlg.open();
		      }
		    });

	    Button showerror2 = new Button(composite, SWT.PUSH);
	    showerror2.setText("show error2");
	    showerror2.addSelectionListener(new SelectionAdapter() {
		      public void widgetSelected(SelectionEvent event) {
		      	Status status = new Status(IStatus.ERROR, "Won't display", 0, "Error", null);
		      	ErrorDialog dlg = new ErrorDialog(Display.getCurrent().getActiveShell(), "Title", "Message.......", status,IStatus.INFO);
		      	dlg.open();
		      }
		    });
	    Button InputDialog= new Button(composite, SWT.PUSH);
	    InputDialog.setText("Input Dialog");
	    InputDialog.addSelectionListener(new SelectionAdapter() {
		      public void widgetSelected(SelectionEvent event) {
		      	InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(),
		      		  "Title Text", "This is a message", "", null);
		      	int rc = dlg.open();
		      	if (rc == Window.OK)
		      	  System.out.println(dlg.getValue());
		      	else
		      	  System.out.println("User cancelled");
		      }
		    });
	    
	    final Label label = new Label(composite, SWT.NONE);
	    label.setText("This will display the user input from InputDialog");
	    //Create the button to launch the error dialog
	    Button GetInput = new Button(composite, SWT.PUSH);
	    GetInput.setText("Get Input");
	    GetInput.addSelectionListener(new SelectionAdapter() {
	      public void widgetSelected(SelectionEvent event) {
	        InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(),
	            "", "Enter 5-8 characters", label.getText(), new LengthValidator());
	        if (dlg.open() == Window.OK) {
	          // User clicked OK; update the label with the input
	          label.setText(dlg.getValue());
	        }
	      }
	    });
	    
	    //	  Create a big text box for the message text
	    final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
	    GridData data = new GridData(GridData.FILL_BOTH);
	    data.horizontalSpan = 5;
	    text.setLayoutData(data);
	    // Create the Confirm button
	    Button confirm = new Button(composite, SWT.PUSH);
	    confirm.setText("Confirm");
	    confirm.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	    // Create the Error button
	    Button error = new Button(composite, SWT.PUSH);
	    error.setText("Error");
	    error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	    // Create the Information button
	    Button information = new Button(composite, SWT.PUSH);
	    information.setText("Information");
	    information.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	    // Create the Question button
	    Button question = new Button(composite, SWT.PUSH);
	    question.setText("Question");
	    question.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	    // Create the Warning button
	    Button warning = new Button(composite, SWT.PUSH);
	    warning.setText("Warning");
	    warning.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	    // Create the label to display the return value
	    final Label label1 = new Label(composite, SWT.NONE);
	    data = new GridData(GridData.FILL_HORIZONTAL);
	    data.horizontalSpan = 5;
	    label1.setLayoutData(data);

	    // Save ourselves some typing
	    final Shell shell = Display.getCurrent().getActiveShell();

	    // Display a Confirmation dialog
	    confirm.addSelectionListener(new SelectionAdapter() {
	      public void widgetSelected(SelectionEvent event) {
	        boolean b = MessageDialog.openConfirm(shell, "Confirm", text.getText());
	        label.setText("Returned " + Boolean.toString(b));
	      }
	    });

	    // Display an Error dialog
	    error.addSelectionListener(new SelectionAdapter() {
	      public void widgetSelected(SelectionEvent event) {
	        MessageDialog.openError(shell, "Error", text.getText());
	        label.setText("Returned void");
	      }
	    });

	    // Display an Information dialog
	    information.addSelectionListener(new SelectionAdapter() {
	      public void widgetSelected(SelectionEvent event) {
	        MessageDialog.openInformation(shell, "Information", text.getText());
	        label.setText("Returned void");
	      }
	    });

	    // Display a Question dialog
	    question.addSelectionListener(new SelectionAdapter() {
	      public void widgetSelected(SelectionEvent event) {
	        boolean b = MessageDialog.openQuestion(shell, "Question",
	          text.getText());
	        label.setText("Returned " + Boolean.toString(b));
	      }
	    });

	    // Display a Warning dialog
	    warning.addSelectionListener(new SelectionAdapter() {
	      public void widgetSelected(SelectionEvent event) {
	        MessageDialog.openWarning(shell, "Warning", text.getText());
	        label.setText("Returned void");
	      }
	    });

	    
	    
	    
	    
	    //	  Create the indeterminate checkbox
	    final Button indeterminate = new Button(composite, SWT.CHECK);
	    indeterminate.setText("Indeterminate");
	    // Create the ShowProgress button
	    Button showProgress = new Button(composite, SWT.NONE);
	    showProgress.setText("Show Progress");
	    // Display the ProgressMonitorDialog
	    showProgress.addSelectionListener(new SelectionAdapter() {
	      public void widgetSelected(SelectionEvent event) {
	        try {
	          new ProgressMonitorDialog(shell).run(true, true,
	              new LongRunningOperation(indeterminate.getSelection()));
	        } catch (InvocationTargetException e) {
	          MessageDialog.openError(shell, "Error", e.getMessage());
	        } catch (InterruptedException e) {
	          MessageDialog.openInformation(shell, "Cancelled", e.getMessage());
	        }
	      }
	    });
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
	 */
	public void setFocus() {
		// TODO Auto-generated method stub
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -