Showing posts with label notification dialog. Show all posts
Showing posts with label notification dialog. Show all posts

Monday, April 13, 2015

Showing notification or popup dialog in Eclispe

Will use PopupDialog Class from eclipse Jface framework.

I am taking about something like this.











Example:

import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class PopupDialogExample {

public static void main(String[] args) {
open();
}
static void open(){
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("PopupDialog");
shell.setLayout(new GridLayout());
shell.setSize(400, 300);
Button button = new Button(shell,SWT.PUSH);
button.setText("Click here!");
button.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
int shellStyle = PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE;
boolean takeFocusOnOpen = true;
boolean persistSize = true;
boolean persistLocation = true;
boolean showDialogMenu = true;
boolean showPersistActions = true;
String titleText = "Updates Available"
String infoText = "Eclipse updates are available!";
PopupDialog  dialog = new PopupDialog(shell, shellStyle, takeFocusOnOpen, persistSize, persistLocation, showDialogMenu, showPersistActions, titleText, infoText){

@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
Label text = new Label(composite,SWT.SINGLE);
text.setText("There is a update for your plugin, please install them before proceed!");
return composite;
}
};
dialog.open();
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}


}