Search in sources :

Example 31 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.

the class RepositoryImportProgressDialog method transOverwritePrompt.

public boolean transOverwritePrompt(TransMeta transMeta) {
    MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "RepositoryImportDialog.OverwriteTrans.Title"), null, BaseMessages.getString(PKG, "RepositoryImportDialog.OverwriteTrans.Message", transMeta.getName()), MessageDialog.QUESTION, new String[] { BaseMessages.getString(PKG, "System.Button.Yes"), BaseMessages.getString(PKG, "System.Button.No") }, 1, BaseMessages.getString(PKG, "RepositoryImportDialog.DontAskAgain.Label"), !askOverwrite);
    MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
    int answer = md.open();
    askOverwrite = !md.getToggleState();
    return (answer & 0xFF) == 0;
}
Also used : MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle)

Example 32 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.

the class RepositoryImportProgressDialog method jobOverwritePrompt.

public boolean jobOverwritePrompt(JobMeta jobMeta) {
    MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "RepositoryImportDialog.OverwriteJob.Title"), null, BaseMessages.getString(PKG, "RepositoryImportDialog.OverwriteJob.Message", jobMeta.getName()), MessageDialog.QUESTION, new String[] { BaseMessages.getString(PKG, "System.Button.Yes"), BaseMessages.getString(PKG, "System.Button.No") }, 1, BaseMessages.getString(PKG, "RepositoryImportDialog.DontAskAgain.Label"), !askOverwrite);
    MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
    int answer = md.open();
    askOverwrite = !md.getToggleState();
    return (answer & 0xFF) == 0;
}
Also used : MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle)

Example 33 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.

the class TransGraph method handleTransMetaChanges.

public void handleTransMetaChanges(TransMeta transMeta) throws KettleException {
    if (transMeta.hasChanged()) {
        if (spoon.props.getAutoSave()) {
            spoon.saveToFile(transMeta);
        } else {
            MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "TransLog.Dialog.FileHasChanged.Title"), null, BaseMessages.getString(PKG, "TransLog.Dialog.FileHasChanged1.Message") + Const.CR + BaseMessages.getString(PKG, "TransLog.Dialog.FileHasChanged2.Message") + Const.CR, MessageDialog.QUESTION, new String[] { BaseMessages.getString(PKG, "System.Button.Yes"), BaseMessages.getString(PKG, "System.Button.No") }, 0, BaseMessages.getString(PKG, "TransLog.Dialog.Option.AutoSaveTransformation"), spoon.props.getAutoSave());
            MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
            int answer = md.open();
            if ((answer & 0xFF) == 0) {
                spoon.saveToFile(transMeta);
            }
            spoon.props.setAutoSave(md.getToggleState());
        }
    }
}
Also used : MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 34 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.

the class TransGraph method splitHop.

