Eclipse PDE: How to add buttons to a view? - eclipse

I have created a simple view, but it would be nice to add buttons to it. For example, I drew two blue buttons into the view below. Is there a way to add similar buttons to my Eclipse view? I know that I can add a pulldown menu, from this question, but buttons are preferable.
My example below is just a demonstration - the location/size/color of the buttons does not matter as long as the buttons are inside the view.

In case you are using SWT:
For a start you could install WindowBuilder. It lets you work on the UI level without caring to much about implementation. The generated code however is not layed out in the way that you can work with, when you are creating views with more than a few buttons.
The implementation depends on your Eclipse version.
In the old Eclipse 3.x, a Button could be set up by Overriding the method createPartControl:
#Override
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout(1, false));
Button btnMybutton = new Button(container, SWT.NONE);
btnMybutton.setBounds(0, 10, 75, 25);
btnMybutton.setText("MyButton");
//do anything else here
}
If you are familiar with other UI Frameworks and don't like SWT, you might as well switch to e.g. Vaadin or JavaFX. There's a blog articleabout changing the renderer of your application.

Related

SmartGWT tab losing GWT based contents

I have written very basic GWT application where SmartGWt tabs render with label on both tabs.
Problem I am facing here is, when I put GWT based label in second tab and reload application, first tab renders SmartGWT based label but when i click on second tab to look GWT label, it doesn't appear and also I am surprised why first tab content is removed as It was appearing earlier before clicking on second tab.
Please have a look into below code.
package com.test.client;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
public class TestGWT implements EntryPoint
{
public void onModuleLoad()
{
TabSet tabSet = new TabSet();
tabSet.setWidth("400px");
Tab tab1 = new Tab("Tab1");
Canvas pane = new Canvas();
pane.addChild(new com.smartgwt.client.widgets.Label("test label"));
tab1.setPane(pane);
Tab tab2 = new Tab("Tab2");
Canvas pane2 = new Canvas();
pane2.addChild(new Label("test label2")); // I need to put GWT widget in SmartGWT tab but it does not render in this tab. Also, it removes contents from first tab
tab2.setPane(pane2);
tabSet.addTab(tab1);
tabSet.addTab(tab2);
RootPanel.get("testid").add(tabSet);
}
}
When I set second SmartGWT tab to appear first which has GWT widget then things are working fine.
I am using GWT-2.6.1
Please share your thoughts here!
Regards,
Shobhit
Although I agree on the cause of the problem being RootPanel.get("testid").add(tabSet), the solution is replacing that line with:
tabSet.show();
Keep in mind that in SmartGWT, you should add components to other components using add(). Trying to add components using their IDs is prone to errors.
Finally, keep in mind that Isomorphic discourages mixing SmartGWT's components with components from other libraries. While this is unavoidable sometimes, if you can avoid it in your application, you should, because this is a very common source for bugs. See my comments below for additional sources for these claims.
The problem is adding the TabSet to the RootPanel. So you receive an
A widget that has an existing parent widget may not be added to the detach list.
error.
Change RootPanel.get("testid").add(tabSet); to
tabSet.setHtmlElement((Element) Document.get().getElementById("testid"));
tabSet.draw();
and it will work fine.

How to add Perspective Bar Switcher to pure eclipse 4 rcp application

I have created a pure Eclipse e4 rich client platform application application model. I created multiple perspectives using perspective stack, but I am unable to switch other perspective because there is no default perspective bar or switcher icon present in Eclipse e4. How to implement a perspective switcher in pure Eclipse e4?
EPartService.switchPerspective will do the actual switch, but you will have to design and implement the UI.
You could use a ToolBar in the window Trim Bar with buttons for each perspective. Alternatively a Combo as a Tool Control with a list of the perspectives, it is up to you.
To put a control at the right of a Trim Bar you need to add two Tool Control objects to the trim. Something like:
The first Tool Control is just a spacer to fill the center of the bar.
On the tags tab for the control add the word stretch to tell e4 to stretch this control over as much space as possible:
You will also have to specify a class for the control. This just needs to create an empty Composite to occupy the space. For example:
public class SpacerControl
{
#PostConstruct
public void postConstruct(final Composite parent)
{
Composite body = new Composite(parent, SWT.NONE);
body.setLayout(new FillLayout());
}
}
The second Tool Control will contain your Combo control for the perspective switch. Something like:
public class ComboControl
{
#PostConstruct
public void createGui(final Composite parent)
{
Combo combo = new Combo(parent, SWT.READ_ONLY);
... initialize Combo, add listeners, ....
}
}
This should end up looking something like this:

