Skip to content

Commit

Permalink
Added widget status checks to prevent SWT errors
Browse files Browse the repository at this point in the history
  • Loading branch information
blafond committed Dec 4, 2017
1 parent cd51022 commit 1c4d930
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.metamodels.core.Annotation;
import org.teiid.designer.metamodels.core.ModelAnnotation;
import org.teiid.designer.metamodels.diagram.Diagram;
import org.teiid.designer.metamodels.diagram.DiagramEntity;
import org.teiid.designer.relational.ui.actions.CreateRelationalIndexAction;
import org.teiid.designer.relational.ui.actions.CreateRelationalProcedureAction;
import org.teiid.designer.relational.ui.actions.CreateRelationalTableAction;
Expand Down Expand Up @@ -112,7 +114,8 @@
import org.teiid.designer.ui.viewsupport.ModelObjectUtilities;
import org.teiid.designer.ui.viewsupport.ModelUtilities;

public class ModelEditorMainPage extends EditorPart implements ModelEditorPage, IResourceChangeListener, INotifyChangedListener, ISelectionProvider {
public class ModelEditorMainPage extends EditorPart
implements ModelEditorPage, IResourceChangeListener, INotifyChangedListener, ISelectionProvider {

private static final String SPACE = StringConstants.SPACE;
private static final String TAB = StringConstants.TAB;
Expand Down Expand Up @@ -509,7 +512,7 @@ public void doubleClick(DoubleClickEvent event) {
}

private FilteredTree createFilteredTree(Composite parent) {
int style = SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
int style = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
FilteredTree transfersTree = new FilteredTree(parent, style,
new PatternFilter(), true) {
@Override
Expand Down Expand Up @@ -890,13 +893,22 @@ private void handleNotification(Notification notification) {
// If we get here, we need to make sure the

switch( notification.getEventType() ) {
// case Notification.ADD: {
//
// } break;
//
// case Notification.ADD_MANY: {
//
// } break;
case Notification.ADD:
case Notification.ADD_MANY:
case Notification.REMOVE:
case Notification.REMOVE_MANY:{
EObject eObj = NotificationUtilities.getEObject(notification);
if( eObj != null && ! (eObj instanceof Diagram || eObj instanceof DiagramEntity) ) {
Runnable work = new Runnable() {
@Override
public void run() {
modelTreeViewer.refresh();
}
};

UiUtil.runInSwtThread(work, true);
}
} break;

case Notification.SET: {
EObject eObj = NotificationUtilities.getEObject(notification);
Expand Down Expand Up @@ -959,35 +971,14 @@ public String getDateAsString( long timestamp ) {
return formatter.format(theDate);
}

class EmptySelectionProvider implements ISelectionProvider {
@Override
public void addSelectionChangedListener(ISelectionChangedListener listener) {

}

@Override
public ISelection getSelection() {
return new StructuredSelection(modelResource);
}

@Override
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
}

@Override
public void setSelection(ISelection selection) {

}
}

@Override
public void addSelectionChangedListener(ISelectionChangedListener listener) {

}

@Override
public ISelection getSelection() {
return null;
return new StructuredSelection(new Object());
}

@Override
Expand All @@ -997,5 +988,6 @@ public void removeSelectionChangedListener(ISelectionChangedListener listener) {

@Override
public void setSelection(ISelection selection) {
System.out.println(" MEMP >> Selection ="+ selection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ void internalSetFocus() {
event.widget = getTabFolder();
event.item = item;
event.type = SWT.Selection;
if( !tabFolderSelectionInProgress ) {
if( isTabActive(item) ) {
try {
getTabFolder().notifyListeners(SWT.Selection, event);
} catch (SWTException e) {
Expand All @@ -966,6 +966,18 @@ void internalSetFocus() {
setFocus(index);
}
}

boolean isTabActive(CTabItem item) {
if( tabFolderSelectionInProgress ) return false;

CTabFolder tabFolder = getTabFolder();

if( tabFolder == null || tabFolder.isDisposed() ) return false;

if( item == null || item.isDisposed() ) return false;

return true;
}

/**
* Sets focus to the control for the given page. If the page has an editor, this calls its <code>setFocus()</code> method.
Expand Down

0 comments on commit 1c4d930

Please sign in to comment.