private void splitHop(TransHopMeta hi) {
    int id = 0;
    if (!spoon.props.getAutoSplit()) {
        MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "TransGraph.Dialog.SplitHop.Title"), null, BaseMessages.getString(PKG, "TransGraph.Dialog.SplitHop.Message") + Const.CR + hi.toString(), MessageDialog.QUESTION, new String[] { BaseMessages.getString(PKG, "System.Button.Yes"), BaseMessages.getString(PKG, "System.Button.No") }, 0, BaseMessages.getString(PKG, "TransGraph.Dialog.Option.SplitHop.DoNotAskAgain"), spoon.props.getAutoSplit());
        MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        id = md.open();
        spoon.props.setAutoSplit(md.getToggleState());
    }
    if ((id & 0xFF) == 0) {
        // Means: "Yes" button clicked!
        // Only split A-->--B by putting C in between IF...
        // C-->--A or B-->--C don't exists...
        // A ==> hi.getFromStep()
        // B ==> hi.getToStep();
        // C ==> selected_step
        // 
        boolean caExists = transMeta.findTransHop(selectedStep, hi.getFromStep()) != null;
        boolean bcExists = transMeta.findTransHop(hi.getToStep(), selectedStep) != null;
        if (!caExists && !bcExists) {
            StepMeta fromStep = hi.getFromStep();
            StepMeta toStep = hi.getToStep();
            // In case step A targets B then we now need to target C
            // 
            StepIOMetaInterface fromIo = fromStep.getStepMetaInterface().getStepIOMeta();
            for (StreamInterface stream : fromIo.getTargetStreams()) {
                if (stream.getStepMeta() != null && stream.getStepMeta().equals(toStep)) {
                    // This target stream was directed to B, now we need to direct it to C
                    stream.setStepMeta(selectedStep);
                    fromStep.getStepMetaInterface().handleStreamSelection(stream);
                }
            }
            // In case step B sources from A then we now need to source from C
            // 
            StepIOMetaInterface toIo = toStep.getStepMetaInterface().getStepIOMeta();
            for (StreamInterface stream : toIo.getInfoStreams()) {
                if (stream.getStepMeta() != null && stream.getStepMeta().equals(fromStep)) {
                    // This info stream was reading from B, now we need to direct it to C
                    stream.setStepMeta(selectedStep);
                    toStep.getStepMetaInterface().handleStreamSelection(stream);
                }
            }
            // In case there is error handling on A, we want to make it point to C now
            // 
            StepErrorMeta errorMeta = fromStep.getStepErrorMeta();
            if (fromStep.isDoingErrorHandling() && toStep.equals(errorMeta.getTargetStep())) {
                errorMeta.setTargetStep(selectedStep);
            }
            TransHopMeta newhop1 = new TransHopMeta(hi.getFromStep(), selectedStep);
            if (transMeta.findTransHop(newhop1) == null) {
                transMeta.addTransHop(newhop1);
                spoon.addUndoNew(transMeta, new TransHopMeta[] { newhop1 }, new int[] { transMeta.indexOfTransHop(newhop1) }, true);
            }
            TransHopMeta newhop2 = new TransHopMeta(selectedStep, hi.getToStep());
            if (transMeta.findTransHop(newhop2) == null) {
                transMeta.addTransHop(newhop2);
                spoon.addUndoNew(transMeta, new TransHopMeta[] { newhop2 }, new int[] { transMeta.indexOfTransHop(newhop2) }, true);
            }
            int idx = transMeta.indexOfTransHop(hi);
            spoon.addUndoDelete(transMeta, new TransHopMeta[] { hi }, new int[] { idx }, true);
            transMeta.removeTransHop(idx);
            spoon.refreshTree();
        }
    // else: Silently discard this hop-split attempt.
    }
}
Also used : StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 35 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project translationstudio8 by heartsome.

the class XLFValidator method validateXliffFile.

/**
	 * 验证 XLIFF 文件的语言对是否与项目的语言对一致。
	 * @param iFile
	 *            ;
	 * @throws XPathEvalException
	 * @throws XPathParseException
	 * @throws NavException
	 */
