Eclipse e4 Application (Eclipse 2018-12).
I have developed a custom PerspectiveSwitcher class extending Composite. This class builds an UI to display - (1) user information using Label, (2) quick group change drop down combo box using Combo, and (3) tabbed perspective switcher using CTabFolder.
I want to add PerspectiveSwitcher UI as a second toolbar on the separate line, like in the image below:
However,
I want the "Company and App LOGO" to be placed on the right side (as pointed to by the red arrow). I tried several combinations of GridData parameters, but none worked.
When I stretch the application window horizontally long enough, the icon toolbar and my custom toolbar merge, as below:
Here is my Application.e4xmi is as follows. The first Tool Control adds the "Company and App LOGO", while the second Tool Control adds the PerspectiveSwitcher UI.
The first Tool Control class is:
public class TrimLogoControl
{
#PostConstruct
public void createPartControl(final Composite parent)
{
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
final Label logoLabel1 = new Label(composite, SWT.NONE);
logoLabel1.setImage(PlugIn.createImage("icons/company_logo.png"));
logoLabel1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Label logoLabel2 = new Label(composite, SWT.NONE);
logoLabel2.setImage(Plugin.createImage("icons/app_logo.png"));
logoLabel2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
}
}
The second Tool Control class is:
public class PerspectiveSwitcherControl
{
#PostConstruct
public void createPartControl(final Composite parent)
{
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
new PerspectiveSwitcher(composite, SWT.NONE); // Custom class
}
}
I would very much appreciate, if someone can answer - how to move logos to the right, and how to keep the PerspectiveSwitcher toolbar on the separate line?
I tried adding another Tool Control before the first Tool Control and setting it to FillLayout as explained in How to add Perspective Bar Switcher to pure eclipse 4 rcp application. But that did not work.
I also checked the thread Eclipse e4 tool Control in trimbars, but that did not help either.
To align controls at the right of a trim bar add a separate ToolControl with a tag of stretch. This control will grab any available space in the bar giving right alignment for the result of the bar.
The code for the control can just be an empty Composite with a FillLayout.
I don't know if it possible to force things on to a separate line.
Related
I would like to create a custom tooltip for an RCP MDirectToolItem or MHandledToolItem. JFace provides the org.eclipse.jface.window.ToolTip class, which I can extend and override the createToolTipContentArea() method. However, to instantiate a JFace ToolTip, I have to give it the SWT Control that will use the ToolTip. I cannot figure out a way to get the underlying SWT Control from the MDirectToolItem.
I have been able to get the MToolBar and the MDirectToolItem (which I defined in the Application.e4xmi) using the EModelService.find() method. I tried getting the underlying SWT Control from the MDirectToolItem, but it does not appear there is a way to do that.
I also tried creating an SWT ToolItem and adding it to the MToolBar, but the children of the MToolBar are only MToolBarElement's.
Tool items don't have a separate control, they are part of the parent ToolBar control. The SWT ToolItem class represents the tool item, this is just derived from Widget rather than Control.
So you will have to set the tool tip on the tool bar control and work out which tool item is active when the tool tip is shown.
The application model classes which represent UI objects all extend the MUIElement interface. This provides a getWidget method to get the UI object.
So for MToolBar you can do:
ToolBar toolbar = (ToolBar)mtoolbar.getWidget();
and for MToolItem (either handled or direct) you can do:
ToolItem toolitem = (ToolItem)mtoolitem.getWidget();
If you create the ToolTip with the NO_RECREATE style it will call the
getToolTipArea method to determine if the tool tip need to be changed. You can use something like the following to have a different area for each tool item:
#Override
protected Object getToolTipArea(final Event event)
{
// TODO save the ToolBar in the class as 'toolBar'
ToolItem item = toolBar.getItem(new Point(event.x, event.y));
if (item != null)
return item;
return super.getToolTipArea(event);
}
I added a search text ToolControl to a MPart toolbar as described here:
Eclipse e4 tool Control in trimbars
http://www.vogella.com/tutorials/EclipseRCP/article.html#toolbar_advanced_toolcontrols
My problem is:
When I have another item (e.g. handled tool item with icon) in the toolbar, I can see most of the text, but not all. When there is no other item, I see just the upper line of the text.
The toolbar height seems not to be adapted to my control,
Whould be great if anyone can help me.
Christin
The basic problem is that although the ToolBar control allows controls as children it doesn't take their depth in to account when calculating the tool bar depth.
The Vogella example (which is intended for the window trim bar rather than a part tool bar) is using a default GridLayout which adds a margin above the search text. You could try using:
Composite comp = new Composite(parent, SWT.NONE);
// GridLayout with no margins
comp.setLayout(GridLayoutFactory.fillDefaults().create());
Text text = new Text(comp, SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL | SWT.BORDER);
text.setMessage("Search");
GridDataFactory.fillDefaults().hint(130, SWT.DEFAULT).applyTo(text);
That is using a GridLayout with no margins.
I am implementing a plug-in in eclipse, which reads a set of values from a database and displays it in a TableViewer inside a ViewPart. The TableViewer uses an ArrayContentProvider as shown
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
...
viewer.setContentProvider(new ArrayContentProvider());
I also have a handler which has access to the TableViewer instance for importing data from an XML file. When the importer imports data, I create a ModelProvider instance which generates a list of objects whose data is displayed by TableViewer.
The handler then sets the input:
viewer.setInput(new ModelProvider(Data.getDocs()).getTableRows());
When I test this application, with this ViewPart already open (and the TableViewer being empty) and invoke the handler for importing data, the data is imported succesfully but the TableViewer shows only a single row and the scroll bar. Only when I drag the ViewPart to some other location on the Workbench, then all the rows are shown.
I have even tried:
viewer.setInput(new ModelProvider(Data.getDocs()).getTableRows());
viewer.refresh();
and
viewer.setInput(null);
viewer.setInput(new ModelProvider(Data.getDocs()).getTableRows());
viewer.refresh();
but nothing works. How do I make all the rows display as soon as new input is set?
I don't think you have a table problem, but a layout problem.
If your viewer's parent has a GridLayout, then do:
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
OR you can just set a FillLayout on the parent, and that's it.
(if you think I misunderstood your question, please post a screenshot)
I have a combo box. When I click a link, it opens a popup including a combo box (with data loaded from database). It always keeps data from the first call (it does not refresh).
How can I refresh this?
VerticalPanel vp = new VerticalPanel();
vp.setSpacing(10);
ListStore<State> states = new ListStore<State>();
states.add(getStates());
ComboBox<State> combo = new ComboBox<State>();
combo.setEmptyText("Select a state...");
combo.setDisplayField("name");
combo.setWidth(150);
combo.setStore(states);
combo.setTypeAhead(true);
combo.setTriggerAction(TriggerAction.ALL);
vp.add(combo);
Assuming, that you are working with GXT and there fore are using the GXT Window class, you can do something like this:
myWindow.addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() {
#Override
public void onBeforeShow(BeforeShowEvent event) {
mxComoBox.clear();
}
});
You see the old value, because a popup will be reused. so you have to clear the value of the combo, when the popup get visible.
This code should work with GXT 3.1.2. Older versions of GXT might have a different coding.
Hope that helps.
I am trying to add MapWidget to VerticalPanel but the map added on the
left corner:
And I added marker and the marker should be centered on the image
I can't see the marker when I load the map. I should navigate to this
location to show map.
The code for this
private FormPanel form = new FormPanel();
private VerticalPanel main = new VerticalPanel();
public Map(){
ScrollPanel container = new ScrollPanel();
initWidget(container);
container.setStyleName("FuoEgForm");
form.setWidget(main);
main.setSpacing(6);
container.add(main);
}
public MapWidget addMapWidget(){
MapWidget map = new MapWidget();
//map.setSize("100%", "100%");
map.setStyleName("gwt-map");
map.removeMapType(MapType.getNormalMap());
map.removeMapType(MapType.getSatelliteMap());
map.addMapType(MapType.getPhysicalMap());
map.addMapType(MapType.getHybridMap());
map.setCurrentMapType(MapType.getHybridMap());
//map.setSize("100%", "100%");
map.setWidth("500px");
map.setHeight("500px");
main.add(map);
}
How can I solve this issue? The map should fill the gray
boundary?
As of gwt-maps-1.1, the MapWidget implements the RequiresResize interface. When added to a panel that supports this interface (such as DockLayoutPanel), the widget automatically calls map.checkResizeAndCenter() whenever the panel containing the widget is resized. This new feature makes it possible to set your map size to 100% in both directions and fill up the available space on the screen. To use LayoutPanel subclasses properly, make sure your html page is set to use standards mode by adding as the first line in the document.
In gwt-maps 1.0, it may be necessary to force the map to resize its layout after the map is initially added. you can use the MapWidget.checkResizeAndCenter() method to clean this up. You may need to delay calling this function using a DeferredCommand or other mechanism to wait until after the DOM layout pass that resizes the map is called.
or you can find unexpected another unexpected reason that happened with me
i made the map invisible #constructor
and then set it visible if clicked on a button
the solution
make the map always visible :)
I insert these line below the add(map) :
LatLng c = mapWidget.getCenter();
resizeMap(mapWidget.getMVCObject());
mapWidget.setCenter(c);