Search in sources :

Example 1 with InputDialog

use of org.eclipse.jface.dialogs.InputDialog in project meclipse by flaper87.

the class Collection method makeActions.

private void makeActions() {
    insert = new Action(getCaption("collection.insertDoc")) {

        @Override
        public void run() {
            FileDialog dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
            dialog.setFilterExtensions(new String[] { "*.json" });
            String result = dialog.open();
            if (result != null) {
                try {
                    String jsonText = IOUtils.readFile(new File(result));
                    JSONObject jsonObj = new JSONObject(jsonText);
                    col.insert(JSONUtils.toDBObject(jsonObj));
                } catch (Exception ex) {
                    UIUtils.openErrorDialog(view.getSite().getShell(), ex.toString());
                }
            }
        }
    };
    rename = new Action(getCaption("collection.renameColl")) {

        @Override
        public void run() {
            InputDialog dialog = new InputDialog(view.getSite().getShell(), getCaption("collection.renameColl"), getCaption("collection.msg.newCollName"), col.getName(), new RequiredInputValidator(getCaption("collection.msg.inputCollName")));
            if (dialog.open() == InputDialog.OK) {
                try {
                    col.rename(dialog.getValue());
                } catch (MongoException ex) {
                    UIUtils.openErrorDialog(view.getSite().getShell(), ex.toString());
                }
                view.getViewer().refresh(getParent());
            }
        }
    };
    delete = new Action(getCaption("collection.deleteColl")) {

        @Override
        public void run() {
            if (MessageDialog.openConfirm(view.getSite().getShell(), getCaption("confirm"), String.format(getCaption("collection.msg.reallyDeleteColl"), col.getName()))) {
                col.drop();
                view.getViewer().refresh(getParent());
            }
        }
    };
}
Also used : RequiredInputValidator(org.mongodb.meclipse.util.RequiredInputValidator) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) InputDialog(org.eclipse.jface.dialogs.InputDialog) MongoException(com.mongodb.MongoException) JSONObject(org.json.JSONObject) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) MongoException(com.mongodb.MongoException)

Example 2 with InputDialog

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

the class MergeXliff method getTargetFilePath.

/**
	 * 获取合并后的文件的路径
	 * @param srcXlfPath
	 *            被分割的第一个文件
	 */
private void getTargetFilePath(final Vector<String> srcFilesPath) {
    String originalFileName = xlfhandler.getSplitOriginalName(srcFilesPath.get(0));
    if (originalFileName == null) {
        targetFilePath = null;
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                MessageDialog.openInformation(shell, Messages.getString("splitAndMergeXliff.MergeXliff.msgTitle2"), Messages.getString("splitAndMergeXliff.MergeXliff.msg9"));
            }
        });
    } else {
        String srcXlfLC = null;
        int leastLength = -1;
        // 循环遍历每一个文件,找出其中深度最低的文件,之后再取其父目录做为合并文件的位置
        for (String fileLC : srcFilesPath) {
            IFile iFile = ResourceUtils.fileToIFile(fileLC);
            String fullStr = iFile.getFullPath().toOSString();
            String separator = "\\".equals(System.getProperty("file.separator")) ? "\\\\" : "/";
            String[] array = fullStr.split(separator);
            if (leastLength == -1) {
                leastLength = array.length;
                srcXlfLC = fileLC;
            } else {
                if (array.length < leastLength) {
                    srcXlfLC = fileLC;
                }
            }
        }
        if (srcXlfLC == null || "".equals(srcXlfLC)) {
            return;
        }
        final String fileExtension = originalFileName.substring(originalFileName.lastIndexOf("."), originalFileName.length());
        originalFileName = originalFileName.substring(0, originalFileName.lastIndexOf(fileExtension)) + "_merged" + fileExtension;
        // 下面判断这个层次最高的文件,它的父的父是不是"XLIFF" 文件夹,如果是的话
        IFile srcXlfIFile = ResourceUtils.fileToIFile(srcXlfLC);
        IPath mergeFileParentIPath = null;
        if ("XLIFF".equals(srcXlfIFile.getParent().getParent().getName())) {
            mergeFileParentIPath = srcXlfIFile.getParent().getLocation();
        } else {
            mergeFileParentIPath = srcXlfIFile.getParent().getParent().getLocation();
        }
        targetFilePath = mergeFileParentIPath.append(originalFileName).toOSString();
        if (new File(targetFilePath).exists()) {
            final String initValue = "Copy of " + originalFileName;
            final String message = MessageFormat.format(Messages.getString("splitAndMergeXliff.MergeXliff.msg10"), originalFileName);
            final IPath curPath = mergeFileParentIPath;
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    InputDialog dialog = new InputDialog(shell, Messages.getString("splitAndMergeXliff.MergeXliff.dialogTitle"), message, initValue, null);
                    dialog.open();
                    if (dialog.getReturnCode() == Window.CANCEL) {
                        targetFilePath = null;
                    } else {
                        String newFileName = dialog.getValue();
                        if (!fileExtension.equals(newFileName.substring(newFileName.lastIndexOf("."), newFileName.length()))) {
                            newFileName = newFileName + fileExtension;
                        }
                        targetFilePath = curPath.append(newFileName).toOSString();
                    }
                }
            });
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) InputDialog(org.eclipse.jface.dialogs.InputDialog) IPath(org.eclipse.core.runtime.IPath) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 3 with InputDialog

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

