Java Code Examples for org.eclipse.jface.window.Window#OK

The following examples show how to use org.eclipse.jface.window.Window#OK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSarlLaunchShortcut.java    From sarl with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a configuration from the given collection of configurations that should be launched,
 * or {@code null} to cancel. Default implementation opens a selection dialog that allows
 * the user to choose one of the specified launch configurations.  Returns the chosen configuration,
 * or {@code null} if the user cancels.
 *
 * @param configList list of configurations to choose from.
 * @return configuration to launch or {@code null} to cancel.
 */
@SuppressWarnings("static-method")
protected ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList) {
	final IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
	final ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
	dialog.setElements(configList.toArray());
	dialog.setTitle(Messages.AbstractSarlLaunchShortcut_0);
	dialog.setMessage(Messages.AbstractSarlLaunchShortcut_1);
	dialog.setMultipleSelection(false);
	final int result = dialog.open();
	labelProvider.dispose();
	if (result == Window.OK) {
		return (ILaunchConfiguration) dialog.getFirstResult();
	}
	return null;
}
 
Example 2
Source File: SourceContainerWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void editAttributeEntry(CPListElementAttribute elem) {
	String key= elem.getKey();
	if (key.equals(CPListElement.OUTPUT)) {
		CPListElement selElement=  elem.getParent();
		OutputLocationDialog dialog= new OutputLocationDialog(getShell(), selElement, fClassPathList.getElements(), new Path(fOutputLocationField.getText()).makeAbsolute(), true);
		if (dialog.open() == Window.OK) {
			selElement.setAttribute(CPListElement.OUTPUT, dialog.getOutputLocation());
			fFoldersList.refresh();
			fClassPathList.dialogFieldChanged(); // validate
		}
	} else if (key.equals(CPListElement.EXCLUSION) || key.equals(CPListElement.INCLUSION)) {
		EditFilterWizard wizard= newEditFilterWizard(elem.getParent(), fFoldersList.getElements(), fOutputLocationField.getText());
		OpenBuildPathWizardAction action= new OpenBuildPathWizardAction(wizard);
		action.run();
	} else if (key.equals(CPListElement.IGNORE_OPTIONAL_PROBLEMS)) {
		String newValue= "true".equals(elem.getValue()) ? null : "true"; //$NON-NLS-1$ //$NON-NLS-2$
		elem.setValue(newValue);
		fFoldersList.refresh(elem);
	} else {
		if (editCustomAttribute(getShell(), elem)) {
			fFoldersList.refresh();
			fClassPathList.dialogFieldChanged(); // validate
		}
	}
}
 
Example 3
Source File: StringListFieldEditor.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates and returns a new item for the list.
 * This implementation opens a question dialog, where user can
 * enter a new item.
 * 
 * @return the string the user wanted to add, or null
 *         if the cancel button was pressed or the string was an empty one
 */
protected String getNewInputObject() {
    
    InputQueryDialog dialog =
        InputQueryDialog.createQuery("Enter string", "Please enter keyword",
                IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL);
    dialog.setValidator(this);
    
    int code = dialog.open();
    if (code == Window.OK) {
        
        String g = dialog.getInput();
        if (g != null && g.length() == 0) {
            return null;
        }
        
        return g;
    }
    return null;
}
 
Example 4
Source File: FlowInfoPage.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
private void openProcessWizard() {
	Flow flow = getModel();
	try {
		String wizardId = "wizards.new.process";
		IWorkbenchWizard w = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(wizardId).createWizard();
		if (!(w instanceof ProcessWizard))
			return;
		ProcessWizard wizard = (ProcessWizard) w;
		wizard.setRefFlow(flow);
		WizardDialog dialog = new WizardDialog(UI.shell(), wizard);
		if (dialog.open() == Window.OK) {
			Navigator.refresh(Navigator.findElement(ModelType.PROCESS));
		}
	} catch (Exception e) {
		Logger log = LoggerFactory.getLogger(getClass());
		log.error("failed to open process dialog from flow " + flow, e);
	}
}
 
Example 5
Source File: Controller.java    From arx with Apache License 2.0 6 votes vote down vote up
/**
 * File->New project.
 */
