Skip to content

Commit

Permalink
RED-354 (#23, #33) fixing focus on saving problems; closing invalid e…
Browse files Browse the repository at this point in the history
…ditor on save
  • Loading branch information
michalanglart committed Jun 29, 2016
1 parent 4d90d73 commit 95b8b22
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
import org.eclipse.nebula.widgets.nattable.grid.cell.AlternatingRowConfigLabelAccumulator;
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
Expand All @@ -50,6 +51,7 @@
import org.eclipse.nebula.widgets.nattable.selection.MoveCellSelectionCommandHandler;
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
Expand Down Expand Up @@ -123,6 +125,7 @@
import org.robotframework.red.nattable.configs.RowHeaderStyleConfiguration;
import org.robotframework.red.nattable.configs.SelectionStyleConfiguration;
import org.robotframework.red.nattable.painter.SearchMatchesTextPainter;
import org.robotframework.red.swt.SwtThread;

import com.google.common.base.Supplier;
import com.google.common.collect.Range;
Expand Down Expand Up @@ -689,8 +692,24 @@ private void clearDocumentationMatches() {
}

@Persist
public void whenSaving() {
public void onSave() {
isDocumentationModified = false;
if (!table.isPresent()) {
return;
}
final ICellEditor cellEditor = table.get().getActiveCellEditor();
if (cellEditor != null && !cellEditor.isClosed()) {
final boolean commited = cellEditor.commit(MoveDirectionEnum.NONE);
if (!commited) {
cellEditor.close();
}
}
SwtThread.asyncExec(new Runnable() {
@Override
public void run() {
setFocus();
}
});
}

protected void waitForDocumentationChangeJob() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.tools.services.IDirtyProviderService;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.layout.GridDataFactory;
Expand All @@ -24,6 +25,7 @@
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
Expand All @@ -37,6 +39,7 @@
import org.eclipse.nebula.widgets.nattable.selection.MoveCellSelectionCommandHandler;
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
import org.eclipse.nebula.widgets.nattable.tooltip.NatTableContentTooltip;
Expand Down Expand Up @@ -263,6 +266,23 @@ public void setFocus() {
table.setFocus();
}

@Persist
public void onSave() {
final ICellEditor cellEditor = table.getActiveCellEditor();
if (cellEditor != null && !cellEditor.isClosed()) {
final boolean commited = cellEditor.commit(MoveDirectionEnum.NONE);
if (!commited) {
cellEditor.close();
}
}
SwtThread.asyncExec(new Runnable() {
@Override
public void run() {
setFocus();
}
});
}

private void setDirty() {
dirtyProviderService.setDirtyState(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.tools.services.IDirtyProviderService;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.layout.GridDataFactory;
Expand All @@ -31,6 +32,7 @@
import org.eclipse.nebula.widgets.nattable.config.NullComparator;
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.edit.command.EditSelectionCommand;
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
Expand All @@ -45,6 +47,7 @@
import org.eclipse.nebula.widgets.nattable.selection.MoveCellSelectionCommandHandler;
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
import org.eclipse.nebula.widgets.nattable.sort.SortConfigAttributes;
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
Expand Down Expand Up @@ -270,6 +273,23 @@ public void setFocus() {
table.setFocus();
}

@Persist
public void onSave() {
final ICellEditor cellEditor = table.getActiveCellEditor();
if (cellEditor != null && !cellEditor.isClosed()) {
final boolean commited = cellEditor.commit(MoveDirectionEnum.NONE);
if (!commited) {
cellEditor.close();
}
}
SwtThread.asyncExec(new Runnable() {
@Override
public void run() {
setFocus();
}
});
}

private void setDirty() {
dirtyProviderService.setDirtyState(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.tools.services.IDirtyProviderService;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ISelection;
Expand All @@ -35,6 +36,7 @@
import org.eclipse.nebula.widgets.nattable.selection.MoveCellSelectionCommandHandler;
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
import org.eclipse.nebula.widgets.nattable.tooltip.NatTableContentTooltip;
Expand Down Expand Up @@ -259,6 +261,23 @@ public void setFocus() {
table.setFocus();
}

@Persist
public void onSave() {
final ICellEditor cellEditor = table.getActiveCellEditor();
if (cellEditor != null && !cellEditor.isClosed()) {
final boolean commited = cellEditor.commit(MoveDirectionEnum.NONE);
if (!commited) {
cellEditor.close();
}
}
SwtThread.asyncExec(new Runnable() {
@Override
public void run() {
setFocus();
}
});
}

@SuppressWarnings("restriction")
private void setDirty() {
dirtyProviderService.setDirtyState(true);
Expand Down

0 comments on commit 95b8b22

Please sign in to comment.