Example usage for org.eclipse.jface.dialogs MessageDialog openQuestion

List of usage examples for org.eclipse.jface.dialogs MessageDialog openQuestion

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog openQuestion.

Prototype

public static boolean openQuestion(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a simple Yes/No question dialog.

Usage

From source file:com.netxforge.editing.base.impl.ScreenFormService.java

License:Open Source License

private void createBackLink(Composite parent) {
    bckLnk = formToolkit.createHyperlink(parent, "Back", SWT.NONE);
    formToolkit.adapt(bckLnk);//from   w w w.  j a v  a  2s .c o  m
    bckLnk.addHyperlinkListener(new IHyperlinkListener() {
        public void linkActivated(HyperlinkEvent e) {
            if (getActiveScreen().isValid()) {
                if (dirtyWarning()) {
                    return; // Check for cancellation after dirty warning
                }
                popScreen();
            } else {
                if (editingService.isDirty()) {
                    boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
                            "Save needed, but entry not valid",
                            "You have unsaved changes, which are not valid yet, discard?");
                    if (result) {
                        // clean the service.
                        undoAndFlush();
                        popScreen();
                    } else {
                        // Stay on this screen.
                    }
                } else {
                    popScreen();
                }
            }
        }

        public void linkEntered(HyperlinkEvent e) {
        }

        public void linkExited(HyperlinkEvent e) {
        }
    });
}

From source file:com.netxforge.netxstudio.delta16042013.generics.presentation.GenericsModelWizard.java

License:Open Source License

/**
 * Do the work after everything is specified.
 * <!-- begin-user-doc -->/*from   ww w  .  ja  va  2  s .  c o  m*/
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public boolean performFinish() {
    try {
        // Get the URI of the model file.
        //
        final URI fileURI = getModelURI();
        if (new File(fileURI.toFileString()).exists()) {
            if (!MessageDialog.openQuestion(getShell(),
                    NetxstudioEditorPlugin.INSTANCE.getString("_UI_Question_title"),
                    NetxstudioEditorPlugin.INSTANCE.getString("_WARN_FileConflict",
                            new String[] { fileURI.toFileString() }))) {
                initialObjectCreationPage.selectFileField();
                return false;
            }
        }

        // Do the work within an operation.
        //
        IRunnableWithProgress operation = new IRunnableWithProgress() {
            public void run(IProgressMonitor progressMonitor) {
                try {
                    // Create a resource set
                    //
                    ResourceSet resourceSet = new ResourceSetImpl();

                    // Create a resource for this file.
                    //
                    Resource resource = resourceSet.createResource(fileURI);

                    // Add the initial model object to the contents.
                    //
                    EObject rootObject = createInitialModel();
                    if (rootObject != null) {
                        resource.getContents().add(rootObject);
                    }

                    // Save the contents of the resource to the file system.
                    //
                    Map<Object, Object> options = new HashMap<Object, Object>();
                    options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
                    resource.save(options);
                } catch (Exception exception) {
                    NetxstudioEditorPlugin.INSTANCE.log(exception);
                } finally {
                    progressMonitor.done();
                }
            }
        };

        getContainer().run(false, false, operation);

        return NetxstudioEditorAdvisor.openEditor(workbench, fileURI);
    } catch (Exception exception) {
        NetxstudioEditorPlugin.INSTANCE.log(exception);
        return false;
    }
}

From source file:com.netxforge.netxstudio.screens.editing.actions.WarningDeleteAction.java

License:Open Source License

/**
 * Run the delete with undo./*  w  w  w . ja va 2  s . c o m*/
 */
private void doRunUndo() {
    Collection<EObject> eObjects = ((WarningDeleteCommand) command).getObjects();

    EObject first = eObjects.iterator().next();

    boolean questionResult = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
            "Delete object of type: " + first.eClass().getName(),
            "Are you sure you want to delete \"" + editingService.getDelegator().getText(first)
                    + "\". Related objects (" + (eObjects.size() - 1) + ")");
    if (questionResult && warnUserOnReferences(eObjects)) {
        domain.getCommandStack().execute(command);
    }
}

From source file:com.netxforge.netxstudio.screens.editing.actions.WarningDeleteAction.java

License:Open Source License

/**
 * Run the delete without undo./* w  w  w.  j  av a2 s . com*/
 */
