Java Code Examples for org.eclipse.jface.dialogs.MessageDialog.openConfirm()

The following are Jave code examples for showing how to use openConfirm() of the org.eclipse.jface.dialogs.MessageDialog class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: pmTrans   File: PmTrans.java   Source Code and License Vote up 6 votes
protected void exportTextFile() {
	boolean done = false;
	while (!done)
		if (!textEditor.isDisposed()) {
			FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
			fd.setFilterNames(new String[] { "Plain text file (*.txt)", "All Files (*.*)" });
			fd.setFilterExtensions(new String[] { "*.txt", "*.*" });
			String lastPath = Config.getInstance().getString(Config.LAST_EXPORT_TRANSCRIPTION_PATH);
			if (lastPath != null && !lastPath.isEmpty())
				fd.setFileName(lastPath);
			String file = fd.open();
			try {
				if (file != null) {
					Config.getInstance().putValue(Config.LAST_EXPORT_TRANSCRIPTION_PATH, file);
					File destFile = new File(file);
					boolean overwrite = true;
					if (destFile.exists())
						overwrite = MessageDialog.openConfirm(shell, "Overwrite current file?",
								"Would you like to overwrite " + destFile.getName() + "?");
					if (overwrite) {
						textEditor.exportText(new File(file));
						done = true;
					}
				} else
					done = true;
			} catch (Exception e) {
				e.printStackTrace();
				MessageBox diag = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
				diag.setMessage("Unable to export to file " + transcriptionFile.getPath());
				diag.open();
			}
		}
}
 
Example 2
Project: scanning   File: Stashing.java   Source Code and License Vote up 6 votes
/**
 * Stash using appropriate messages to the user.
 * @param models
 * @param shell
 */
@Override
public void save(Object object) {
	try {

		if (file.exists()) {
			boolean ok = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Confirm Overwrite", "Are you sure that you would like to overwrite '"+file.getName()+"'?");
			if (!ok) return;
		}

		stash(object);

	} catch (Exception e) {
		ErrorDialog.openError(Display.getCurrent().getActiveShell(), "Error Saving Information", "An exception occurred while writing the "+getStashName()+" to file.",
				              new Status(IStatus.ERROR, "org.eclipse.scanning.device.ui", e.getMessage()));
	    logger.error("Error Saving Information", e);
	}
}
 
Example 3
Project: scanning   File: ConsumerView.java   Source Code and License Vote up 6 votes
private void restart() {

	    HeartbeatBean bean = getSelection();
	    if (bean==null) return;

	    boolean ok = MessageDialog.openConfirm(getSite().getShell(), "Confirm Retstart", "If you restart this consumer other people's running jobs may be lost.\n\n"
				                                                                      + "Are you sure that you want to continue?");
	    if (!ok) return;

	    final KillBean kbean = new KillBean();
	    kbean.setExitProcess(false);
		kbean.setMessage("Requesting a restart of "+bean.getConsumerName());
	    kbean.setConsumerId(bean.getConsumerId());
	    kbean.setRestart(true);
		send(bean, kbean);

		consumers.clear();
        viewer.refresh();
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			logger.error("Refreshing consumers that we can process", e);
		}
        viewer.refresh();
	}
 
Example 4
Project: neoscada   File: ConfirmationDialogFuture.java   Source Code and License Vote up 5 votes
private Boolean showDialog ( final ConfirmationCallback cb, final Display display, final Shell parentShell, final String dialogTitle )
{
    switch ( cb.getConfirmationType () )
    {
        case CONFIRM:
            return MessageDialog.openConfirm ( parentShell, dialogTitle, cb.getLabel () ) ? true : null;
        case ERROR:
            MessageDialog.openError ( parentShell, dialogTitle, cb.getLabel () );
            return true;
        case WARNING:
            MessageDialog.openWarning ( parentShell, dialogTitle, cb.getLabel () );
            return true;
        case INFORMATION:
            MessageDialog.openInformation ( parentShell, dialogTitle, cb.getLabel () );
            return true;
        case QUESTION:
            return MessageDialog.openQuestion ( parentShell, dialogTitle, cb.getLabel () );
        case QUESTION_WITH_CANCEL:
        {
            final MessageDialog dialog = new MessageDialog ( parentShell, dialogTitle, null, cb.getLabel (), MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0 );
            final int result = dialog.open ();
            if ( result == 2 /*CANCEL*/)
            {
                return null;
            }
            else
            {
                return result == Window.OK;
            }
        }
        default:
            throw new IllegalArgumentException ( String.format ( "Unable to process type: %s", cb.getConfirmationType () ) );
    }
}
 
