Results 1 to 2 of 2
  1. #1
    oberoi06 is offline Member
    Join Date
    May 2014
    Posts
    1
    Rep Power
    0

    Default Dialog is not disposed on windows 8

    HI i am using a frame over which i am loading a dialog. The singleton dialog holds a progress bar.
    I have created my own swing worker. i am controlling the construct method of swing worker(which functions like doInBackground method).
    I am trying to call hidedialog from an external file. The dialog gets stuck sometimes. How do i solve it . It works fine on win7 but fails on win8.



    public class LoadingProgressDialogSingleton extends com.manu.scpoweb.common.ds.client.swing.dialog.Dia log {
    protected static LoadingProgressDialogSingleton oneAndOnlyProgressDialog = null;
    JProgressBar progressBar = null;
    DFULoadStatusBean dfuLoadStatusBean = null;
    double progress;
    int progressComplete = 0;
    BusinessObjectUserContext uc = null;
    CopyProgressBarWorker copyProgressBarWorker = null;
    ProgressBarWorker progressBarWorker = null;
    public static synchronized LoadingProgressDialogSingleton getProgressDialog(IApplicationContext iApplicationContext, ClientDataManager dataManager){
    if (oneAndOnlyProgressDialog == null){
    oneAndOnlyProgressDialog = new LoadingProgressDialogSingleton(iApplicationContext .getParentFrame(),
    iApplicationContext.getResource(APMConstants.RESOU RCE_BUNDLE, "ProgressBar.Loading"), Boolean.TRUE);

    oneAndOnlyProgressDialog.progressBar = new JProgressBar(0, 100);
    oneAndOnlyProgressDialog.progressBar.setValue(0);
    oneAndOnlyProgressDialog.progressBar.setPreferredS ize(new Dimension(175, 20));
    oneAndOnlyProgressDialog.progressBar.setStringPain ted(true);
    oneAndOnlyProgressDialog.progressBar.setBorder(Bor derFactory.createBevelBorder(BevelBorder.LOWERED)) ;

    JLabel label = new JLabel(iApplicationContext.getResource(APMConstant s.RESOURCE_BUNDLE, "ProgressBar.Reloading"));

    JPanel center_panel = new JPanel();
    center_panel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1;
    gbc.insets = new Insets(2, 6, 2, 6);
    center_panel.add(label, gbc);
    gbc.gridy = 1;
    center_panel.add(oneAndOnlyProgressDialog.progress Bar, gbc);
    gbc.gridy = 2;
    center_panel.add(Box.createVerticalGlue(), gbc);

    oneAndOnlyProgressDialog.getContentPane().add(cent er_panel, BorderLayout.CENTER);
    oneAndOnlyProgressDialog.setLocationRelativeTo(nul l); // center on screen
    oneAndOnlyProgressDialog.setPreferredSize(new Dimension(350, 107));
    oneAndOnlyProgressDialog.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE);

    oneAndOnlyProgressDialog.uc = new BusinessObjectUserContext(iApplicationContext.getU ser().getUserName(),
    iApplicationContext.getUserLocale());
    oneAndOnlyProgressDialog.uc.setAttributes(dataMana ger.getUserContext().getUserPreferences());
    }
    return oneAndOnlyProgressDialog;

    }
    public void showDialog(java.util.List<AttributeUUID> promoOfferKeysOnly){

    final Thread showDialogThread = new Thread(new Runnable() {
    public void run() {
    toFront();
    show();
    }
    });
    showDialogThread.start();

    if (promoOfferKeysOnly != null && promoOfferKeysOnly.size() > 0 ) {
    progressBarWorker = new ProgressBarWorker();
    BusinessObjectUserContext uc = new BusinessObjectUserContext(oneAndOnlyProgressDialog .uc.getUserName(),
    oneAndOnlyProgressDialog.uc.getLocale());
    uc.setAttributes(oneAndOnlyProgressDialog.uc.getUs erPreferences());
    progressBarWorker.setBusinessObjectUserContext(uc) ;
    progressBarWorker.setDataKey(promoOfferKeysOnly.ge t(0));
    progressBarWorker.start();
    }
    }

    public static synchronized void hideDialog(){
    if (oneAndOnlyProgressDialog != null){
    ProgressBarWorker worker = oneAndOnlyProgressDialog.progressBarWorker;
    CopyProgressBarWorker copyWorker = oneAndOnlyProgressDialog.copyProgressBarWorker;
    oneAndOnlyProgressDialog.dispose();

    if(oneAndOnlyProgressDialog.isShowing())
    oneAndOnlyProgressDialog.setVisible(false);
    oneAndOnlyProgressDialog = null;
    if (worker!=null){
    worker.setProgressComplete();
    }
    if (copyWorker!=null){
    copyWorker.setCopyCompleted();
    }
    }
    }
    protected LoadingProgressDialogSingleton(Frame iParent, String iTitle, boolean iModal) {
    super(iParent, iTitle, iModal);
    }
    class ProgressBarWorker extends SwingWorker {
    BusinessObjectUserContext uc = null;
    AttributeUUID dataKey = null;

    public AttributeUUID getDataKey() {
    return dataKey;
    }

    public void setDataKey(AttributeUUID dataKey) {
    this.dataKey = dataKey;
    }
    public void setProgressComplete(){
    progressComplete = 100;
    }
    public Object construct() {
    progressComplete = 0;
    EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
    if (queue instanceof ManuEventQueue) {
    try {
    JAASUtilities.runAs(((ManuEventQueue) Toolkit.getDefaultToolkit().getSystemEventQueue()) .getSubject(),
    new PrivilegedExceptionAction() {
    public Object run() throws Exception {
    long totalDFUsCnt = 0;
    long basePriceLoadedCnt = 0;
    long baseCostLoadedCnt = 0;
    long udasLoadedCnt = 0;
    long histLoadedCnt = 0;
    long fcstLoadedCnt = 0;
    progressBar.setValue(5);
    //Initialize progress property.
    while (progressComplete < 5) {
    if (Thread.currentThread().isInterrupted())
    break;
    if (dataKey != null) {
    dfuLoadStatusBean = APMController.getDFULoadStatus(dataKey, uc);
    if (dfuLoadStatusBean == null || !dfuLoadStatusBean.isStrated()) {
    Thread.currentThread().sleep(5000);
    continue;
    } else {
    if (dfuLoadStatusBean.getNumberOfDFUsInOffer() != null && totalDFUsCnt != dfuLoadStatusBean.getNumberOfDFUsInOffer().getSeco nd()) {
    totalDFUsCnt = dfuLoadStatusBean.getNumberOfDFUsInOffer().getSeco nd();
    progressBar.setValue(10);
    }
    if (dfuLoadStatusBean.getDfuBaseCostStatusAndCountPai r() != null && (baseCostLoadedCnt != totalDFUsCnt)) {
    if (dfuLoadStatusBean.getDfuBaseCostStatusAndCountPai r().getFirst()) {
    baseCostLoadedCnt = totalDFUsCnt;
    progressComplete++;

    } else {
    baseCostLoadedCnt = dfuLoadStatusBean.getDfuBaseCostStatusAndCountPair ().getSecond();
    }
    }
    if (dfuLoadStatusBean.getDfuBasePriceStatusAndCountPa ir() != null && (basePriceLoadedCnt != totalDFUsCnt)) {
    if (dfuLoadStatusBean.getDfuBasePriceStatusAndCountPa ir().getFirst()) {
    basePriceLoadedCnt = totalDFUsCnt;
    progressComplete++;

    } else {
    basePriceLoadedCnt = dfuLoadStatusBean.getDfuBasePriceStatusAndCountPai r().getSecond();
    }
    }
    if (dfuLoadStatusBean.getDfusUDAStatusAndCountPair() != null && (udasLoadedCnt != totalDFUsCnt)) {
    if (dfuLoadStatusBean.getDfusUDAStatusAndCountPair(). getFirst()) {
    udasLoadedCnt = totalDFUsCnt;
    progressComplete++;

    } else {
    udasLoadedCnt = dfuLoadStatusBean.getDfusUDAStatusAndCountPair().g etSecond();
    }
    }
    if (dfuLoadStatusBean.getDfusHISTStatusAndCountPair() != null && (histLoadedCnt != totalDFUsCnt)) {
    if (dfuLoadStatusBean.getDfusHISTStatusAndCountPair() .getFirst()) {
    histLoadedCnt = totalDFUsCnt;
    progressComplete++;
    } else {
    histLoadedCnt = dfuLoadStatusBean.getDfusHISTStatusAndCountPair(). getSecond();
    }
    }
    if (dfuLoadStatusBean.getDfusFCSTStatusAndCountPair() != null && (fcstLoadedCnt != totalDFUsCnt)) {
    if (dfuLoadStatusBean.getDfusFCSTStatusAndCountPair() .getFirst()) {
    fcstLoadedCnt = totalDFUsCnt;
    progressComplete++;
    } else {
    fcstLoadedCnt = dfuLoadStatusBean.getDfusFCSTStatusAndCountPair(). getSecond();
    }
    }
    if (totalDFUsCnt != 0.0)
    progress = (((baseCostLoadedCnt / totalDFUsCnt * 80) + (basePriceLoadedCnt / totalDFUsCnt * 80) +
    (udasLoadedCnt / totalDFUsCnt * 80) + (histLoadedCnt / totalDFUsCnt * 80) +
    (fcstLoadedCnt / totalDFUsCnt * 80)) / 500d);

    if (progress != 0.0) {
    progressBar.setValue((int) (progress * 100));
    Thread.currentThread().sleep(500);
    }
    }
    }
    }
    return null;
    }
    });
    } catch (PrivilegedActionException e) {
    e.printStackTrace();
    }
    }
    return null; //To change body of implemented methods use File | Settings | File Templates.
    }
    public void finished() {
    }

    public void setBusinessObjectUserContext(BusinessObjectUserCon text iUc) {
    uc = iUc;
    }
    }
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default Re: Dialog is not disposed on windows 8

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: 05-03-2013, 02:57 PM
  2. Replies: 1
    Last Post: 05-02-2013, 08:11 PM
  3. Replies: 3
    Last Post: 09-20-2012, 11:48 AM
  4. Question about Dialog windows and files
    By Moorag in forum New To Java
    Replies: 2
    Last Post: 03-19-2011, 01:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •