Distinguishing between mouseDrag and mouseMove in Eclipse Mars - eclipse

Since I migrated on Mars the drag and drop functionality of my RCP app is not working anymore.
After some debugging I found out a different behavior in Mars from Luna in this class org.eclipse.gef.ui.parts.DomainEventDispatcher in the method:
/**
* #see EventDispatcher#dispatchMouseMoved(org.eclipse.swt.events.MouseEvent)
*/
public void dispatchMouseMoved(org.eclipse.swt.events.MouseEvent me) {
if (!editorCaptured) {
super.dispatchMouseMoved(me);
if (draw2dBusy())
return;
}
if (okToDispatch()) {
if ((me.stateMask & InputEvent.ANY_BUTTON) != 0)
domain.mouseDrag(me, viewer);
else
domain.mouseMove(me, viewer);
}
}
The distinguish between mouseDrag and mouseMove is not revealed anymore because me.stateMask is 0 even when I am dragging the mouse (click and drag) inside the editor. Does anyone know if this is an Eclipse Bug or new behavior?
UPDATE:
I researched more and the problem doesn't come from there, but there is a method: receive(org.eclipse.swt.events.MouseEvent me) in the SWTEventDispatcher:
private void receive(org.eclipse.swt.events.MouseEvent me) {
currentEvent = null;
updateFigureUnderCursor(me);
if (captured) {
if (mouseTarget != null)
currentEvent = new MouseEvent(this, mouseTarget, me);
} else {
IFigure f = root.findMouseEventTargetAt(me.x, me.y);
if (f == mouseTarget) {
if (mouseTarget != null)
currentEvent = new MouseEvent(this, mouseTarget, me);
return;
}
if (mouseTarget != null) {
currentEvent = new MouseEvent(this, mouseTarget, me);
mouseTarget.handleMouseExited(currentEvent);
}
setMouseTarget(f);
if (mouseTarget != null) {
currentEvent = new MouseEvent(this, mouseTarget, me);
mouseTarget.handleMouseEntered(currentEvent);
}
}
}
In the specific case when I click on a figure/editpart, after dispatchMouseReleased is called (from SWTEventDispatcher), in the method receive(..), on Luna 'IFigure f = root.findMouseEventTargetAt(me.x, me.y);' is null and now on Mars it returns a Figure. This is the current difference I found that makes the drag and drop not work.
Yet..I don't understand what the difference is between Luna and Mars that org.eclipse.draw2d.findMouseEventTargetAt works differently.

So I managed to solve this problem.. org.eclipse.draw2d.Figure.findMouseEventTargetInDescendantsAt was changed from Luna to Mars.
in Luna we have this code:
if (fig.containsPoint(PRIVATE_POINT.x, PRIVATE_POINT.y)) {
fig = fig.findMouseEventTargetAt(PRIVATE_POINT.x,
PRIVATE_POINT.y);
return fig;
}
Mars:
if (fig.containsPoint(PRIVATE_POINT.x, PRIVATE_POINT.y)) {
fig = fig.findMouseEventTargetAt(PRIVATE_POINT.x,
PRIVATE_POINT.y);
if (fig != null) {
return fig;
}
}
I have my own class that extends LayeredPane and I had to override this method to always return the figure, even when it's null. Somehow in the receive(MouseEvent me) method from SWTEventDispatcher the root.findMouseEventTargetAt(me.x, me.y) should return null in the specific case a figure is being clicked and dragged but was returning a value != null.

Related

checking paragraph property loses the selection

