I am trying to create a multipage editor looking similar to the manifest editor using the wizard for multipage editors provided by eclipse. The first page is created as follows:
void createPage0() {
Composite composite = new Composite(getContainer(), SWT.DEFAULT);
composite.setLayout(new FillLayout());
FormToolkit toolkit = new FormToolkit(composite.getDisplay());
Form form = toolkit.createForm(composite);
form.setText("Test Viewer");
toolkit.decorateFormHeading(form);
int index = addPage(composite);
setPageText(index, "editor1");
}
When ran with eclipse, the created form has two scroll activ scroll bar, although there is obviously nothing to scroll.
I tried cleaning and refreshing the project. Nothing changed. Help?
I found out the problem. The composite surrounding form somehow makes the scroll bars. The following code solves the problem.
void createPage0() {
FormToolkit toolkit = new FormToolkit(composite.getDisplay());
Form form = toolkit.createForm(composite);
form.setText("Test Viewer");
toolkit.decorateFormHeading(form);
int index = addPage(composite);
setPageText(index, "editor1");
}
Related
I would like to add a button on some rows of my TreeViewer. To do that, I’ve used a method that I saw on a forum and it was working on a TableViewer.
I‘ve implemented my own Label provider on the column where I want the button to be. So I’ve overriden the class update(ViewerCell cell) which calls my method addButton(cell):
(I have simplified the code for a better comprehension)
public class SelectVariableButtonLabelProvider extends ColumnLabelProvider {
#Override
public void update(ViewerCell cell) {
if(...){
addButton(cell);
}
}
private void addButton(ViewerCell cell) {
TreeItem item = (TreeItem) cell.getItem();
Button btn = new Button((Composite) cell.getViewerRow().getControl(), SWT.NONE);
btn.setText(" select variable ");
//action when the button is clicked
btn.addListener(SWT.Selection, new SelectVariableButtonListener(tree,
DataTypeTreeUtils.getTreeNodeDataTypeInstance(cell.getElement()), viewer));
TreeEditor editor = new TreeEditor(item.getParent());
editor.grabHorizontal = true;
editor.grabVertical = true;
// editor.horizontalAlignment = SWT.RIGHT;
editor.minimumWidth = btn.getSize().x + 110;
editor.setEditor(btn, item, cell.getColumnIndex());
editor.layout();
}
}
It’s almost working. Except that the buttons of the column of buttons is duplicated when I want to extend the column.
screenshot of the bug
The left “column of buttons'' : is completely working. The buttons are functional and they adapt themself to the extension of the nodes in the tree Viewer.
The right “column of buttons” : is fixed on the viewer and the buttons are not completely functional. And when I want to extend or not the nodes in the tree, the buttons are not corresponding to their rows anymore. (These are also the buttons in the foreground).
So I would like to not have the right columns which probably appeared because of a bug. I think this could be due to the composite to which the button is initialized :
Button btn = new Button((Composite) cell.getViewerRow().getControl(), SWT.NONE);
Or just because buttons are simply bugging when they are on Tree Viewers ? The same method is working on Table Viewers.
Just in case and if it helps, this is the declaration of the viewer:
viewer = new TreeViewer(treeContainer, SWT.FULL_SELECTION);
viewer.setContentProvider(new TreeNodeTreeContentProvider());
viewer.setLabelProvider(new CustomColumnLabelProvider());
viewer.getTree().setHeaderVisible(true);
viewer.getTree().setLinesVisible(true);
and this is the declaration of the column where I want to add the buttons:
//column with the buttons "select variable"
TreeViewerColumn viewerSetValueColumn = new TreeViewerColumn(viewer, SWT.NONE);
viewerSetValueColumn.getColumn().setWidth(110);
viewerSetValueColumn.setLabelProvider(new SelectVariableButtonLabelProvider(viewer, getAllVariables()));
EDIT:
I would like to have buttons in some rows of a column of my treeViewer. But I want them to be always visible, so I would like to avoid using editing support.
I've used the LabelProvider to do it but it caused a bug (screenshot of the bug).
Does anyone know how to add buttons to a treeViewer using the labelProvider?
I am currently working on a school project where we are creating a GWT web application which uses a GeoChart widget to display information about the servers we have crawled. Simply put, I would wish to create a text box on top of our GeoChart widget which shows an interactive world map that takes up the whole screen right now to input information. I have searched quite extensively but I have been unable to come up with an answer.
Here is the code as follows:
#Override
public void onModuleLoad() {
dataReader = (DataReaderAsync) GWT.create(DataReader.class);
RootLayoutPanel.get().add(getSimpleLayoutPanel());
// Create the API Loader
ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
chartLoader.loadApi(new Runnable() {
#Override
public void run() {
getSimpleLayoutPanel().setWidget(getGeoChart());
drawGeoChart();
}
});
}
As GeoChart is a widget, it is wrapped under(i am not sure if this is the right word) a SimpleLayoutPanel right now which will display it into a full screen. As stated above, I would wish to include text above the geoChart. From my understanding, I would need to create another widget containing my text and add both the GeoChart widget and the text box widget into it. What would be the best way to go about doing this?
I believe DialogBox could solve your problem. People usually program the DialogBox in a way that it only pops up into display when certain event is triggered and disappears after user finishes some operation. In your particular case, you can simply make the DialogBox shows up from the beginning and never disappears. And the best part of it: you don't need to add the DialogBox widget to the geoChart widget. Calling dialogBox.center() or dialogBox.show() will do the magic for you.
Here is the sample code.
#Override
public void onModuleLoad() {
dataReader = (DataReaderAsync) GWT.create(DataReader.class);
RootLayoutPanel.get().add(getSimpleLayoutPanel());
// Create the API Loader
ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
chartLoader.loadApi(new Runnable() {
#Override
public void run() {
getSimpleLayoutPanel().setWidget(getGeoChart());
drawGeoChart();
}
});
// NOTE: the first argument 'false' makes sure that this dialog box
// will not disappear when user clicks outside of it
// NOTE: the second argument 'false' makes sure that mouse and keyboard
// events outside of the dialog box will NOT be ignored
DialogBox dialogBox = new DialogBox(false, false);
DialogBox.setText("Demo");
HorizontalPanel panel = new HorizontalPanel();
panel.setSpacing(5);
InlineLabel labelOfTextBox = new InlineLabel("Label");
TextBox textBox = new TextBox();
panel.add(labelOfTextBox);
panel.add(textBox);
dialogBox.setWidget(panel);
// show up in the center
dialogBox.center();
}
Dear all thanks for answering my question. To rectify this problem, I have made use of the custom widget API within GWT(known as Composite). Here's the code as below:
private static class CombinedWidget extends Composite {
public CombinedWidget() {
// place the check above the text box using a vertical panel.
VerticalPanel panel = new VerticalPanel();
DockLayoutPanel dPanel = new DockLayoutPanel(Unit.EM);
panel.setSpacing(13);
panel.add(nameProject);
nameProject.setStyleName("gwt-Group-Label");
panel.add(className);
panel.add(nameKs);
panel.add(nameEsmond);
panel.add(nameBowen);
panel.add(nameAaron);
dPanel.addWest(panel, 13);
dPanel.add(getGeoChart());
// all composites must call initWidget() in their constructors.
initWidget(dPanel);
setWidth("100%");
}
Actually I sort of changed from the original idea. Instead of putting it on the very top, I attached the labels into a VerticalPanel and then created a CombinedWidget(custom widget) which adds both a VerticalPanel and DockLayoutPanel together. I then added the VerticalPanel(containing all the labels) and the GeoChart into the DockLayoutPanel.
This solved my problem of displaying both the labels and the GeoChart on the same page(as originally i added it into a VerticalPanel but it would not work as the app would not read the GeoChart due to the VerticalPanel being overlayed on top of the GeoChart).
If you guys want a picture of my app to visualise, please say so!
I'm trying to add JFree step charts to a scrollable view in eclipse as a plugin, but the charts keep resizing (kinda randomly) each time I modify the view's dimensions.
I want to set them to a fixed size, however large or small the view might get (that's why I made it scrollable in the first place) so I tried something like this:
public void createPartControl(final Composite parent) {
ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
Composite comp = new Composite(scrolled, SWT.NONE);
comp.setLayout(new FillLayout(SWT.VERTICAL));
final JFreeChart chart = createChart();
ChartComposite chartComposite1 = new ChartComposite(comp, SWT.NONE, chart, true);
// set chart size attempt
chartComposite1.setSize(500, 200);
chartComposite1.redraw();
comp.redraw();
scrolled.redraw();
// ScrolledComposite stuff
scrolled.setContent(comp);
scrolled.setExpandVertical(true);
scrolled.setExpandHorizontal(true);
scrolled.setAlwaysShowScrollBars(true);
scrolled.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
org.eclipse.swt.graphics.Rectangle r = scrolled.getClientArea();
scrolled.setMinSize(parent.computeSize(r.width, SWT.DEFAULT));
}
});
But it doesn't do anything. The chart keeps auto resizing as I modify the view's size.
Any help?
Make sure that you undestand how layouts work in SWT. Understanding Layouts in SWT is a good start.
chartComposite1.setSize() is useless, it will be overwritten by the layout that was set in comp.setLayout( ... ).
... and forcing controls to redraw() doesn't help either as it doesn't update the location or size of controls.
As I suggested earlier, if you know the size of the charts, use a single columned GridLayout and control the size of the charts through GridData::widthHint and heightHint.
I am supposed to create a scroll bar in my Eclipse RCP view and I referred to the ScrolledComposite javadoc and taking help from this.
private void createComposite2(final Composite parent,final String text, int compositeNumber)
{
final ScrolledComposite rightScrolled = new ScrolledComposite(parent, SWT.V_SCROLL|SWT.H_SCROLL|SWT.BORDER);
group=GUIToolkit.newGroup(rightScrolled, SWT.NONE, text, null);
rightScrolled.setContent(group);
group.setLayout(new FillLayout());
rightScrolled.setExpandHorizontal(true);
rightScrolled.setExpandVertical(true);
group.setSize(group.computeSize(SWT.DEFAULT, SWT.DEFAULT));
group.setBackground(white);
createPartControl(group,compositeNumber);
}
But instead the scroll is absent. Can anybody tell me what exactly is the problem? In one of the online resources I saw addControlListner. Will that help? If yes, how can I use it?
After some research and hit and trial, i came up with this code,
private void createComposite2(final Composite parent,final String text, int compositeNumber)
{
final ScrolledComposite rightScrolled = new ScrolledComposite(parent, SWT.V_SCROLL|SWT.H_SCROLL);
group=GUIToolkit.newGroup(rightScrolled, SWT.NONE, text, null);
rightScrolled.setContent(group);
rightScrolled.setExpandHorizontal(true);
rightScrolled.setExpandVertical(true);
rightScrolled.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
org.eclipse.swt.graphics.Rectangle r = rightScrolled.getClientArea();
rightScrolled.setMinSize(group.computeSize(r.width, SWT.DEFAULT));
}
});
group.setLayout(new FillLayout());
group.setBackground(white);
createPartControl(group,compositeNumber);
}
which resulted in scroll coming but it would not readjust to show the window.
Have a look at the first composite with name SOAD. It's the normal size.
and now this is when i push it on left side, the scroll should have been activated, and it is not... It is cropping the content.
How do i fix this
I am creating a custom tooltip where i have a textbox.I am able to do that but i could not get balloon like icon as in the attached picture .Can anyone help me regarding this.
Mytooltip class:
public class MyToolTip extends ToolTip {
private Shell parentShell;
public MyToolTip(Control control) {
super(control,SWT.BALLOON,false);
this.parentShell = control.getShell();
}
#Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
// TODO Auto-generated method stub
Composite comp = new Composite(parent,SWT.NONE);
comp.setLayout(new FillLayout());
Text text = new Text(comp,SWT.BORDER);
text.setText("");
return comp;
}
}
Class using tooltip:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.VERTICAL));
Text text = new Text(shell, SWT.BORDER);
text.setText("sample text field");
MyToolTip myTooltipLabel = new MyToolTip(text);
myTooltipLabel.setShift(new Point(-5, -5));
myTooltipLabel.setHideOnMouseDown(false);
myTooltipLabel.activate();
myTooltipLabel.setRespectDisplayBounds(false);
myTooltipLabel.setRespectMonitorBounds(false);
The problem is, that you are using org.eclipse.jface.window.ToolTip whereas the code that was used to create that screenshot uses org.eclipse.swt.widgets.ToolTip.
The SWT tooltip can have the balloon look by passing SWT.BALLOON as the style bit.
The JFace tooltip does not support SWT.BALLOON, only ToolTip.NO_RECREATE and ToolTip.RECREATE.
So here is the conclusion: You can't subclass the swt tooltip to make it editable. You can't make the JFace tooltip look the way you want it to look. The only solution that is left is creating your own Widget based on Composite or Canvas that does what you want.