RCP e4 programmatically create Toolbar with HandledToolItem in Part - rcp

I'm having a problem regarding the HandledToolItem in my MToolbar.
When pressing a button the application should create a new Part with a Toolbar and one HandledToolItem. The problem is that the HandledToolItem is always greyed out and I don't know why yet.
final MPart mPart = modelService.createModelElement(MPart.class);
mPart.setLabel("Test");
mPart.setElementId("newid");
mPart.setContributionURI("bundleclass://something");
mPart.setCloseable(true);
// create Toolbar
final MToolBar mBar = modelService.createModelElement(MToolBar.class);
mPart.setToolbar(mBar);
// create HanledToolItem
final MHandledToolItem mItem = modelService.createModelElement(MHandledToolItem.class);
mBar.getChildren().add(mItem);
// create Handle and Command
final MHandler toolHandler = modelService.createModelElement(MHandler.class);
final MCommand toolCommand = modelService.createModelElement(MCommand.class);
toolCommand.setElementId("dsadsadsa");
toolHandler.setCommand(toolCommand);
toolHandler.setContributionURI("bundleclass://something");
mItem.setIconURI("platform:/plugin/RCPCAN/icons/icon_con_scroll_lock.png");
mItem.setTooltip("Lock Table Scrollbar");
mItem.setCommand(toolCommand);
mItem.setEnabled(true);
// show part
partService.showPart(mPart, PartState.ACTIVATE);

You must add any handler you create to the list of handlers for the application or component:
#Inject
MApplication app;
...
app.getHandlers().add(handler);
Similarly commands must be added to the getCommands list.
Note: It is much easier to use a 'PartDescriptor' in your Application.e4xmi containing the design of the part. You can then just call
partService.showPart("part descriptor id", PartState.ACTIVATE);
without needing to create anything in your code.
If you want to create multiple copies of a part use:
MPart newPart = partService.createPart("part descriptor id");
partService.showPart(newPart, PartState.ACTIVATE);

Related

How to automatically sort JavaFX tableview when adding a new row to it?

I have a TableView that shows program names (String) and times (LocalDateTime). When I open it, it is automatically sorted by time.
But when I click to the new button, add a new item to the row, the new item is the first item in the table. After clicking on the column name of time, it still doesn't put it in its place (it's either the first or last item).
I'm trying to write here all the codes relating to it.
programTable = new TableView<>();
programTable.setEditable(true);
ObservableList<Program> programs = weddingScriptController.getPrograms();
SortedList<Program> sortedData = new SortedList<>(programs);
sortedData.comparatorProperty().bind(programTable.comparatorProperty());
Button newButton = new Button("Új");
newButton.setOnAction(e -> {
ProgramCreateWindow window = new ProgramCreateWindow();
window.display(programs);
});
//other stuff
TableColumn<Program, String> nameCol = new TableColumn<>("Név");
nameCol.setCellValueFactory(new PropertyValueFactory<Program, String>("name"));
TableColumn<Program, LocalDateTime> defaultTimeCol = new TableColumn<>("Idő");
defaultTimeCol.setCellValueFactory(new PropertyValueFactory<Program, LocalDateTime>("defaultTime"));
defaultTimeCol.setCellFactory(TextFieldTableCell.forTableColumn(new ProgramDateTimeStringConverter()));
defaultTimeCol.setSortType(TableColumn.SortType.ASCENDING);
//other stuff
programTable.setItems(sortedData);
programTable.getSortOrder().add(defaultTimeCol);
programTable.sort();
I've tried deleting that sorted list, and using the programs list, but it doesn't solve the problem.
programTable.setItems(programs);
I've also tried giving that function the sortedList, but it gets error when trying to add the new item to it.
window.display(sortedList);
What should I use to make this new item sorting work?
I know that it may be a dumb question, but I don't get it how it works, what am I doing right, what am I doing wrong.

Visual Studio extension - get reference to currently selected item in Git history

I managed to get a custom button added to the Git history context menu thanks to the help offered here.
I'm continuing work at the same extension and am again stuck. Once the button I've added to the context menu is clicked I need to get a reference to the commit that is selected when it is clicked. The idea is that I then need to grab the code changes associate with that commit.
I've gotten as far as getting a reference to the ActiveWindow which has a caption of "History - master". Which makes me believe I'm close. However, ActiveWindow.Selection is null. So I'm not sure where to go next to get the selected commit.
This is what I'm using to get the ActiveWindow property.
EnvDTE80.DTE2 dte = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2;
Anyone know how to grab a reference to the selected commit? Then use that to grab information about the commit including the changed files?
My question looks similar to this one, but for Git instead of TFS.
Thanks in advance for the help!
Took forever, but I finally managed to get at the selected commit. It involves reflection because a lot of the types used in the git extension are internal. There's got to be a better way to do this.
The IGitCommit that I'm able to retrieve doesn't have the changes for the commit populated. Hopefully getting the changes that are part of the commit isn't as challenging.
private IGitCommit GetSelectedCommit()
{
ThreadHelper.ThrowIfNotOnUIThread();
EnvDTE80.DTE2 dte = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2;
// GUID found via dte.ActiveWindow.ObjectKind
Guid gitHistoryWindowGuid = new Guid("116D2292-E37D-41CD-A077-EBACAC4C8CC4");
IVsUIShell vsUIShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
int toolWindowReturn = vsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fFrameOnly, ref gitHistoryWindowGuid, out IVsWindowFrame vsWindowFrame);
WindowFrame windowFrame = (WindowFrame)vsWindowFrame;
ToolWindowView toolWindowView = (ToolWindowView)windowFrame.FrameView;
// panel is of innaccessible type Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ContentHostingPanel
// so use base System.Windows.Controls.Grid
Grid contentHostingPanel = (Grid)toolWindowView.Content;
// Type Microsoft.VisualStudio.Platform.WindowManagement.Controls.GenericPaneContentPresenter is internal
// so use base ContentPresenter
ContentPresenter genericPaneContentPresenter = contentHostingPanel.Children[1] as ContentPresenter;
// Microsoft.VisualStudio.TeamFoundation.ToolWindowBase.ToolWindowBaseProxy is innaccessible
// so use base ContentPresenter
ContentPresenter toolWindowBaseProxy = (ContentPresenter)genericPaneContentPresenter.Content;
// Is of type Microsoft.TeamFoundation.Git.Controls.History.HistoryView,
// but this class is defined as internal so using base UserControl.
UserControl historyView = (UserControl)toolWindowBaseProxy.Content;
// Is of type Microsoft.TeamFoundation.Git.Controls.History.HistoryViewModel,
// but this class is defined as internal so using base Microsoft.TeamFoundation.MVVM.ViewModelBase.
ViewModelBase historyViewModel = (ViewModelBase)historyView.DataContext;
// Use reflection to get at properties of internal type HistoryViewModel and ObservableCollection<GitHistoryItem>
object gitHistoryItem = ((IList)historyViewModel.GetType().GetProperty("SelectedItems").GetValue(historyViewModel, null))[0];
IGitCommit gitCommit = (IGitCommit)gitHistoryItem.GetType().GetProperty("Commit").GetValue(gitHistoryItem, null);
return gitCommit;
}

Xamarin Android : Retain data on activity change and come back

