Skip to content

Commit

Permalink
register/unregister the property change listener when the text contro…
Browse files Browse the repository at this point in the history
…l is created/disposed
  • Loading branch information
koentsje committed May 29, 2014
1 parent 47e3425 commit 6d3a689
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import java.beans.PropertyChangeListener;

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.jboss.tools.forge.core.runtime.ForgeRuntime;
import org.jboss.tools.forge.ui.internal.viewer.ForgeTextViewer;

public abstract class AbstractForgeConsole
implements ForgeConsole, PropertyChangeListener {
implements ForgeConsole, PropertyChangeListener, DisposeListener {

private ForgeRuntime runtime;
private ForgeTextViewer textViewer;
Expand Down Expand Up @@ -39,7 +41,17 @@ public Control createControl(Composite parent) {
if (textViewer == null) {
textViewer = createTextViewer(parent);
}
Control result = textViewer.getControl();
getRuntime().addPropertyChangeListener(this);
result.addDisposeListener(this);
return textViewer.getControl();
}

@Override
public void widgetDisposed(DisposeEvent event) {
if (event.getSource() == getTextViewer().getControl()) {
getRuntime().removePropertyChangeListener(this);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class ForgeConsoleImpl extends AbstractForgeConsole {

public ForgeConsoleImpl(ForgeRuntime runtime) {
super(runtime);
getRuntime().addPropertyChangeListener(this);
}

@Override
Expand Down Expand Up @@ -47,5 +46,5 @@ public void propertyChange(PropertyChangeEvent evt) {
getTextViewer().stopConsole();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class ForgeConsoleImpl extends AbstractForgeConsole {

public ForgeConsoleImpl(ForgeRuntime runtime) {
super(runtime);
getRuntime().addPropertyChangeListener(this);
}

@Override
Expand Down

0 comments on commit 6d3a689

Please sign in to comment.