Advance JFACE

13
Advance JFACE Rahul Shukla

Transcript of Advance JFACE

Page 1: Advance JFACE

Advance JFACE Rahul Shukla

Page 2: Advance JFACE

When our table contains large data then we usually prefer Virtual Table Tree .

It creates table items on demand.

Faster in case of large data .

Virtual Table/Tree

Page 3: Advance JFACE

public class VirtualTableViewer { public VirtualTableViewer(Shell shell) { final TableViewer v = new TableViewer(shell,SWT.VIRTUAL); v.setLabelProvider(new LabelProvider()); v.setContentProvider(new ArrayContentProvider()); v.setUseHashlookup(true); v.setInput(createModel()); v.getTable().setLinesVisible(true);}private String[] createModel() { String[] elements = new String[1000000]; for (int i = 0; i < 1000000; i++) { elements[i] = "Item" + i; } return elements;}

Virtual Table Example

Page 4: Advance JFACE

When we want lazy loading of data

It Loads the data when it is required

In TeamCenter our all Tree are Lazy Tree

Create Item Virtually

Lazy Table/Tree

Page 5: Advance JFACE

public class VirtualLazyTableViewer {

private class MyContentProvider implements ILazyContentProvider {

private TableViewer viewer;

private String[] elements;

public MyContentProvider(TableViewer viewer) {

this.viewer = viewer;}

public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

this.elements = (String[]) newInput;}

public void updateElement(int index) {

viewer.replace(elements[index], index);}}

public VirtualLazyTableViewer(Shell shell) {

final TableViewer v = new TableViewer(shell, SWT.VIRTUAL);

v.setLabelProvider(new LabelProvider());

v.setContentProvider(new MyContentProvider(v));

v.setUseHashlookup(true);

String[] model = createModel();

v.setInput(createModel());

v.setItemCount(model.length); // This is the difference when using a ILazyContentProvider

v.getTable().setLinesVisible(true);}

private String[] createModel() {

String[] elements = new String[10000];

for (int i = 0; i < 10000; i++) {elements[i] = "Item"+i;}

return elements;}

}

Lazy Table Viewer Example

Page 6: Advance JFACE

Dialog

◦ A dialog is a specialized window used for narrow-focused communication with the user.

◦ Dialogs are usually modal. Consequently, it is generally bad practice to open a dialog without

a parent. A modal dialog without a parent is not prevented from disappearing behind the

application's other windows, making it very confusing for the user.

◦ If there is more than one modal dialog is open the second one should be parented off of the

shell of the first one otherwise it is possible that the OS will give focus to the first dialog

potentially blocking the UI.

TrayDialog

◦ A TrayDialog is a specialized Dialog that can contain a tray on its side. The tray's content is

provided as a DialogTray. It is recommended to subclass this class instead of Dialog in all

cases except where the dialog should never show a tray. For example, dialogs which are

very short, simple, and quick to dismiss (e.g. a message dialog with an OK button) should

subclass Dialog.

TitleAreaDialog

◦ A dialog for showing messages to the user. This concrete dialog class can be instantiated

as is, or further subclassed as required.

JFace Dialog

Page 7: Advance JFACE

Simple Dialog

TitleAreaDialog

Dialog

Page 8: Advance JFACE

Confirmation Dialog

◦ boolean openConfirm =

MessageDialog.openConfirm(getShell(), "Confirm

Dialog", "Do You want To Continue");

Error Dialog

◦ MessageDialog.openError(getShell(), "Error Dialog",

"Error Occured");

Warning Dialog

◦ MessageDialog.openWarning(getShell(), "Warning

Dialog", "Doc is not given");

Message Dialog

Page 9: Advance JFACE

protected Control createDialogArea(Composite parent) {

◦ Creates and returns the contents of the upper part of this dialog (above the button

bar). The Dialog implementation of this framework method creates and

returns a new Composite with standard margins and spacing. The

returned control's layout data must be an instance of GridData. This

method must not modify the parent's layout. Subclasses must override

this method but may call super as in the following example:

protected Button createButton(Composite parent, int id, String

label,boolean defaultButton)

◦ Creates a new button with the given id.

◦ The Dialog implementation of this framework method creates a standard push button,

registers it for selection events including button presses, and registers default

buttons with its shell. The button id is stored as the button's client data. If the

button id is IDialogConstants.CANCEL_ID, the new button will be accessible from

getCancelButton(). If the button id is IDialogConstants.OK_ID, the new button will be

accesible from getOKButton(). Note that the parent's layout is assumed to be a

GridLayout and the number of columns in this layout is incremented. Subclasses may

override.

Customized Dialog

Page 10: Advance JFACE

protected Control createButtonBar(Composite parent) {

◦ Creates and returns the contents of this dialog's button bar.

◦ The Dialog implementation of this framework method lays out a button bar and

calls the createButtonsForButtonBar framework method to populate it.

Subclasses may override.

◦ The returned control's layout data must be an instance of GridData.

protected void createButtonsForButtonBar(Composite parent) {

◦ Adds buttons to this dialog's button bar.

◦ The Dialog implementation of this framework method adds standard ok and

cancel buttons using the createButton framework method. These standard

buttons will be accessible from getCancelButton, and getOKButton. Subclasses

may override.

Customized Dialog

Page 11: Advance JFACE

A dialog to show a wizard to the end user.

In typical usage, the client instantiates this class with a particular wizard.

The dialog serves as the wizard container and orchestrates the

presentation of its pages.

The standard layout is roughly as follows: it has an area at the top

containing both the wizard's title, description, and image; the actual wizard

page appears in the middle; below that is a progress indicator (which is

made visible if needed); and at the bottom of the page is message line and

a button bar containing Help, Next, Back, Finish, and Cancel buttons (or

some subset).

Clients may subclass WizardDialog, although this is rarely required.

Wizard Dialog

Page 12: Advance JFACE

public class WizardExamle extends Wizard {

@Overridepublic boolean performFinish() {// TODO Auto-generated method stubreturn false;}

@Overridepublic void addPages() {addPage(new WizardPage1("Page 1"));addPage(new WizardPage2("Page2"));super.addPages();}@Overridepublic boolean performCancel() {return super.performCancel();}@Overridepublic boolean canFinish() {return super.canFinish();}

}

Wizard

Page 13: Advance JFACE

public class WizardPage2 extends WizardPage {

protected WizardPage2(String pageName) { super(pageName); setTitle(pageName); }

@Override public void createControl(Composite parent) { setControl(new Composite(parent, SWT.NONE)); setPageComplete(false);

}

@Override public boolean isPageComplete() { return super.isPageComplete(); }

@Override public boolean canFlipToNextPage() { return super.canFlipToNextPage(); }

Wizard Page