Example 5
Project: scanning   File: ConsumerView.java   Source Code and License Vote up 5 votes
private void stop() {

	    HeartbeatBean bean = getSelection();
	    if (bean==null) return;

	    boolean ok = MessageDialog.openConfirm(getSite().getShell(), "Confirm Stop", "If you stop this consumer it will have to be restarted by an administrator using a server hard restart.\n\n"
				                                                                      + "Are you sure that you want to do this?\n\n"
				                                                                      + "(NOTE: Long running jobs can be terminated without stopping the consumer!)");
	    if (!ok) return;


	    boolean notify = MessageDialog.openQuestion(getSite().getShell(), "Warn Users", "Would you like to warn users before stopping the consumer?\n\n"
						                        + "If you say yes, a popup will open on users clients to warn about the imminent stop.");
        if (notify) {

		final AdministratorMessage msg = new AdministratorMessage();
		msg.setTitle("'"+bean.getConsumerName()+"' will shutdown.");
		msg.setMessage("'"+bean.getConsumerName()+"' is about to shutdown.\n\n"+
		               "Any runs corrently running may loose progress notification,\n"+
				       "however they should complete.\n\n"+
		               "Runs yet to be started will be picked up when\n"+
		               "'"+bean.getConsumerName()+"' restarts.");
		try {
			final IPublisher<AdministratorMessage> send = service.createPublisher(new URI(Activator.getJmsUri()), IEventService.ADMIN_MESSAGE_TOPIC);
			send.broadcast(msg);
			} catch (Exception e) {
				logger.error("Cannot notify of shutdown!", e);
			}
        }

	    final KillBean kbean = new KillBean();
		kbean.setMessage("Requesting a termination of "+bean.getConsumerName());
	    kbean.setConsumerId(bean.getConsumerId());
		send(bean, kbean);

	}
 
Example 6
Project: scanning   File: StatusQueueView.java   Source Code and License Vote up 5 votes
/**
 * Edits a not run yet selection
 */
@SuppressWarnings({"squid:S3776", "squid:S135"})
protected void editSelection() {

	for (StatusBean bean : getSelection()) {
		if (bean.getStatus()!=org.eclipse.scanning.api.event.status.Status.SUBMITTED) {
			MessageDialog.openConfirm(getSite().getShell(), "Cannot Edit '"+bean.getName()+"'", "The run '"+bean.getName()+"' cannot be edited because it is not waiting to run.");
			continue;
		}

		try {
			final IConfigurationElement[] c = Platform.getExtensionRegistry().getConfigurationElementsFor(MODIFY_HANDLER_EXTENSION_POINT_ID);
			if (c!=null) {
				for (IConfigurationElement i : c) {
					final IModifyHandler handler = (IModifyHandler)i.createExecutableExtension("class");
					handler.init(service, createConsumerConfiguration());
					if (handler.isHandled(bean)) {
						boolean ok = handler.modify(bean);
						if (ok) continue;
					}
				}
			}
		} catch (Exception ne) {
			final String err = "Cannot modify "+bean.getRunDirectory()+" normally.\n\nPlease contact your support representative.";
			logger.error(err, ne);
			ErrorDialog.openError(getSite().getShell(), "Internal Error", err, new Status(IStatus.ERROR, Activator.PLUGIN_ID, ne.getMessage()));
			continue;
		}
		MessageDialog.openConfirm(getSite().getShell(), "Cannot Edit '"+bean.getName()+"'", "There are no editers registered for '"+bean.getName()+"'\n\nPlease contact your support representative.");
	}
}
 
Example 7
Project: scanning   File: DefaultResultsHandler.java   Source Code and License Vote up 5 votes
@Override
public boolean open(StatusBean bean) throws Exception {
	try {
		final IWorkbenchPage page = Util.getPage();

		final File fdir = new File(Util.getSanitizedPath(bean.getRunDirectory()));
		if (!fdir.exists()){
			MessageDialog.openConfirm(getShell(), "Directory Not Found", "The directory '"+bean.getRunDirectory()+"' has been moved or deleted.\n\nPlease contact your support representative.");
		    return false;
		}

		if (Util.isWindowsOS()) { // Open inside DAWN
			final String         dir  = fdir.getAbsolutePath();
			IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(dir+"/fred.html");
			final IEditorInput edInput = Util.getExternalFileStoreEditorInput(dir);
			page.openEditor(edInput, desc.getId());

		} else { // Linux cannot be relied on to open the browser on a directory.
			Util.browse(fdir);
		}
		return true;
	} catch (Exception e1) {
		ErrorDialog.openError(getShell(), "Internal Error", "Cannot open "+bean.getRunDirectory()+".\n\nPlease contact your support representative.",
				new Status(IStatus.ERROR, Activator.PLUGIN_ID, e1.getMessage()));
		return false;
	}
}
 