public void actionMenuFileNew() {

    if ((model != null) && model.isModified()) {
        if (main.showQuestionDialog(main.getShell(),
                                    Resources.getMessage("Controller.61"), //$NON-NLS-1$
                                    Resources.getMessage("Controller.62"))) { //$NON-NLS-1$
            actionMenuFileSave();
        }
    }

    // Separator
    final DialogProject dialog = new DialogProject(main.getShell());
    dialog.create();
    if (dialog.open() != Window.OK) {
        return;
    }

    // Set project
    reset();
    model = dialog.getProject();
    update(new ModelEvent(this, ModelPart.MODEL, model));
}
 
Example 6
Source File: IDEFileReportProvider.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public IPath getSaveAsPath( Object element )
{
	IFile file = null;
	if ( element instanceof IFileEditorInput )
	{
		IFileEditorInput input = (IFileEditorInput) element;
		file = input.getFile( );
	}
	SaveReportAsWizardDialog dialog = new SaveReportAsWizardDialog( UIUtil.getDefaultShell( ),
			new SaveReportAsWizard( model, file ) );
	if ( dialog.open( ) == Window.OK )
	{
		return dialog.getResult( );
	}
	return null;
}
 
Example 7
Source File: CheckConfigurationConfigureDialog.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Opens the module editor for the current selection.
 *
 * @param selection
 *          the selection
 */
private void openModule(ISelection selection) {

  Module m = (Module) ((IStructuredSelection) selection).getFirstElement();
  if (m != null) {

    Module workingCopy = m.clone();

    RuleConfigurationEditDialog dialog = new RuleConfigurationEditDialog(getShell(),
            workingCopy, !mConfigurable,
            Messages.CheckConfigurationConfigureDialog_titleModuleConfigEditor);
    if (Window.OK == dialog.open() && mConfigurable) {
      mModules.set(mModules.indexOf(m), workingCopy);
      mIsDirty = true;
      mTableViewer.refresh(true);
      refreshTableViewerState();
    }
  }
}
 
Example 8
Source File: SourceAttachmentBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IPath chooseExtension() {
	IPath currPath= getFilePath();
	if (currPath.segmentCount() == 0) {
		currPath= fEntry.getPath();
	}

	IPath resolvedPath= getResolvedPath(currPath);
	File initialSelection= resolvedPath != null ? resolvedPath.toFile() : null;

	String currVariable= currPath.segment(0);
	JARFileSelectionDialog dialog= new JARFileSelectionDialog(getShell(), false, true, false);
	dialog.setTitle(NewWizardMessages.SourceAttachmentBlock_extvardialog_title);
	dialog.setMessage(NewWizardMessages.SourceAttachmentBlock_extvardialog_description);
	dialog.setInput(fFileVariablePath.toFile());
	dialog.setInitialSelection(initialSelection);
	if (dialog.open() == Window.OK) {
		File result= (File) dialog.getResult()[0];
		IPath returnPath= Path.fromOSString(result.getPath()).makeAbsolute();
		return modifyPath(returnPath, currVariable);
	}
	return null;
}
 
Example 9
Source File: WebBrowserViewer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void setCustomSize()
{
	CustomSizeDialog dialog = new CustomSizeDialog(getShell());
	if (dialog.open() == Window.OK)
	{
		currentSize = new BrowserSize("custom", dialog.fWidth, dialog.fHeight, null, null); //$NON-NLS-1$
		backgroundArea.setSize(currentSize.getWidth(), currentSize.getHeight());
	}
}
 
Example 10
Source File: TreeWithAddRemove.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void addItemWithDialog(MapOfStringsInputDialog dialog) {
    if (dialog.open() == Window.OK) {
        Tuple<String, String> keyAndValueEntered = dialog.getKeyAndValueEntered();
        if (keyAndValueEntered != null) {
            addTreeItem(keyAndValueEntered.o1, keyAndValueEntered.o2);
        }
    }
}
 
Example 11
Source File: DialogUtils.java    From typescript.java with MIT License 5 votes vote down vote up
public static IResource openResourceDialog(IProject project, Shell shell, int typesMask) {
	OpenResourceDialog dialog = new OpenResourceDialog(shell, false, project, typesMask);
	if (dialog.open() != Window.OK) {
		return null;
	}
	Object[] results = dialog.getResult();
	if (results != null && results.length > 0) {
		return (IResource) results[0];
	}
	return null;
}
 
