Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Custom popupDialog: is this the right way to do id?
Custom popupDialog: is this the right way to do id? [message #754711] Thu, 03 November 2011 23:40
Eclipse User
Hello,
I need to show a dialog with a "content assist look and feel", but my
eclipse rcp rich client application doesn't have any editor.. The dialog
is shown on a mousehover event... it's like a tooltip, but it contains a
custom composite with a tree or a table, and it must have the focus and
resizing management like a content assist popupDialog.
I did a new class like the one below, but the question is: maybe I am
using the wrong tool, or using it the wrong way... are there any ways to
use popupDialogs better than I did?
I didn't find any documentation on this topic... When this task will be
completed, I'll surely write a little tutorial!

Thank you in advance!

This is the class:

package it.rcpvision.project.popupdialogs;

import it.rcpvision.project.Model;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wb.swt.SWTResourceManager;

public class CustomPopupDialog extends PopupDialog {

public static final int POPUP_MAXIMUM_WIDTH = 400;
public static final int POPUP_MINIMUM_HEIGHT = 300;
private Model model;

private Point location;
private Composite dialogArea;

public CustomPopupDialog(Shell parent, Model model, Point location) {
super(parent, INFOPOPUP_SHELLSTYLE, true, false, false, false, false,
model.getTitle(), null);
this.model = model;
this.location = location;
}

@Override
protected Control createDialogArea(Composite parent) {
dialogArea = (Composite) super.createDialogArea(parent);

applyBackgroundColor(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND),
dialogArea);
CustomizedComposite customComposite = new
CustomizedComposite(dialogArea, SWT.NONE);
GridDataFactory.fillDefaults().applyTo(customComposite);
return dialogArea;
}

@Override
protected void adjustBounds() {
super.adjustBounds();
Shell shell = this.getShell();

Rectangle displayBounds =
PlatformUI.getWorkbench().getDisplay().getBounds();
int popupWidth = POPUP_MAXIMUM_WIDTH;
int dialogAreaHeight = dialogArea.getClientArea().height;
int popupHeight = dialogAreaHeight < POPUP_MINIMUM_HEIGHT ?
POPUP_MINIMUM_HEIGHT : dialogAreaHeight;

if (popupWidth + location.x > displayBounds.width){
location.x = location.x - popupWidth;
}

if (popupHeight + location.y > displayBounds.height) {
location.y = location.y - popupHeight;
}

Rectangle popupDialogBounds = new Rectangle(location.x, location.y,
popupWidth, popupHeight);
shell.setBounds(popupDialogBounds);


applyBackgroundColor(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND),
shell);
shell.setBackgroundMode(SWT.INHERIT_FORCE);

}


}


--
Lorenzo Murrocu
Eclispe Developer
http://www.rcp-vision.com/
Previous Topic:SourceViewer undo support
Next Topic:StyledCellLabelProvider and SWT.FULL_SELECTION
Goto Forum:
  


Current Time: Thu Oct 23 04:47:44 GMT 2014

Powered by FUDForum. Page generated in 0.09805 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software