I am using a Nattable inside a eclipse ViewPart. My RCP application is such that, each time I open the view, the table can have different columns based on the datamodel(represented by a different POJO) I wish to display.In short, can I do something like the below? :
`
IWorkBenchPage page = .....;
MyView view = page.openView(MyViewID,"myview",VIEW_ACTIVATE);
IDataProvider dp = ....;
// the following statement will set the dataprovider, the necessary layers
view.dataProvider(dp);
view.getTable().refresh();
....
`
I Believe this is possible, if you change the data provider (including the column accessor).
I have a similar situation in my product, and I found that the easiest way is to dispose the old table and recreate a new table with the new data.
Related
I'm making a to-do list app and after user presses the button I create a new GridLayout(and all the data about time and name of the task inside of it) and add it into my RelativeLayout. How do I save those GridLayouts in UI so after the activity is destroyed and launched again those layouts are there.
After pressing the button I trigger the Create Activity method
public void CreateActivity(String name,int hours, int minutes,int i)
{
RelativeLayout.LayoutParams relparams= new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
relparams.addRule(RelativeLayout.BELOW,i);
relparams.setMargins(0,50,0,100);
Glayouts.add(new GridLayout(this));
Glayouts.get(i+1).setBackgroundColor(Color.GRAY);
Glayouts.get(i+1).setMinimumWidth(relative.getWidth());
Glayouts.get(i+1).setId(i+1);
Glayouts.get(i+1).setPadding(10,0,0,0);
GridLayout.LayoutParams namee = new GridLayout.LayoutParams();
namee.columnSpec = GridLayout.spec(0);
namee.rowSpec = GridLayout.spec(0);
namee.setGravity(Gravity.LEFT);
final TextView Actname = new TextView(this);
Actname.setText(name);
GridLayout.LayoutParams checkbox = new GridLayout.LayoutParams();
checkbox.columnSpec = GridLayout.spec(1);
checkbox.rowSpec = GridLayout.spec(0);
checkbox.setGravity(Gravity.RIGHT);
CheckBox check = new CheckBox(this);
// ADDING TO LAYOUT
Glayouts.get(i+1).addView(Actname,namee);
Glayouts.get(i+1).addView(check,checkbox);
relative.addView(Glayouts.get(i+1),relparams);
Theoretically when you extends View, then you can also override onSaveInstanceState and onRestoreInstanceState methods, where you must provide your own SavedState class that typically extends BaseSavedState. You can find info on that here
In your case, your layout is dynamic, therefore this doesn't really work. To tell you the truth, your layout probably shouldn't be constructed this way, you should be rendering the grid using a RecyclerView based on a "model" that describes this layout, render the items of the grid via the RecyclerView.Adapter, and you should persist either the "model", or the data you use to construct this model along with the user-inputted state so that you can re-construct the model that will be rendered via your RecyclerView.
You can read more about RecyclerView here.
You can read more about data persistence here.
You can read about using onSaveInstanceState to save data in Activities/Fragments across config change and process death (but not finishing then restarting the app) here.
You can’t. The best way to save state is to use some persistence mechanism, for example database (I’d recommend Room as it is officially supported by Google).
After clicking a button, you should put all the needed information (name, hours, minutes) in the database and when Activity is created, you can read all persisted data and - basing on it - create all needed layouts again.
Another option is storing data in SharedPreferences - it is much easier to setup, so you can also start with this solution. Please note, I'm suggesting it as a first step in the world of persistency in Android, not as a preferred solution for storing data.
In my RCP application there are two views.
I know how to get the active view. It's by using the following code:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
But I need the list of all the views, which are present in the Active Workbench Window.
Use
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences()
for that matter.
The views are on the page rather than the window:
IViewReference [] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
You can also get all pages (although there is usually only one)
IWorkbenchPage [] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
and windows:
IWorkbenchWindow [] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
To be sure you have everything iterate through all the pages on all the windows.
Hi Keerthi use below code to get views,
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences()
This will return arry of views iterator over the array and you will get each view.
To get view id, execute below
for(IViewPart view :PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViews()){
view.getViewSite().getId();//Get view id
}
I hope this will definitely work for you :)
I am creating a web page with several tabs. To implement that I am using wicket AjaxTabbedPanel and several AbstractTab. In each tab I have tables with data and I am using a javascript script to make the tables sortable.
public TabbedPage() {
List<ITab> tabs = new ArrayList<ITab>();
tabs.add(new AbstractTab(new Model<String>("first tab")) {
public Panel getPanel(String panelId) {
return new TablePanel(panelId);
}
});
tabs.add(new AbstractTab(new Model<String>("second tab")) {
public Panel getPanel(String panelId) {
return new TablePanel(panelId);
}
});
add(new AjaxTabbedPanel("tabs", tabs));
}
When I load the page the table in the tab selected by default is sortable. However, as soon as I click any of the links to jump to other tabs (including the one of the tab already selected), none of the tables in any of the tabs allows me sort them (including the one that was previously working - the table in the default tab). If I refresh the page I can sort the table (of the tab selected in the moment of the refresh), but as soon as I click in any of links to switch tabs, the tables stop having the sortable capability again. Any ideas of why is this happening?
EDIT:
I just found that if I replace the AjaxTabbedPanel by TabbedPanel I don't have this problem. Although I'm still not sure why is that. Can anyone enlighten me?
add(new TabbedPanel("tabs", tabs));
Sorting the table by JavaScript is most likely a function called with a specific DOM-Id and seems to be executed 'onLoad'. it then accesses the currently displayed table and does it's work.
Changing the content of your Panel by Ajax doesn't trigger 'onLoad' so the function isn't executed again. TabbedPanel reloads the page and therefore executed your script.
Selecting a previous sortable table with AjaxTabbedPanel doesn't work because of the dynamically generated DOM-Ids.
Your solution is to add a AjaxCallDecorator to the links from AjaxTabbedPanel or to include the script or at least the function call to your tabbed panels.
At least this it what comes to mind without seeing any sources...
EDIT:
You might want to look at The Wicket Wiki. There's a description on how to call js after clicking an AjaxLink. That's exactly what should solve your problem.
Summary: Just add
link.add(new AttributeAppender("onclick", new Model("myTableSortingScript();"), ";"));
to the links generated by AjaxTabbedPanel.
In Wicket 6.0 you can run JavaScript on a component basis: Just override renderHead(IHeaderResponse response) for your component:
#Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(new OnLoadHeaderItem("initalizeMe(\"" + getMarkupId() + "\");"));
}
initializeMe(mycomponentId) is executed every time the component is loaded by the AjaxTabbedPanel. This also works with the standard TabbedPanel.
No real idea since I'm not sure what the code is doing but I had a similar problem with my Panel Manager. Basically if you dynamically load HTML into a panel (a div or another element) using "innerhtml" script in the content will not be executed.
To get around this I scan the loaded content for "script" tags and append them using the DOM methods - this does run the script and makes it available. My "load" method is:
// Load Content
Panel.load = function(Content) {
// "null" the old (to clear it)
Panel.innerHTML = null;
// Load the content
Panel.innerHTML = Content;
// Load Scripts
var AllScripts = Panel.getElementsByTagName("script");
var AllScriptsCnt = AllScripts.length;
for (var Cnt = 0; Cnt < AllScriptsCnt; Cnt++){
var CurScript = document.createElement('script');
CurScript.type = "text/javascript";
CurScript.text = AllScripts[Cnt].text;
Panel.appendChild(CurScript);
};
};
Again, not sure if this is the issue, but it sounds pretty much on target from my experience.
What im trying to do is have a table which does not appear editable directly but can be edited in some widget outside the table. That is, the selected node can be edited here, and all nodes use the same editor because i want it to always be shown.
What I've tried is to subclass QItemDelegate and just return the instance of QTextEdit i already have, like this:
class Delegate extends QItemDelegate {
#Override
public QWidget createEditor(QWidget parent, QStyleOptionViewItem option, QModelIndex index) {
return qtextEdit;
}
}
which works, except that when you leave the editor it gets destroyed. Maybe delegate isn't supposed to be used this way. So how can i achieve this?
(ps. im using jambi but c++ code is fine)
The QDataWidgetMapper class is exactly what you want, to edit the values of whatever record outside of the view in external controls.
Taken straight from the documentation, this is how you'd use it:
QDataWidgetMapper *mapper = new QDataWidgetMapper;
mapper->setModel(model);
mapper->addMapping(mySpinBox, 0);
mapper->addMapping(myLineEdit, 1);
mapper->addMapping(myCountryChooser, 2);
mapper->toFirst();
And, if you have a view (QTreeView / QListView / QTableView / etc) and you want to edit the currently selected item, connect the appropriate signal & slot:
connect(&view, SIGNAL(activated(QModelIndex)), mapper, SLOT(setCurrentModelIndex(QModelIndex)));
I am using Infragistics wingrid in my application. I have assigned a datasource to my wingrid. Now i want to add a new column at a specific location.
Can any one please tell me how can this be performed?
Regards, Savan.
Greetings,
I would add the new column to your datasource. Since the datasource is bound to the grid the column should appear.
It sounds like you're trying to add an unbound column. In this case you can add the following in the InitializeLayout delegate of the grid:
private void myUltraGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
e.Layout.Bands[0].Columns.Add("New Column Name");
}
Infragistics HOWTO:UltraWinGrid Layout Initialization
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.Aspx?ArticleID=1692
From the article:
"When the DataSource property of the grid is set to a source of data, the InitializeLayout event fires. The UltraWinGrid expects grid layout initialization to be performed inside this event.
This does not mean that you can’t tweak the layout at other times, but most of the layout-related properties should be set inside the InitializeLayout event."