public static boolean validateXliffFile(IFile iFile) {
    shell = Display.getDefault().getActiveShell();
    try {
        Object[] arrObj = getProjectLang(iFile);
        if (arrObj == null) {
            return false;
        }
        String xlfFolderPath = iFile.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
        String xlfFullPath = iFile.getFullPath().toOSString();
        if (!xlfFullPath.startsWith(xlfFolderPath) || iFile.getParent().getFullPath().toOSString().equals(xlfFolderPath)) {
            // 该 XLIFF 文件是 XLIFF 目录的直接子文件或者不在 XLIFF 的目录下
            if (!blnMsg1) {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(shell, Messages.getString("file.XLFValidator.msgTitle"), MessageFormat.format(Messages.getString("file.XLFValidator.msg1"), xlfFullPath), Messages.getString("file.XLFValidator.toggleStateMsg"), false, null, null);
                blnMsg1 = dialog.getToggleState();
            }
            return false;
        }
        Language projectSrcLang = (Language) arrObj[0];
        @SuppressWarnings("unchecked") List<Language> lstProjectTgtLang = (List<Language>) arrObj[1];
        // /test/XLIFF/zh-CN/split/test.xlf (zh-CN 在第三级目录下)
        String parentName = xlfFullPath.split(System.getProperty("file.separator").replaceAll("\\\\", "\\\\\\\\"))[3];
        Vector<String> languageVector = new Vector<String>();
        languageVector.add(parentName);
        if (LocaleService.verifyLanguages(languageVector)) {
            boolean flag = false;
            for (Language lang : lstProjectTgtLang) {
                if (lang.getCode().equalsIgnoreCase(parentName)) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                if (!blnMsg1) {
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(shell, Messages.getString("file.XLFValidator.msgTitle"), MessageFormat.format(Messages.getString("file.XLFValidator.msg2"), xlfFullPath), Messages.getString("file.XLFValidator.toggleStateMsg"), false, null, null);
                    blnMsg1 = dialog.getToggleState();
                }
                return false;
            }
        } else {
            if (!blnMsg1) {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(shell, Messages.getString("file.XLFValidator.msgTitle"), MessageFormat.format(Messages.getString("file.XLFValidator.msg3"), xlfFullPath), Messages.getString("file.XLFValidator.toggleStateMsg"), false, null, null);
                blnMsg1 = dialog.getToggleState();
            }
            return false;
        }
        String xlfSrcLang = null;
        String xlfTgtLang = null;
        VTDGen vg = new VTDGen();
        XMLModifier xm = null;
        boolean isConfirmSrc = false;
        boolean isConfirmTgt = false;
        String fileOsPath = ResourceUtils.iFileToOSPath(iFile);
        boolean result = false;
        try {
            result = vg.parseFile(fileOsPath, true);
        } catch (Exception e) {
        }
        if (!result) {
            MessageDialog.openError(shell, Messages.getString("file.XLFValidator.errorTitle"), MessageFormat.format(Messages.getString("file.XLFValidator.parseError"), fileOsPath));
            return false;
        }
        VTDNav vn = vg.getNav();
        VTDUtils vu = new VTDUtils(vn);
        AutoPilot ap = new AutoPilot(vn);
        ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
        ap.selectXPath("/xliff/file");
        String original = null;
        int tempi = ap.evalXPath();
        if (tempi == -1) {
            MessageDialog.openError(shell, Messages.getString("file.XLFValidator.errorTitle"), MessageFormat.format(Messages.getString("file.XLFValidator.parseError"), fileOsPath));
            return false;
        }
        do {
            xlfSrcLang = vu.getCurrentElementAttribut("source-language", null);
            xlfTgtLang = vu.getCurrentElementAttribut("target-language", null);
            original = vu.getCurrentElementAttribut("original", null);
            if (original == null || original.trim().isEmpty()) {
                MessageDialog.openWarning(shell, Messages.getString("file.XLFValidator.warningTitle"), MessageFormat.format(Messages.getString("file.XLFValidator.msg10"), xlfFullPath));
                return false;
            }
            String msg = null;
            // XLIFF 源语言为空或与项目源语言不一致;
            if (xlfSrcLang == null || !xlfSrcLang.equalsIgnoreCase(projectSrcLang.getCode())) {
                if (!blnIsOpenConfirmSrc && !isConfirmSrc) {
                    if (xlfSrcLang == null) {
                        msg = MessageFormat.format(Messages.getString("file.XLFValidator.msg4"), xlfFullPath, projectSrcLang.getCode());
                    } else {
                        msg = MessageFormat.format(Messages.getString("file.XLFValidator.msg5"), xlfFullPath, xlfSrcLang.toLowerCase(), projectSrcLang.getCode());
                    }
                    MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell, Messages.getString("file.XLFValidator.msgTitle2"), null, msg, MessageDialog.CONFIRM, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, Messages.getString("file.XLFValidator.toggleStateMsg"), false);
                    int returnCode = dialog.open();
                    if (returnCode == IDialogConstants.YES_ID) {
                        isConfirmSrc = true;
                        blnIsOpenConfirmSrcY = true;
                    } else if (returnCode == IDialogConstants.NO_ID) {
                        isConfirmSrc = false;
                        blnIsOpenConfirmSrcY = false;
                    }
                    blnIsOpenConfirmSrc = dialog.getToggleState();
                }
                if ((isConfirmSrc || (blnIsOpenConfirmSrc && blnIsOpenConfirmSrcY)) && xlfSrcLang != null) {
                    xm = vu.update(null, xm, "/xliff/file[@original=\"" + original + "\"]/@source-language", projectSrcLang.getCode(), VTDUtils.CREATE_IF_NOT_EXIST);
                } else if (!isConfirmSrc && !(blnIsOpenConfirmSrc && blnIsOpenConfirmSrcY)) {
                    return false;
                }
            }
            // XLIFF 目标语言为空,(且其所在的 XLIFF 一级子目录名称是项目的目标语言代码之一,已在上面验证)直接设置
            if (xlfTgtLang == null || xlfSrcLang == null) {
                // XLIFF 文件中源与目标都为空时,由于 VTD 要求不能在一个位置修改两次,因此使用下面的方式插入源与目标到 file 节点中
                if (xlfTgtLang == null && xlfSrcLang == null) {
                    String attrFragment = new StringBuffer(" source-language=\"").append(projectSrcLang.getCode()).append("\" target-language=\"").append(parentName).append("\"").toString();
                    // attrName="attrValue"
                    // ”
                    // 得到开始标记的结束位置
                    long i = vn.getOffsetAfterHead();
                    if (xm == null) {
                        xm = new XMLModifier(vn);
                    }
                    if (vn.getEncoding() < VTDNav.FORMAT_UTF_16BE) {
                        xm.insertBytesAt((int) i - 1, attrFragment.getBytes());
                    } else {
                        xm.insertBytesAt(((int) i - 1) << 1, attrFragment.getBytes());
                    }
                } else if (xlfTgtLang == null) {
                    xm = vu.update(null, xm, "/xliff/file[@original=\"" + original + "\"]/@target-language", parentName, VTDUtils.CREATE_IF_NOT_EXIST);
                } else if (xlfSrcLang == null) {
                    xm = vu.update(null, xm, "/xliff/file[@original=\"" + original + "\"]/@source-language", projectSrcLang.getCode(), VTDUtils.CREATE_IF_NOT_EXIST);
                }
            }
            if (xlfTgtLang != null) {
                // XLIFF 目标语言非空,但未放在对应的目录下。
                boolean flag = false;
                for (Language lang : lstProjectTgtLang) {
                    if (lang.getCode().equalsIgnoreCase(xlfTgtLang)) {
                        flag = true;
                        break;
                    }
                }
                String message = null;
                if (!flag) {
                    message = MessageFormat.format(Messages.getString("file.XLFValidator.msg6"), xlfFullPath, xlfTgtLang, parentName);
                } else if (!xlfTgtLang.equalsIgnoreCase(parentName)) {
                    message = MessageFormat.format(Messages.getString("file.XLFValidator.msg7"), xlfFullPath, xlfTgtLang, parentName);
                }
                if (!blnIsOpenConfirmTgt && !isConfirmTgt && message != null) {
                    MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell, Messages.getString("file.XLFValidator.msgTitle2"), null, message, MessageDialog.CONFIRM, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, Messages.getString("file.XLFValidator.toggleStateMsg"), false);
                    int returnCode = dialog.open();
                    if (returnCode == IDialogConstants.YES_ID) {
                        isConfirmTgt = true;
                        blnIsOpenConfirmTgtY = true;
                    } else if (returnCode == IDialogConstants.NO_ID) {
                        isConfirmTgt = false;
                        blnIsOpenConfirmTgtY = false;
                    }
                    blnIsOpenConfirmTgt = dialog.getToggleState();
                }
                if ((blnIsOpenConfirmTgt && blnIsOpenConfirmTgtY) || isConfirmTgt) {
                    xm = vu.update(null, xm, "/xliff/file[@original=\"" + original + "\"]/@target-language", parentName, VTDUtils.CREATE_IF_NOT_EXIST | VTDUtils.PILOT_TO_END);
                // vu.bind(xm.outputAndReparse());
                } else if (message != null) {
                    return false;
                }
            }
            // Bug #2329:文件语言更改成项目语言时应同时更改 source 节点的 xml:lang 属性值,如果 target 节点有 xml:lang 属性,也要修改成项目语言
            AutoPilot tempAp = new AutoPilot(vn);
            tempAp.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
            xm = vu.update(tempAp, xm, "/xliff/file[@original=\"" + original + "\"]/body//trans-unit/source/@xml:lang", projectSrcLang.getCode(), VTDUtils.CREATE_IF_NOT_EXIST | VTDUtils.PILOT_TO_END);
            xm = vu.update(tempAp, xm, "/xliff/file[@original=\"" + original + "\"]/body//trans-unit/target/@xml:lang", parentName, VTDUtils.PILOT_TO_END);
        } while (ap.evalXPath() != -1);
        if (xm != null) {
            // vu.bind(xm.outputAndReparse());
            vu.bind(vu.updateVTDNav(xm, ResourceUtils.iFileToOSPath(iFile)));
        }
        vg.clear();
        iFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (XPathParseException e) {
        e.printStackTrace();
        logger.error(Messages.getString("file.XLFValidator.logger1"), e);
        MessageDialog.openInformation(shell, Messages.getString("file.XLFValidator.msgTitle"), Messages.getString("file.XLFValidator.msg8"));
        return false;
    } catch (XPathEvalException e) {
        e.printStackTrace();
        logger.error(Messages.getString("file.XLFValidator.logger1"), e);
        MessageDialog.openInformation(shell, Messages.getString("file.XLFValidator.msgTitle"), Messages.getString("file.XLFValidator.msg8"));
        return false;
    } catch (NavException e) {
        e.printStackTrace();
        logger.error(Messages.getString("file.XLFValidator.logger1"), e);
        MessageDialog.openInformation(shell, Messages.getString("file.XLFValidator.msgTitle"), Messages.getString("file.XLFValidator.msg8"));
        return false;
    } catch (CoreException e) {
        logger.error("", e);
    } catch (ModifyException e) {
        logger.error("", e);
    }
    return true;
}
Also used : XMLModifier(com.ximpleware.XMLModifier) XPathParseException(com.ximpleware.XPathParseException) Language(net.heartsome.cat.common.locale.Language) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) ModifyException(com.ximpleware.ModifyException) ArrayList(java.util.ArrayList) List(java.util.List) Vector(java.util.Vector) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException) VTDGen(com.ximpleware.VTDGen) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) ModifyException(com.ximpleware.ModifyException) CoreException(org.eclipse.core.runtime.CoreException) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav)

Aggregations

MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)66 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)16 TableItem (org.eclipse.swt.widgets.TableItem)8 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)6 Point (org.pentaho.di.core.gui.Point)6 ArrayList (java.util.ArrayList)5 Shell (org.eclipse.swt.widgets.Shell)5 IOException (java.io.IOException)4 IProject (org.eclipse.core.resources.IProject)4 File (java.io.File)3 Display (org.eclipse.swt.widgets.Display)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 BackingStoreException (org.osgi.service.prefs.BackingStoreException)3 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)2 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)2 List (java.util.List)2 Job (org.eclipse.core.runtime.jobs.Job)2 IPerspectiveDescriptor (org.eclipse.ui.IPerspectiveDescriptor)2 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)2 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)2