the class RenameResourceAndCloseEditorAction method queryNewResourceName.

/**
	 * Return the new name to be given to the target resource.
	 * 
	 * @return java.lang.String
	 * @param resource
	 *            the resource to query status on
	 */
protected String queryNewResourceName(final IResource resource) {
    final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
    final IPath prefix = resource.getFullPath().removeLastSegments(1);
    IInputValidator validator = new IInputValidator() {

        public String isValid(String string) {
            if (resource.getName().equals(string)) {
                return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
            }
            IStatus status = workspace.validateName(string, resource.getType());
            if (!status.isOK()) {
                return status.getMessage();
            }
            if (workspace.getRoot().exists(prefix.append(string))) {
                return IDEWorkbenchMessages.RenameResourceAction_nameExists;
            }
            return null;
        }
    };
    InputDialog dialog = new InputDialog(shellProvider.getShell(), IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle, IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
    dialog.setBlockOnOpen(true);
    int result = dialog.open();
    if (result == Window.OK)
        return dialog.getValue();
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) InputDialog(org.eclipse.jface.dialogs.InputDialog) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) Point(org.eclipse.swt.graphics.Point) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 4 with InputDialog

use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.

the class GenericHiddenTextController method createButtonCommand.

protected Command createButtonCommand(final Button button) {
    if (button.getData(NAME).equals(HIDDEN_TEXT)) {
        InputDialog dlg = new InputDialog(button.getShell(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Messages.getString("GenericHiddenTextController.NewPassword"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Messages.getString("GenericHiddenTextController.NoteConvention"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "\"\"", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        null) {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
                 */
            @Override
            protected Control createDialogArea(Composite parent) {
                Control control = super.createDialogArea(parent);
                String paramName = (String) button.getData(PARAMETER_NAME);
                getText().setData(PARAMETER_NAME, paramName);
                // editionControlHelper.register(paramName, getText());
                return control;
            }
        };
        if (dlg.open() == Window.OK) {
            String paramName = (String) button.getData(PARAMETER_NAME);
            elem.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), new Boolean(true));
            return new PropertyChangeCommand(elem, paramName, dlg.getValue());
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) InputDialog(org.eclipse.jface.dialogs.InputDialog) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Composite(org.eclipse.swt.widgets.Composite)

Example 5 with InputDialog

use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.

the class PasswordController method createButtonCommand.

protected Command createButtonCommand(final Button button) {
    if (button.getData(NAME).equals(PASSWORD)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter param = elem.getElementParameter(paramName);
        //$NON-NLS-1$
        String initValue = "\"\"";
        if (param.getValue() != null && ContextParameterUtils.containContextVariables(param.getValue().toString())) {
            initValue = param.getValue().toString();
        }
        InputDialog dlg = new InputDialog(button.getShell(), //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("PasswordController.NewPassword"), //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("PasswordController.NoteConvention"), initValue, null) {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
                 */
            @Override
            protected Control createDialogArea(Composite parent) {
                Control control = super.createDialogArea(parent);
                String paramName = (String) button.getData(PARAMETER_NAME);
                getText().setData(PARAMETER_NAME, paramName);
                editionControlHelper.register(paramName, getText());
                return control;
            }
        };
        if (dlg.open() == Window.OK) {
            elem.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), new Boolean(true));
            return new PropertyChangeCommand(elem, paramName, dlg.getValue());
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) InputDialog(org.eclipse.jface.dialogs.InputDialog) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Composite(org.eclipse.swt.widgets.Composite) IElementParameter(org.talend.core.model.process.IElementParameter)

Aggregations

InputDialog (org.eclipse.jface.dialogs.InputDialog)31 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)12 Composite (org.eclipse.swt.widgets.Composite)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 FillLayout (org.eclipse.swt.layout.FillLayout)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Button (org.eclipse.swt.widgets.Button)5 Group (org.eclipse.swt.widgets.Group)5 Label (org.eclipse.swt.widgets.Label)5 IStatus (org.eclipse.core.runtime.IStatus)4 Control (org.eclipse.swt.widgets.Control)4 Event (org.eclipse.swt.widgets.Event)4 Listener (org.eclipse.swt.widgets.Listener)4 IllegalOperationException (cl.utfsm.acs.acg.core.IllegalOperationException)3 ArrayList (java.util.ArrayList)3 Status (org.eclipse.core.runtime.Status)3 ErrorDialog (org.eclipse.jface.dialogs.ErrorDialog)3 SashForm (org.eclipse.swt.custom.SashForm)3 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)3