private void doRunNoWayBack() {
    Collection<EObject> eObjects = ((WarningNWBDeleteCommand) command).getObjects();

    EObject first = eObjects.iterator().next();
    boolean questionResult = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
            "Delete object of type (first object) : " + first.eClass().getName(),
            "Are you sure you want to delete \"" + editingService.getDelegator().getText(first)
                    + "\". Related objects (" + (eObjects.size() - 1)
                    + "), this operation can not be undone as the default undo limit(" + UNDO_LIMIT
                    + ") is exceeded");
    if (questionResult && warnUserOnReferences(eObjects)) {
        // Set the undo flag to false.
        // Note: it might already have been created with undo = false, when
        // selection of the objects occurred while pressing the CTRL key.
        ((WarningDeleteCommand) command).undo = false;
        domain.getCommandStack().execute(command);
    }
}

From source file:com.netxforge.netxstudio.screens.ScreenDialog.java

License:Open Source License

@Override
protected void cancelPressed() {
    if (screen.isValid()) {
        dirtyWarning();/*from   w w w.j ava  2 s .c om*/
        super.cancelPressed();
    } else {
        if (screen.getScreenService().getEditingService().isDirty()) {
            boolean result = MessageDialog.openQuestion(this.getShell(), "Save needed, but entry not valid",
                    "You have unsaved changes, which are not valid yet, discard?");
            if (result) {
                // clean the service.
                screen.getScreenService().undoAndFlush();
                super.cancelPressed();
            } else {
                // Stay on this screen.
            }
        } else {
            super.cancelPressed();
        }
    }
}

From source file:com.netxforge.netxstudio.screens.ScreenDialog.java

License:Open Source License

public void dirtyWarning() {
    // Warn for unsaved changes.
    if (screen.getScreenService().getEditingService().isDirty()) {
        boolean result = MessageDialog.openQuestion(this.getShell(), "Save needed",
                "You have unsaved changes, which will be discarded when not saved, save?");
        if (result && ScreenUtil.isDataScreenInjection(screen)) {
            ScreenUtil.dataScreenInjectionFor(screen).addData();
        } else {//from  w  ww . java 2 s. c o  m
            screen.getScreenService().undoAndFlush();
        }
    } else {
        // Flush the stack anyway.
        screen.getScreenService().getEditingService().getEditingDomain().getCommandStack().flush();
    }
}

From source file:com.nextep.datadesigner.dbgm.gui.ColumnEditorGUI.java

License:Open Source License

@Override
protected Control createSWTControl(Composite parent) {
    group = new ColumnSWTComposite(parent, 1, this);

    // Custom columns creation
    createCustomColumns(group);/*from  w ww .j  a  v a  2  s .  c  o  m*/
    // Initializing table editors
    initTableEditor();

    // Registering table
    initializeTable(group.getColumnsTable(), getTableEditor());

    // Deletion listener
    group.getColumnsTable().addListener(SWT.MouseUp, new Listener() {

        @Override
        public void handleEvent(Event event) {
            final IBasicTable table = (IBasicTable) getModel();
            if (table.updatesLocked() || !VersionHelper.ensureModifiable(table, false)) {
                return;
            }
            final TableColumn delCol = group.getColumnsTable().getColumn(0);
            final int delWidth = delCol.getWidth();
            final TableItem[] sel = group.getColumnsTable().getSelection();
            if (sel.length > 0 && sel[0].getData() instanceof IBasicColumn) {
                if (event.x < delWidth) {
                    final IBasicColumn column = (IBasicColumn) sel[0].getData();
                    final boolean confirmed = MessageDialog.openQuestion(group.getShell(),
                            MessageFormat.format(DBGMUIMessages.getString("table.editor.confirmDelColumnTitle"),
                                    column.getName()),
                            MessageFormat.format(DBGMUIMessages.getString("table.editor.confirmDelColumn"),
                                    column.getName(), column.getParent().getName()));
                    if (confirmed) {
                        ColumnEditorGUI.this.handleEvent(ChangeEvent.COLUMN_REMOVED,
                                (IBasicColumn) sel[0].getData(), null);
                    }
                }
            }

        }
    });
    return group;
}

From source file:com.nextep.datadesigner.dbgm.gui.ForeignKeyNewEditorGUI.java

License:Open Source License