I'm developing an app in Xamarin.android where in I want to retain the data of Edit Text, spinners etc. whenever i revisit to that activity. E.g.
Activity A contains Edit Text, Spinners.
I navigate to Activity B from Activity A, and whenever I come back to Activity A from B I want to retain those values of Edit Text and Spinners.
I tried using Put Extra and Get Extra, but as there are multiple values this approach seems to be wrong.
var activity2 = new Intent (this, typeof(Activity2));
activity2.PutExtra ("MyData", "Data from Activity1");
StartActivity (activity2);
Also OnSaveInstanceState and OnRestoreInstanceState is not working out for me as I'm using Fragments in my Activity A
Please Guide
Can't your fragments save their own data using Fragment.onSaveInstanceState ?
in your case you need to save this temp data in Shared Preference
here is example
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
ISharedPreferencesEditor editor = prefs.Edit();
editor.PutInt(("number_of_times_accessed", accessCount++);
editor.PutString("date_last_accessed", DateTime.Now.ToString("yyyy-MMM-dd"));
editor.Apply();
save what ever you want int or string
and when you load you activity retrieve this data and set it to your views
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
string passedString = prefs.GetString(key, defValue);
// here set retured data to your view
// Ex : YourEditText.Text = passedString
hope this help

How do I use ExcelDNA to select a cell?

I want to force the focus onto a particular cell, which I have a reference for via XlCall.Excel(XlCall.xlfCaller). I know how to do this in VSTO, but is there a way to do it with ExcelDNA?
One way would be to use the COM Automation interface, as you would from VBA or VSTO. Just be sure to use the Application object you get from ExcelDnaUtil.Application as your root. To convert from the ExcelReference that you received from xlfCaller to a COM Range object, you might try (this is the VB.NET version):
Private Function ReferenceToRange(ByVal xlRef As ExcelReference) As Object
Dim strAddress As String = XlCall.Excel(XlCall.xlfReftext, xlRef, True)
ReferenceToRange = ExcelDnaUtil.Application.Range(strAddress)
End Function
If you want to stick with the C API, you'd first have to select the right sheet, then the actual cell. So you might have:
string myCellSheet = (string)XlCall.Excel(XlCall.xlSheetNm, myCell);
XlCall.Excel(XlCall.xlcWorkbookSelect, new object[] { myCellSheet });
XlCall.Excel(XlCall.xlcFormulaGoto, myCell);
You won't be able to change the selection in a worksheet function, so I presume you are calling this from a macro or ribbon handler.
It's possible to do with ExcelDNA:
var activeCell = new ExcelReference(5, 5);
ExcelAsyncUtil.QueueAsMacro(() => XlCall.Excel(XlCall.xlcSelect, activeCell));
"ExcelAsyncUtil.QueueAsMacro" could be skipped, it's depends on context from which you call Excel command. If you call it from another Excel function - you should wrap it up with QueueAsMacro

Blackberry invalidate field not causing a repaint

I'm writing a Blackberry app. I have a custom list field where I can select an item in the list which pushes the edit screen onto the stack. I edit the item and save, and when I pop that screen off so I am back on my list screen, I want to view the update I just made reflected in the list. I have done this on other screens which just had LabelFields and it worked fine. However, with the list screen, calling invalidate() seems to do nothing. I know the value has saved correctly through print lines, and I see the paint() method in the listfield is getting called. But the only way I can get the list field to update is to delete it from the screen and re-add it. That seems wrong. What am I doing wrong?
public class ListTasksScreen extends MainScreen{
private TaskList tasks;
private CustomListField taskListField;
public ListTasksScreen (TaskList tasks){
super();
this.tasks = tasks;
Vector incompleteTasks = tasks.getIncompleteTasks();
taskListField = new CustomListField(incompleteTasks, tasks);
add(taskListField);
}
public void updateTaskList(TaskList t)
{
Vector incompleteTasks = t.getIncompleteTasks();
taskListField= new TaskListField(incompletetTasks, t);
//I just want to call taskListField.invalidate() here.
//the only thing that seems to work is deleting taskListField
//and re-adding
this.delete(taskListField);
add(taskListField);
}
}
Is there a typo in your code above? in the updateTaskList method you do:
taskListField= new TaskListField(incompletetTasks, t);
should it be:
taskListField= new CustomListField(incompletetTasks, t);
Anyway, I think the reason you are having problems is because when you update your task list you are actually creating a new CustomListField object. When you first do add(taskListField) you are passing a reference to the field to the screen, so it has its own reference. When you call taskListField= new CustomListField(incompletetTasks, t); you are only updating your own reference, not the one in the screen. So if you call invalidate the screen will repaint using the original reference, which must be using references to the original versions of incompleteTasks and tasks too.
The reason it works the other way is because you are actually removing the old reference and adding the new one, so the screen now knows of the updated data.
What you should do is add a method to your CustomListField that allows you to update the task list object. Then when you call that method on the existing reference to taskListField and then call invalidate, your paint method should now use the new values when it calls drawListRow in the callback.
to add item and update list:
add item to array/vector of list items
perform insert new row (listField.insert(listField.getSize());)

Resources