Example 8
Project: bdf2   File: ConnectionDeleteCommand.java   Source Code and License Vote up 5 votes
@Override
public void execute() {
	flag = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "提示", "删除外键约束时是否删除对应的列字段?");
	column = connection.getFkColumn();
	index = connection.getTarget().getColumns().indexOf(column);
	redo();
}
 
Example 9
Project: pandionj   File: PandionJUI.java   Source Code and License Vote up 5 votes
static PandionJView openViewDialog() {
	if(MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Open PandionJ view", PandionJConstants.Messages.RUN_DIALOG)) {
		try {
			return (PandionJView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(PandionJConstants.VIEW_ID);
		} catch (PartInitException e) {
			MessageDialog.openError(Display.getDefault().getActiveShell(), "Open PandionJ view", "View could not be opened.");
		}
	}
	return null;
}
 
Example 10
Project: neoscada   File: BlockControlImage.java   Source Code and License Vote up 4 votes
protected void toggleBlock ()
{
    final DataItemValue value = getBlockItemValue ();

    final Map<String, Variant> attributes = new HashMap<String, Variant> ();

    if ( !isActive ( value ) )
    {
        final String reason = getBlockReason ( value );
        if ( reason == null )
        {
            // user did not press "OK"
            return;
        }
        if ( reason.isEmpty () )
        {
            attributes.put ( "org.eclipse.scada.da.master.common.block.note", Variant.valueOf ( Messages.BlockControllerImage_String_BlockNote_None ) );//$NON-NLS-1$
        }
        else
        {
            attributes.put ( "org.eclipse.scada.da.master.common.block.note", Variant.valueOf ( reason ) );//$NON-NLS-1$                
        }
    }
    else
    {
        String blockNote = getActiveBlockAttribute ( value, ATTR_BLOCK_NOTE );
        if ( blockNote == null || blockNote.isEmpty () )
        {
            blockNote = Messages.BlockControllerImage_String_BlockNote_None;
        }

        if ( !MessageDialog.openConfirm ( getShell (), Messages.BlockControllerImage_ConfirmDialog_Title, String.format ( Messages.BlockControllerImage_ConfirmDialog_Message_Format, blockNote ) ) )
        {
            return;
        }

    }

    attributes.put ( "org.eclipse.scada.da.master.common.block.active", Variant.valueOf ( !isActive ( value ) ) );//$NON-NLS-1$

    try
    {
        final CallbackHandler handler = new DisplayCallbackHandler ( getShell (), "Confirmation", "Confirm block operation" );
        this.registrationManager.startWriteAttributes ( this.item.getConnectionString (), this.item.getId (), attributes, handler );
    }
    catch ( final InterruptedException e )
    {
        logger.warn ( "Failed to write", e );
    }
}
 
Example 11
Project: neoscada   File: FactoryEditor.java   Source Code and License Vote up 4 votes
public void handleDelete ()
{
    final ISelection sel = this.viewer.getSelection ();
    if ( sel == null || sel.isEmpty () || ! ( sel instanceof IStructuredSelection ) )
    {
        return;
    }

    final IStructuredSelection selection = (IStructuredSelection)sel;

    final Collection<String> items = new LinkedList<String> ();

    final Iterator<?> i = selection.iterator ();
    while ( i.hasNext () )
    {
        final ConfigurationDescriptor info = (ConfigurationDescriptor)i.next ();
        items.add ( info.getConfigurationInformation ().getId () );
    }

    if ( items.isEmpty () )
    {
        return;
    }

    if ( !MessageDialog.openConfirm ( this.viewer.getControl ().getShell (), "Delete configurations", String.format ( "Delete %s configuration entries", items.size () ) ) )
    {
        return;
    }

    final org.eclipse.core.runtime.jobs.Job job = this.factoryInput.createDeleteJob ( items );
    job.addJobChangeListener ( new JobChangeAdapter () {

        @Override
        public void done ( final IJobChangeEvent event )
        {
            refresh ();
        }

    } );
    job.schedule ();
}
 
Example 12
Project: scanning   File: SimulationConnection.java   Source Code and License Vote up 4 votes
@Override
public void configure() throws StreamConnectionException {
	MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Matthew Taylor TODO", "Please write a form to set the three things for simulation: URI, sleep time, cache size");
	// TODO Show a form setting URI, sleep time, cache size.
}
 
Example 13
Project: Hydrograph   File: WidgetUtility.java   Source Code and License Vote up 2 votes
/**
 * Elt confirm message.
 * 
 * @param message
 *            the message
 * @return true, if successful
 */
public static boolean eltConfirmMessage(String message){
    return MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), Messages.WARNING, message);
}