Example 12
Source File: MarkerEditorComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void switchMarkerTypeImpl( MarkerType newType )
{
	if ( newType == MarkerType.ICON_LITERAL )
	{
		ImageDialog iconDialog = (ImageDialog) context.getUIFactory( )
				.createChartMarkerIconDialog( new Shell( ),
						getMarker( ).getFill( ),
						context );
		if ( iconDialog.open( ) == Window.OK )
		{
			Fill resultFill = iconDialog.getResult( );
			if ( resultFill.eAdapters( ).isEmpty( ) )
			{
				// Add adapters to new EObject
				resultFill.eAdapters( )
						.addAll( getMarker( ).eAdapters( ) );
			}
			getMarker( ).setFill( resultFill );
		}
		else
		{
			// Without saving
			return;
		}
	}

	getMarker( ).setType( newType );
	
	updateMarkerPreview( );
}
 
Example 13
Source File: FormatterPreferencePage.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private void handleNewButton() {
    final CreateProfileDialog p= new CreateProfileDialog(getShell(), fProfileManager, new FormatterProfile());
    if (p.open() == Window.OK) {
        fProfileCombo.add(p.getCreatedProfile().getName());
        fProfileCombo.select(fProfileCombo.getItemCount()-1);
        handleComboSelection();
        if (p.openEditDialog()) {
            handleEditButton(true);
        }
    }
}
 
Example 14
Source File: SWTPromptServices.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Documentation(
    value = "Prompts for a Float value with the given message.",
    params = {
        @Param(name = "message", value = "The message displayed to the user"),
    },
    result = "Prompts the user and return the input of the user as a Float.",
    examples = {
        @Example(expression = "'Enter your weight: '.promptFloat()", result = "prompts the user"),
    }
)
// @formatter:on
public Float promptFloat(final String message) {
    final RunnableWithResult<Float> runnable = new RunnableWithResult<Float>() {

        @Override
        public void run() {
            final AbstractPromptDialog dialog = new AbstractPromptDialog(Display.getDefault().getActiveShell(),
                    message) {

                @Override
                public boolean validate(String input) {
                    return validateFloat(input);
                }
            };
            if (dialog.open() == Window.OK) {
                result = Float.valueOf(dialog.getValue());
            } else {
                result = null;
            }
        }

    };
    Display.getDefault().syncExec(runnable);
    if (runnable.getResult() != null) {
        return runnable.getResult();
    } else {
        throw new IllegalStateException(M2DOC_DIALOG_CANCELLED);
    }
}
 
Example 15
Source File: StandardChartDataSheet.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
int invokeNewDataSet( )
{
	int count = getDataServiceProvider( ).getAllDataSets( ).length;
	DataService.getInstance( ).createDataSet( );

	if ( getDataServiceProvider( ).getAllDataSets( ).length == count )
	{
		// user cancel this operation
		return Window.CANCEL;
	}

	return Window.OK;
}
 
Example 16
Source File: AddSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IFolder chooseFolder(String title, String message, IPath initialPath) {
	Class<?>[] acceptedClasses= new Class[] { IFolder.class };
	ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, null);

	ILabelProvider lp= new WorkbenchLabelProvider();
	ITreeContentProvider cp= new WorkbenchContentProvider();

	IProject currProject= fNewElement.getJavaProject().getProject();

	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), lp, cp) {
		@Override
		protected Control createDialogArea(Composite parent) {
			Control result= super.createDialogArea(parent);
			PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJavaHelpContextIds.BP_CHOOSE_EXISTING_FOLDER_TO_MAKE_SOURCE_FOLDER);
			return result;
		}
	};
	dialog.setValidator(validator);
	dialog.setTitle(title);
	dialog.setMessage(message);
	dialog.addFilter(filter);
	dialog.setInput(currProject);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	IResource res= currProject.findMember(initialPath);
	if (res != null) {
		dialog.setInitialSelection(res);
	}

	if (dialog.open() == Window.OK) {
		return (IFolder) dialog.getFirstResult();
	}
	return null;
}
 