Eclipse rcp view remove icon

My requirement is to remove the title icons for all views but it seems impossible.
First i removed the references to the icons from extension point="org.eclipse.ui.views" in my plugin.xml file.
There is a similar question to this one where it is suggested to override getTitleImage() in the view that extends ViewPart so i did just that and i tryed 2 versions.
#Override
public Image getTitleImage() {
return null;
}
#Override
public Image getTitleImage() {
return new Image(getSite().getShell().getDisplay(), new Rectangle(0, 0, 1, 1));
}
The result no matter which method i used is that some views don't display the icon and some do. For example the first view is always opened without the icon but the following views get the default icon. Also if i have save and restore enabled and restart the application while leaving some views open, the one that is selected doesn't have the icon while the rest do.
This is so frustrating, i just don't get why something so simple has to be so complicated to implement.
I think the problem is views that have not yet been created (so getTitleImage has not been called). In that case the workbench part reference code uses the default image if there is nothing defined in the view definition.
If the above is correct creating an empty image icon file and defining that as the icon in the org.eclipse.ui.views extension in your plugin.xml should work.

Android activity dynamic layout updates

I am trying to create a small Android App. The app will have four modes. The top part of the display will contain four buttons to switch between these modes, and this part of the display will not change. The rest of the display will change depending which button has been clicked on. It will contain a table with TextViews or images.
My questions are:
Is it possible to create the table layout programmatically?
How should I approach switching between modes:-
Four separate Activity classes?
One Activity and programmatically change the bottom part of it?
Should I create one base Activity with buttons and extend it?
What would be the best option?
Create layout by code is not the good solution. If your table layout is simple, I think it's not a big problem.
Here is a simple code how to create a layout by code :
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.addView(new TextView(this));
setContentView(layout);
}
And as you see, it looks ugly !
Hope this help :)
#: Edit for additional question about Relative Layout:
In RelativeLayout (and some Layout of android), there is an object LayoutParamsto determine some properties of sub-layout (TextView, Button... is called sub-layout too if you put in other Layout)
Here is an example :
RelativeLayout layout = new RelativeLayout(this);
TextView textView = new TextView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
params.addRule(RelativeLayout.BELOW, textView.getId());
layout.addView(textView, params);
You should notice BELOW, it is one of many int constant such as Right_of.... You can see on Android Document about these.

Sidebar on Eclipse RCP

I've just started playing with Eclipse RCP.
A few things that I would like to accomplish:
How do I maximize the initial size of the application?
I would like to create a sidebar type view on my left and would like to fix the size of that view and remove any title bar, minimize/ maximize/ close from that side-bar.
Can anyone help me please?
Thank you.
First, some tutorials like Vogella's are a must read ;)
RCP Tutorial
JFace Tutorial
For 1/, this has to do with the IWorkbenchWindowConfigurer, like:
configurer.getWindow().getShell().setMaximized( true );
on postWindowOpen( IWorkbenchWindowConfigurer configurer ) of your WorkbenchAdvisor.
This thread has other alternatives.
For 2/, you can do it declaratively or by program, like this thread shows:
You can do it in plugin.xml, by providing extension to point org.eclipse.ui.perspectiveExtensions by specifying showTitle="false" on the view element.
or You can do it programmatically in Your PerspectiveFactory implementation:
public void createInitialLayout(IPageLayout layout) {
...
layout.addStandaloneView(View.ID, false,
IPageLayout.LEFT, 1.0f, editorArea);
...
}
Sidebar can be create via using viewpart and adjust in perspective using IPerspective in right or left side and given window size.