in my vsto addin i have some simple code on a timer
private void MainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (!dialogopen & Application.Documents.Count > 0)
{
var doc = Application.ActiveDocument;
Word.InlineShapes shps;
Word.Paragraphs pars;
try
{
pars = doc.Paragraphs;
}
catch (Exception)
{
return;
}
var pars2 = pars.Cast<Word.Paragraph>().ToList();
foreach (var obj in pars2)
{
if (obj.OutlineLevel == Word.WdOutlineLevel.wdOutlineLevelBodyText )//PROBLEM HERE
{
};
}
}
}
as soon as it reaches the line that checks the outlinelevel, even if i dont do a thing, the selection in the activedocument gets lost
of course the user cant use a plugin which keeps on canceling his selection...
googling didnt give me a thing
thanks
EDIT1
I tried making a static function for checking the styles, but it did not help. Here's the code
static public class Helpers
{
static public Word.Paragraph checkPars(List<Word.Paragraph> pars)
{
return pars.FirstOrDefault();//(x) => x.OutlineLevel == Word.WdOutlineLevel.wdOutlineLevelBodyText);
}
}
As you can see, I had to remove the actual check, since it was causing the cursor to blink and lose selection
please advise
We use the Application.ScreenUpdating = true; and this keep the selection for all properties in Paragraph except for the Range property.
Then, we tried to access the range via Reflection and this was the solution.
Range rng = (Range)typeof(Paragraph).GetProperty("Range").GetValue(comObj);
We tried to eliminate querying ActiveDocument thinking that that might have had side-effects that were causing the problem but that was not the case.
Then, we confirmed that the selection was not "lost" and screen-updating is the only problem, so we tried restoring the UI with Application.ScreenRefresh and while it did work, it causes the screen to flicker every time the timer fires and this is not good enough.
Finally, knowing that it's only a UI problem, I tried simply switching off Application.ScreenUpdating...
in ThisAddin
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Timer timer = new Timer(2000);
timer.Elapsed += (s, t) =>
{
var scrnUpdating = Application.ScreenUpdating;
Application.ScreenUpdating = false;
MainTimer.onElapsed(Application, t);
if (scrnUpdating)
Application.ScreenUpdating = true;
};
timer.Start();
}
In another class library (note that it's static, I still think this is the best way)...
public static class MainTimer
{
public static void onElapsed (Word.Application state, System.Timers.ElapsedEventArgs e)
{
if (state.Documents.Count > 0)
{
var doc = state.ActiveDocument;
Word.InlineShapes shps;
Word.Paragraphs pars;
try
{
pars = doc.Paragraphs;
}
catch (Exception)
{
return;
}
var pars2 = pars.Cast<Word.Paragraph>()
.Where(p => p.OutlineLevel == Word.WdOutlineLevel.wdOutlineLevelBodyText)
.Select(p => p) // do stuff with the selected parragraphs...
.ToList();
}
}
}
And this works for me.
The selection remains and is displayed in the UI without flicker.
I also eliminated some premature enumeration from your code: you don't meed the .ToList() before the foreach.

How to find framework element inside viewmodel using Prism

I previously used Caliburn.Micro for my projects before universal windows application. Now I'm porting my apps to universal windows and decided to use Prism Library. Because there are lots of uwp sample for that. But I'm too beginner and don't know how to convert my old viewmodels.
I'm using webview to show some generated html. In caliburn I can find webview in viewmodel using OnViewLoaded event;
protected override void OnViewLoaded(object view)
{
base.OnViewLoaded(view);
var frameworkElement = view as FrameworkElement;
if (frameworkElement == null)
throw new ArgumentException();
var browser = frameworkElement.FindName("browser") as WebView;
if (browser == null)
throw new ArgumentException();
_webBrowser = browser;
}
But I didn't find any event can provide this. In prism there are only OnNavigatedTo and OnNavigatingFrom events.
Do prism have workaround for that?
Sorry about late reply,
I aggree with Igor and Tseng that will break MVVM pattern. But I'm trying to do something complex. Maybe there is a way of doing with it MVVM but I don't want to lose too much time on this.
What I found solution for the problem is as following. I wrote a VisualHelper
public class VisualHelper
{
public static T FindVisualChildInsideFrame<T>(DependencyObject depObj) where T : DependencyObject
{
var frame = FindVisualChild<Frame>(depObj);
if (frame != null && frame.Content is Page)
return FindVisualChild<T>(frame.Content as Page);
return null;
}
public static T FindVisualChild<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
return (T)child;
}
T childItem = FindVisualChild<T>(child);
if (childItem != null)
return childItem;
}
}
return null;
}
}
In my viewmodel, using following code finds WebView control. I'm using SplitView control thats why I'm using FindVisualChildInsideFrame method.
public override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary<string, object> viewModelState)
{
base.OnNavigatedTo(e, viewModelState);
var browser = VisualHelper.FindVisualChildInsideFrame<WebView>(Window.Current.Content);
}

Eclipse scout cache form page

I want to cache state in form page when switching from page to page.
So : I have 3 page with forms and I want to data stays in forms when I switch from one to another.
I found this : https://wiki.eclipse.org/Scout/Concepts/Page_Detail_Form
#Override
protected void execPageActivated() throws ProcessingException {
if (getDetailForm() == null) {
PersonDetailForm form = new PersonDetailForm();
form.setPersonNr(getPersonNr());
setDetailForm(form);
form.startView();
}
}
and says that setDetailForm() caches datas
As already said, attaching a detail form to a page means the detail form will automatically be
hidden when the page gets deactivated and shown when the page gets activated (see
PageDetailFormChanged on Desktop). So the detail form actually gets cached and does not need to
be started more than once per page. This requires that the form does not get closed.
But this don't work for me.
My code is
#Override
protected void execPageActivated() throws ProcessingException {
// / Create and open form
if (getDetailForm() == null) {
MarginCalculationForm form = new MarginCalculationForm();
form.startModify();
setDetailForm(form);
}
super.execPageActivated();
}
but it stays on last page.
For example :
If I have page A,B,C and I open page A it create it self and set it to detailForm(). If I then open page B it is OK too. But if I then click on page A again it check if the detailForm() is not null (and it is not) so it stays on page B (insted of going on page A)
EDIT :
I figure that getDetailForm() is returning the right form but apparently super.execPageActivated() don't work.
I found out what was wrong.
Problem is in DefaultPageChangeStrategy class in Scout. Method pageChanged() is like this :
#Override
public void pageChanged(IOutline outline, IPage deselectedPage, IPage selectedPage) {
if (outline == null) {
return;
}
outline.clearContextPage();
IForm detailForm = null;
ITable detailTable = null;
ISearchForm searchForm = null;
// new active page
outline.makeActivePageToContextPage();
IPage activePage = outline.getActivePage();
if (activePage != null) {
try {
activePage.ensureChildrenLoaded();
}
catch (ProcessingException e1) {
SERVICES.getService(IExceptionHandlerService.class).handleException(e1);
}
if (activePage instanceof IPageWithTable) {
IPageWithTable tablePage = (IPageWithTable) activePage;
detailForm = activePage.getDetailForm();
if (activePage.isTableVisible()) {
detailTable = tablePage.getTable();
}
if (tablePage.isSearchActive()) {
searchForm = tablePage.getSearchFormInternal();
}
}
else if (activePage instanceof IPageWithNodes) {
IPageWithNodes nodePage = (IPageWithNodes) activePage;
detailForm = activePage.getDetailForm();
if (activePage.isTableVisible()) {
detailTable = nodePage.getInternalTable();
}
}
}
// remove first
if (detailForm == null) {
outline.setDetailForm(null);
}
if (detailTable == null) {
outline.setDetailTable(null);
}
if (searchForm == null) {
outline.setSearchForm(null);
}
// add new
if (detailForm != null) {
outline.setDetailForm(detailForm);
}
if (detailTable != null) {
outline.setDetailTable(detailTable);
}
if (searchForm != null) {
outline.setSearchForm(searchForm);
}
}
}
And if it is activePage a AbstractPage (and not AbstractPageWithTable AbstractPageWithNode), detailForm is always null and this break behavior.
So solution is to change AbstractPage with AbstractPageWithNode and add line
setTableVisible(false);
This line is needed because if it's not the firs time launch page will not be presented. (nodePage.getInternalTable() is not null but it is empty so :
if (detailTable != null) {
outline.setDetailTable(detailTable);
}
will present empty page.)

