Skip to content

Commit

Permalink
Added temp fix for Ts deadlock.
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Sep 5, 2018
1 parent 91afeb7 commit c83652c
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ec.nbdemetra.disaggregation;

import com.google.common.collect.ObjectArrays;
import ec.tss.Ts;
import ec.tss.TsInformationType;
import ec.tss.documents.MultiTsDocument;
import ec.tstoolkit.algorithm.IProcSpecification;
import ec.ui.interfaces.ITsCollectionView.TsUpdateMode;
import ec.ui.interfaces.ITsList.InfoType;
import ec.ui.list.JTsList;
import ec.ui.view.tsprocessing.DefaultProcessingViewer;
import java.awt.Dimension;
import java.util.Arrays;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JToolBar;

/**
*
* @author Jean
*/
final class FixedRegTsProcessingViewer extends DefaultProcessingViewer<MultiTsDocument> {

// FACTORY METHODS >
public static FixedRegTsProcessingViewer create(MultiTsDocument doc) {
FixedRegTsProcessingViewer viewer = new FixedRegTsProcessingViewer(DefaultProcessingViewer.Type.APPLY);
if (doc != null) {
viewer.setDocument(doc);
}
return viewer;
}
// visual components
private final JTsList yList, xList;
private final JLabel specLabel;
private boolean quietRefresh;

public FixedRegTsProcessingViewer(DefaultProcessingViewer.Type type) {
super(type);
yList = new JTsList();
yList.setVisible(true);
yList.setShowHeader(false);
yList.setTsUpdateMode(TsUpdateMode.Single);
yList.setInformation(new InfoType[]{InfoType.Name});
xList = new JTsList();
yList.setVisible(true);
xList.setShowHeader(false);
xList.setInformation(new InfoType[]{InfoType.Name});
this.specLabel = new JLabel("Spec: ");
specLabel.setVisible(true);
xList.setPreferredSize(new Dimension(50, 60));
yList.setPreferredSize(new Dimension(50, 60));

toolBar.add(Box.createHorizontalStrut(3), 0);
toolBar.add(new JLabel("Y: "), 1);
toolBar.add(new JToolBar.Separator(), 2);
toolBar.add(yList, 3);
toolBar.add(new JToolBar.Separator(), 4);
toolBar.add(new JLabel("X: "), 5);
toolBar.add(new JToolBar.Separator(), 6);
toolBar.add(xList, 7);
toolBar.add(new JToolBar.Separator(), 8);
toolBar.add(specLabel, 9);
toolBar.add(new JToolBar.Separator(), 10);
toolBar.add(Box.createHorizontalStrut(100), 11);

toolBar.setVisible(true);

// FIXME: there is a deadlock with Ts.Master#freeze() & TsFactory#update(TsInformation);
// these two lines force loading to prevent deadlock but might freeze EDT
xList.setFreezeOnImport(true);
yList.setFreezeOnImport(true);

xList.addPropertyChangeListener(JTsList.TS_COLLECTION_PROPERTY, evt -> {
if (!quietRefresh) {
updateDocument();
}
});
yList.addPropertyChangeListener(JTsList.TS_COLLECTION_PROPERTY, evt -> {
if (!quietRefresh) {
updateDocument();
}
});
}

private void updateDocument() {
try {

quietRefresh = true;
Ts[] y = yList.getTsCollection().toArray();
if (y == null || y.length == 0) {
getDocument().setInput(null);
}
Ts[] x = xList.getTsCollection().toArray();
if (x == null || x.length == 0) {
getDocument().setInput(y);
} else {
getDocument().setInput(ObjectArrays.concat(y[0], x));
}
refreshAll();
} catch (Exception err) {
} finally {
quietRefresh = false;
}
}

private void updateList() {
Ts[] s = getDocument().getTs();
if (s == null || s.length == 0) {
yList.getTsCollection().clear();
xList.getTsCollection().clear();
} else {
yList.getTsCollection().replace(s[0]);
xList.getTsCollection().replace(Arrays.copyOfRange(s, 1, s.length));
}
}

public void refreshSpec() {
MultiTsDocument doc = getDocument();
IProcSpecification spec = doc.getSpecification();
specLabel.setText("Spec: " + (spec != null ? spec.toString() : ""));
}

@Override
public void refreshHeader() {
try {
if (quietRefresh) {
return;
}
refreshSpec();
updateList();
} catch (Exception err) {
}
}

@Override
public void refreshView() {
super.refreshView();
refreshSpec();
}

@Override
public void dispose() {
super.dispose();
yList.dispose();
xList.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
package ec.nbdemetra.disaggregation;

import ec.nbdemetra.ui.NbUtilities;
import ec.nbdemetra.ws.WorkspaceFactory;
import ec.nbdemetra.ws.WorkspaceItem;
import ec.nbdemetra.ws.ui.WorkspaceTopComponent;
import ec.tss.disaggregation.documents.TsDisaggregationModelDocument;
import ec.ui.view.tsprocessing.RegTsProcessingViewer;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;

Expand All @@ -47,7 +44,7 @@
})
public final class TsDisaggregationModelTopComponent extends WorkspaceTopComponent<TsDisaggregationModelDocument> {

protected RegTsProcessingViewer panel;
protected FixedRegTsProcessingViewer panel;

public TsDisaggregationModelTopComponent() {
super(null);
Expand All @@ -63,7 +60,7 @@ public void initDocument() {
setName(getDocument().getDisplayName());
setToolTipText(Bundle.HINT_TsDisaggregationModelTopComponent());
initComponents();
panel = RegTsProcessingViewer.create(this.getDocument().getElement());
panel = FixedRegTsProcessingViewer.create(this.getDocument().getElement());
add(panel);
}

Expand Down

0 comments on commit c83652c

Please sign in to comment.