package org.vietspider.notifier.notifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Shell;
public class NotifierDialogs {
static List<NotifierDialog> activeShells = new ArrayList<NotifierDialog>();
public static void notify(Shell parent,
String title, String message, String id,
NotificationType type, NotificationListener listener) {
NotifierDialog dialog_ = new NotifierDialog(parent, title, message, id, type, listener);
// move other shells up
if (!activeShells.isEmpty()) {
List<NotifierDialog> modifiable = new ArrayList<NotifierDialog>(activeShells);
Collections.reverse(modifiable);
for (NotifierDialog dialog : modifiable) {
Shell shell = dialog.getShell();
Point curLoc = shell.getLocation();
shell.setLocation(curLoc.x, curLoc.y - 100);
if (curLoc.y - 100 < 0) {
activeShells.remove(shell);
shell.dispose();
}
}
}
Rectangle clientArea = parent.getMonitor().getClientArea();
int startX = clientArea.x + clientArea.width - 352;
int startY = clientArea.y + clientArea.height - 102;
Shell shell = dialog_.getShell();
shell.setLocation(startX, startY);
shell.setAlpha(0);
shell.setVisible(true);
activeShells.add(dialog_);
dialog_.fadeIn();
}
public static void remove(NotifierDialog dialog) {
System.out.println("da thay remove "+dialog);
if(!dialog.getShell().isDisposed()) {
dialog.getShell().dispose();
}
activeShells.remove(dialog);
}
}