private void cloneUnmappedColumns() {
    final ForeignKeyConstraint fk = (ForeignKeyConstraint) getModel();
    final boolean confirmed = MessageDialog.openQuestion(group.getShell(),
            MessageFormat.format(DBGMUIMessages.getString("fk.editor.dialog.confirmColumnCreationTitle"),
                    fk.getConstrainedTable().getName()),
            MessageFormat.format(DBGMUIMessages.getString("fk.editor.dialog.confirmColumnCreation"),
                    fk.getConstrainedTable().getName()));
    if (confirmed) {
        final IKeyConstraint remote = fk.getRemoteConstraint();
        final Iterator<IBasicColumn> remoteColIt = remote.getColumns().iterator();
        final Iterator<IBasicColumn> fkColIt = new ArrayList<IBasicColumn>(fk.getColumns()).iterator();
        while (remoteColIt.hasNext()) {
            final IBasicColumn remoteCol = remoteColIt.next();
            IBasicColumn mappedCol = null;
            if (fkColIt.hasNext()) {
                final IBasicColumn fkCol = fkColIt.next();
                if (!isMapped(fk, fkCol)) {
                    mappedCol = cloneColumn(fk, remoteCol.getName(), remoteCol);
                    int colIndex = fk.getColumns().indexOf(fkCol);
                    fk.removeColumn(mappedCol);
                    fk.addConstrainedColumn(colIndex, mappedCol);
                }/*from   w w  w  .  j a v  a2  s .  c o m*/
            } else {
                mappedCol = cloneColumn(fk, remoteCol.getName(), remoteCol);
                fk.addColumn(mappedCol);
            }
        }
        refreshConnector();
    }
}

From source file:com.nextep.datadesigner.dbgm.gui.TypeColumnEditorGUI.java

License:Open Source License

/**
 * @see com.nextep.datadesigner.gui.model.ControlledDisplayConnector#createSWTControl(org.eclipse.swt.widgets.Composite)
 *///from  w ww.  j  a  v a  2 s .  c o m
@Override
protected Control createSWTControl(Composite parent) {
    columns = new ColumnSWTComposite(parent, 2, this);
    editor = VersionedTableEditor.handle(columns.getColumnsTable(), getModel());
    TextColumnEditor.handle(editor, 1, ChangeEvent.NAME_CHANGED, this);
    ComboColumnEditor.handle(editor, 2, ChangeEvent.COLUMN_TYPE_CHANGED, this, Datatype.getTypes());
    TextColumnEditor.handle(editor, 3, ChangeEvent.COLUMN_LENGTH_CHANGED, this);
    TextColumnEditor.handle(editor, 4, ChangeEvent.COLUMN_PRECISION_CHANGED, this);

    // Initializing our table handlers
    initializeTable(columns.getColumnsTable(), editor);

    // Deletion listener
    columns.getColumnsTable().addListener(SWT.MouseUp, new Listener() {

        @Override
        public void handleEvent(Event event) {
            final IUserType type = (IUserType) getModel();
            if (type.updatesLocked() || !VersionHelper.ensureModifiable(type, false)) {
                return;
            }
            final TableColumn delCol = columns.getColumnsTable().getColumn(0);
            final int delWidth = delCol.getWidth();
            final TableItem[] sel = columns.getColumnsTable().getSelection();
            if (sel.length > 0 && sel[0].getData() instanceof TypeColumn) {
                if (event.x < delWidth) {
                    final TypeColumn column = (TypeColumn) sel[0].getData();
                    final boolean confirmed = MessageDialog.openQuestion(columns.getShell(),
                            MessageFormat.format(DBGMUIMessages.getString("table.editor.confirmDelColumnTitle"),
                                    column.getName()),
                            MessageFormat.format(DBGMUIMessages.getString("table.editor.confirmDelColumn"),
                                    column.getName(), column.getParent().getName()));
                    if (confirmed) {
                        TypeColumnEditorGUI.this.handleEvent(ChangeEvent.COLUMN_REMOVED,
                                (TypeColumn) sel[0].getData(), null);
                    }
                }
            }

        }
    });
    // Returning our columns table
    return columns;
}

From source file:com.nextep.datadesigner.vcs.gui.RepositoryFileNavigator.java

License:Open Source License

@Override
public void defaultAction() {
    IRepositoryFile file = (IRepositoryFile) getModel();
    if (file.getFileSizeKB() > 20000) {
        boolean isOK = MessageDialog.openQuestion(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Large file warning",
                MessageFormat.format(VCSUIMessages.getString("repositoryFileLargeWarn"),
                        String.valueOf(file.getFileSizeKB())));
        if (!isOK) {
            return;
        }/*from ww  w  .  j a  va2 s .  c  o m*/
    }
    super.defaultAction();
}