Example 17
Source File: NewSpecHandler.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
public Object execute(ExecutionEvent event) throws ExecutionException
{
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

    // Create the wizard
    NewSpecWizard wizard = new NewSpecWizard(event.getParameter(PARAM_PATH));
    // we pass null for structured selection, cause we just not using it
    wizard.init(window.getWorkbench(), null);
    Shell parentShell = window.getShell();
    // Create the wizard dialog
    WizardDialog dialog = new WizardDialog(parentShell, wizard);
    dialog.setHelpAvailable(true);
    
    // Open the wizard dialog
    if (Window.OK == dialog.open() && wizard.getRootFilename() != null)
    {
    	// read UI values from the wizard page
    	final boolean importExisting = wizard.isImportExisting();
    	final String specName = wizard.getSpecName();
    	final String rootFilename = wizard.getRootFilename();
        
        // the moment the user clicks finish on the wizard page does
        // not correspond with the availability of the spec object
        // it first has to be created/parsed fully before it can be shown in
        // the editor. Thus, delay opening the editor until parsing is done.        	
        createModuleAndSpecInNonUIThread(rootFilename, importExisting, specName);
    }

    return null;
}
 
Example 18
Source File: JavaTemplatePreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Template editTemplate(Template template, boolean edit, boolean isNameModifiable) {
	org.eclipse.jdt.internal.ui.preferences.EditTemplateDialog dialog= new org.eclipse.jdt.internal.ui.preferences.EditTemplateDialog(getShell(), template, edit, isNameModifiable, getContextTypeRegistry());
	if (dialog.open() == Window.OK) {
		return dialog.getTemplate();
	}
	return null;
}
 
Example 19
Source File: MapDescriptorProvider.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public boolean edit( Object input, int handleCount )
{
	boolean result = false;
	CommandStack stack = SessionHandleAdapter.getInstance( )
			.getCommandStack( );

	try
	{
		stack.startTrans( Messages.getString( "MapPage.transName.editMapRule" ) ); //$NON-NLS-1$

		MapRuleBuilder builder = new MapRuleBuilder( UIUtil.getDefaultShell( ),
				MapRuleBuilder.DLG_TITLE_EDIT,
				this );

		MapRuleHandle handle = (MapRuleHandle) input;

		builder.updateHandle( handle, handleCount );

		builder.setDesignHandle( getDesignElementHandle( ) );

		DesignElementHandle reportElement = getDesignElementHandle( );
		while ( reportElement instanceof RowHandle
				|| reportElement instanceof ColumnHandle
				|| reportElement instanceof CellHandle )
		{
			DesignElementHandle designElement = reportElement.getContainer( );
			if ( designElement instanceof ReportItemHandle )
			{
				reportElement = (ReportItemHandle) designElement;
			}
			else if ( designElement instanceof GroupHandle )
			{
				reportElement = (ReportItemHandle) ( (GroupHandle) designElement ).getContainer( );
			}
			else
			{
				reportElement = designElement;
			}
			if ( reportElement == null )
				break;
		}

		if ( reportElement instanceof ReportItemHandle )
		{
			builder.setReportElement( (ReportItemHandle) reportElement );
		}
		else if ( reportElement instanceof GroupHandle )
		{
			builder.setReportElement( (ReportItemHandle) ( (GroupHandle) reportElement ).getContainer( ) );
		}

		if ( builder.open( ) == Window.OK )
		{
			result = true;
		}
		stack.commit( );

	}
	catch ( Exception e )
	{
		stack.rollback( );
		ExceptionUtil.handle( e );
		result = false;
	}
	return result;
}
 
Example 20
Source File: BuildPathDialogAccess.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Shows the UI for selecting new variable classpath entries. See {@link IClasspathEntry#CPE_VARIABLE} for
 * details about variable classpath entries.
 * The dialog returns an array of the selected variable entries or <code>null</code> if the dialog has
 * been canceled. The dialog does not apply any changes.
 *
 * @param shell The parent shell for the dialog.
 * @param existingPaths An array of paths that are already on the classpath and therefore should not be
 * selected again.
 * @return Returns an non empty array of the selected variable entries or <code>null</code> if the dialog has
 * been canceled.
 */
public static IPath[] chooseVariableEntries(Shell shell, IPath[] existingPaths) {
	if (existingPaths == null) {
		throw new IllegalArgumentException();
	}
	NewVariableEntryDialog dialog= new NewVariableEntryDialog(shell);
	if (dialog.open() == Window.OK) {
		return dialog.getResult();
	}
	return null;
}