When ever I double click the tree viewer file that file name should appear in the next form view
Sample.dat -> double click -> name should be appear Sample.dat and File related properties should be appear.
I created a treeViewer files and double click the file name that name is not appear.
Please kindly help me reg this,eclipse rcp,Juno,e4 etc..
Perspective class...
private void setLayouts(IPageLayout layout) {
// Range 0.05f to 0.95f....
IFolderLayout explorerFolderLayout = layout.createFolder("explorer", IPageLayout.LEFT, 0.25f, layout.getEditorArea());
explorerFolderLayout.addView(ExplorerView.ID);
view class..
viewer.addDoubleClickListener(new IDoubleClickListener() {
#Override
public void doubleClick(DoubleClickEvent event) {
// TODO Auto-generated method stub
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
FileName fn = null;
FileNameContainer fnc = null;
if (selection.isEmpty())
return;
List<Object> list = selection.toList();...
....
You need to add click listener to your tree
final Tree tree = new Tree(parent, SWT.BORDER);
tree.addMouseListener(new MouseListener(){
public void mouseDoubleClick(MouseEvent e) {
//get data of selected element
//we use array[0], because we have not multiselect tree
MyDataObject data = (MyDataObject) tree.getSelection()[0].getData();
//now you need to pass "data" to your view with file info
//I don't know how to do it in pre e4 RCP apps, so
//please read this answer: https://stackoverflow.com/a/2227764/1030113
//hope that helps
}
public void mouseDown(MouseEvent e) {}
public void mouseUp(MouseEvent e) {}
});
//to test
TreeItem treeItem1 = new TreeItem(tree, SWT.NONE);
treeItem1.setText("some item 1");
treeItem1.setData(new MyDataObject("somedata 1"));
TreeItem treeItem2 = new TreeItem(tree, SWT.NONE);
treeItem2.setText("some item 2");
treeItem2.setData(new MyDataObject("somedata 2"));
I don't know how to communicate between view in pre e4 RCP apps, but I found some usefull answers here: https://stackoverflow.com/a/2227764/1030113
Related
I Created a ToolItem "Save As" like image above, But it not display at toolbar position. So how to create a toolbar inside viewpart (Not use plugin.xml)
IMAGE EXAMPLE
This is my code Create Toolbar:
public void createToolbar(Composite parent) {
// Create composite Toolbar and set layout
toolBarComposite = new Composite(parent, SWT.NONE);
gridLayout = new GridLayout(1, false);
toolBarComposite.setLayout(gridLayout);
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBarComposite.setLayoutData(gridData);
// Create Toolbar
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBar = new ToolBar(toolBarComposite, SWT.FLAT);
toolBar.setLayoutData(gridData);
// Create Item
item = new ToolItem(toolBar, SWT.PUSH);
item.setImage(SAVE_IMAGE);
item.setToolTipText("Save (Ctrl + S)");
item.setEnabled(true);
item.addSelectionListener(new SelectionAdapter() {
private static final long serialVersionUID = -102212312093090431L;
#Override
public void widgetSelected(SelectionEvent e) {
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
Thank for your advance !
You're going to have to use contributions on the view site's action bar.
Example
// Copy-pasted from an existing project, so the code can be made nicer
private void createAdditionalToolbarActions()
{
getViewSite().getActionBars().getToolBarManager().add(new GroupMarker("additions")); //$NON-NLS-1$
getViewSite().getActionBars().getToolBarManager().prependToGroup("additions", new SaveAction()); //$NON-NLS-1$
getViewSite().getActionBars().updateActionBars();
}
The method getViewSite is part of ViewPart. Call this after the contents of the view have been created.
The SaveAction must implement IAction or IContributionItem. For convenience, just extend the SaveAction from org.eclipse.jface.action.Action and call methods such as setImageDescriptor and setToolTipText.
Do all your business login in the run override.
please help me, I use the GraphView library (http://www.jjoe64.com/p/graphview-library.html), it works. But i don't understand how to reset previous data.
Method redrawAll() does not work.
IT'S MY CODE:
public class MainActivity extends Activity implements OnClickListener{
private final static int DIALOG_ID=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnDialog=(Button)findViewById(R.id.btnDialog);
btnDialog.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.btnDialog:
createGraph();
break;
}
}
//graph create method
void createGraph(){
// draw sin curve
int num = 100;
GraphViewData[] data = new GraphViewData[num];
GraphView graphView;
double v=0;
for (int i=0; i<num; i++) {
v += 0.50;
data[i] = new GraphViewData(i, Math.random()*v);
}
// graph with dynamically genereated horizontal and vertical labels
graphView = new LineGraphView(
getBaseContext()
, "myGraph"
);
graphView.redrawAll();
((LineGraphView) graphView).setDrawBackground(true);
// add data
graphView.addSeries(new GraphViewSeries(data));
// set view port, start=2, size=10
graphView.setViewPort(2, 40);
graphView.setScalable(true);
LinearLayout layout = (LinearLayout)findViewById(R.id.lvGraphView);
layout.addView(graphView);
}
}
I guess by reset you mean to clear all the graph and then draw something new again? Then you could use graphView.removeAllSeries();.
one way is to remove the graphview View and completely recreate it.
The other way is to use the realtime feature. you should use the latest version of graphview directly from github.
You can change the data in the series using resetData or appendData. Take a look into the GraphView-Demo project on github.
exampleSeries1.resetData(new GraphViewData[] {
new GraphViewData(1, getRandom())
, new GraphViewData(2, getRandom())
, new GraphViewData(2.5, getRandom()) // another frequency
, new GraphViewData(3, getRandom())
, new GraphViewData(4, getRandom())
, new GraphViewData(5, getRandom())
});
I am Trying to create Eclipse Plugin which has a composite with two TreeViewer side by side. On click of each TreeViewer content Eclipse property view should give appropriate information. Now I wanted to set Selection provider for both of this treeviewer hence I used
setSelectionProvider(treeViewer1)
setSelectionProvider(treeviewer2)
But only the second added treeviewer get set since the first one is overwritten. I am intiating this two treeviewer from class Queue.java. Hence I implemented the interface ISelectionProvider over Queue.java as below:
public void addSelectionChangedListener(ISelectionChangedListener listener)
{
selectionChangedListeners.add(listener);
}
public void
removeSelectionChangedListener(ISelectionChangedListener listener)
{
selectionChangedListeners.remove(listener);
}
private void fireSelectionChanged(final SelectionChangedEvent event)
{
Object[] listeners = selectionChangedListeners.getListeners();
for (int i = 0; i < listeners.length; ++i)
{
final ISelectionChangedListener l =
(ISelectionChangedListener) listeners[i];
Platform.run(new SafeRunnable()
{
public void run()
{
l.selectionChanged(event);
}
#Override
public void handleException(Throwable e)
{
removeSelectionChangedListener(l);
}
});
}
}
public void setSelection(ISelection selection)
{
fireSelectionChanged(new SelectionChangedEvent(this, selection));
}
public ISelection getSelection()
{
ArrayList<Object> list = new ArrayList<Object>();
Object o = getProperties();
if (o instanceof IPropertySource)
list.add(o);
return new StructuredSelection(list);
}
Can anyone help me how to resolve this issue. I will be grateful. thanks in advance. Tor.
Your view would have to write a selection provider wrapper or mediator that would delegate to the viewer that currently had focus. Then your view would set it up something like this:
SelectionProviderWrapper wrapper = new SelectionProviderWrapper();
wrapper.addViewer(treeViewer1);
wrapper.addViewer(treeViewer2);
getSite().setSelectionProvider(wrapper);
I would check out org.eclipse.jdt.internal.ui.viewsupport.SelectionProviderMediator for an example of a selection provider for multiple JFace viewers.
I have implemented one SWT table having a button widget in one column. On click of a button I am deleting the entire row. But I don't understand how to refresh/redraw/update the table.
Table processListTable;
TableItem tableItem;
Image deleteImage = Activator.getImageDescriptor("icons/trash.gif").createImage();
private void addRowInTable() {
tableItem = new TableItem(processListTable, SWT.FILL);
tableItem.setText(0, "value 1");
tableItem.setText(1, "value 2");
TableEditor editor = new TableEditor(processListTable);
final Button deleteButton = new Button(processListTable, SWT.PUSH | SWT.FILL);
deleteButton.pack();
editor.minimumWidth = deleteButtonButton.getSize().x;
editor.horizontalAlignment = SWT.CENTER;
editor.setEditor(deleteButtonButton, tableItem, 2);
deleteButtonButton.setImage(deleteImage);
deleteButtonButton.addListener(SWT.Selection, new SelectionListener(tableItem, checkButton));
}
class SelectionListener implements Listener {
TableItem item;
Button deleteButton;
public SelectionListener(TableItem item, Button deleteButton) {
this.item = item;
this.deleteButton = deleteButton;
}
public void handleEvent(Event event) {
this.deleteButton.dispose();
this.item.dispose();
}
}
Check SWT snippet remove selected items from Table.
Just call table.remove(int rowIdx); instead of item.dispose();
public void handleEvent(Event event) {
this.deleteButton.dispose();
this.trash.dispose();
this.item .dispose();
Table table = viewer.getTable();
table.getColumn(2).pack();
table.getColumn(2).setWidth(100);
}
This is the solution for refresh the SWT table.
Use the JFace TableViewer with a model class, delete the object from the model and refresh the TableViewer.
I'm trying to set the selected records of a ListGrid table object in SmartGWT, but I can't find any way of doing it. I know there's a getSelectedRecords() function, but no matching setSelectedRecords(). I tried to see if set/getSelectedState() would work, but GWT complains about needing a primary key and a DataSource object. Is there any way to set the selection of a ListGrid?
For this you can use one of the selectRecords() methods, like so:
public void onModuleLoad()
{
VLayout main = new VLayout();
final ListGrid grid = new ListGrid();
grid.setHeight(500);
grid.setWidth(400);
grid.setFields(new ListGridField("name", "Name"));
grid.setData(createRecords());
final IButton button = new IButton("Select some");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
grid.selectRecords(new int[]{2, 3}); //This will select index 2 and 3
}
});
main.addMember(grid);
main.addMember(button);
RootPanel.get().add(main);
}
private ListGridRecord[] createRecords()
{
return new ListGridRecord[]{
createRecord("monkey"),
createRecord("banana"),
createRecord("orange"),
createRecord("sun")
};
}
private ListGridRecord createRecord(String name)
{
ListGridRecord record = new ListGridRecord();
record.setAttribute("name", name);
return record;
}