Mnemonics in GWT

I would like to create as Java Swing Mnemonics with GWT . But I don't know how to figure it out. I have googled for it but I didn't fond any sample codes for it . I want to bind some keyboard shortcut keys on my buttons. How can I achieve it ? Any suggestions would be really appreciated !
In general you can handle global keyboard shortcusts using a NativePreviewHandler. An example of this can you see here:
NativePreviewHandler nativePreviewHandler = new NativePreviewHandler() {
#Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt() != Event.ONKEYDOWN) {
return;
}
final NativeEvent nativeEvent = event.getNativeEvent();
final boolean altKey = nativeEvent.getAltKey();
final boolean ctrlKey = nativeEvent.getCtrlKey();
if(altKey && ctrlKey && nativeEvent.getKeyCode() == 'A') {
// Do Something
}
}
};
Event.addNativePreviewHandler(nativePreviewHandler);
But as far as I klnow, there's no generic way build into GWT to handle some kind of Action that is bound to a button/Menu as well as a keyboard shortcut. You will have to implement such an abstraction by yourselves.
I hope this code will help you. Here we are adding a key down handler on document element.
RootPanel.get().addDomHandler(new KeyDownHandler() {
#Override
public void onKeyDown(KeyDownEvent event) {
if (event.isControlKeyDown()) {
char ch = (char) event.getNativeKeyCode();
if (ch == 's' || ch == 'S') {
// do operation for Ctrl+S
} else if (ch == 'c' || ch == 'C') {
// do operation for Ctrl+C
}
// add more or use switch case
}
}
}, KeyDownEvent.getType());

Issue with Gwt-Radio Button

I am using same group name for two of my GWT-RadioButtons. When I click one of these, another one gets unchecked, which is good. But programmatically (when i do debug) the other radio button value is still remained as 'true' . As per my requirement it should be false. I am thinking that it is problem of GWT-RadioButton Group concept.
Does this problem of GWT - RadioButton?
The below is code snippet
indiaRadioBtn.setValue(true);
indiaRadioBtn.addClickHandler(new IndianRadioClickHandler());
othersRadioBtn.addClickHandler(new InternationalRadioClickHandler());
if (contactInfo != null) {
if (contactInfo.getPostalAddress().getCountry() != null) {
othersRadioBtn.setValue(true);
}
if (indiaRadioBtn.getValue()) {
index = -1;
for (StateOrProvince stateOrProvince : StateOrProvince.values()) {
index++;
if ((contactInfo.getPostalAddress().getState() != null)
&& contactInfo.getPostalAddress().getState().equals(stateOrProvince.name())) {
stateListBox.setSelectedIndex(index);
}
}
} else {
//some code }
class IndianRadioClickHandler implements ClickHandler {
#Override
public void onClick(ClickEvent event) {
//newOrUpdateContactInfoFormPanel.clear();
ContactInfo contactInfo = getSelectedContactInfo();
/**
* Used same panel and elements for both addresses, so clearing address for Indian.
*/
if (contactInfo != null) {
if (contactInfo.getPostalAddress().getCountry() != null
|| title.equals("Create New Address")) {
contactInfo = null;
}
}
newOrUpdateContactInfoFormPanel.add(getCompleteFormPanel(contactInfo));
}
}
if contactInfo != null then it is executing that loop, i am setting othersRadioBtn.setValue(true);
So my other radio button is should set to false according to group concept.. but it is not doing its job.