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

The following examples show how to use org.eclipse.jface.dialogs.MessageDialog#openConfirm() . These examples are extracted from open source projects. 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
@Override
public void run(){
	StructuredSelection selection = (StructuredSelection) viewer.getSelection();
	if (selection != null && !selection.isEmpty()) {
		for (Object obj : selection.toList()) {
			if (obj instanceof MakroDTO) {
				MakroDTO makro = (MakroDTO) obj;
				if (copyExists(makro)) {
					if (MessageDialog.openConfirm(getShell(), "Makro kopieren",
						"Das Makro " + makro.getMakroName() + " existiert bei "
							+ user.getLabel()
							+ " bereits. Wollen Sie das Makro überschreiben?")) {
						copy(makro);
					}
				} else {
					copy(makro);
				}
			}
		}
	}
}
 
Example 2
protected void removeSelectedConnectors() {
    if (tableViewer != null
            && ((IStructuredSelection) tableViewer.getSelection())
                    .size() > 0) {
        final List<?> selection = ((IStructuredSelection) tableViewer
                .getSelection()).toList();
        if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(),
                Messages.deleteDialogTitle, createMessage())) {
            getEditingDomain().getCommandStack().execute(
                    new RemoveCommand(getEditingDomain(),
                            getEObject(), getConnectorFeature(),
                            selection));
            tableViewer.refresh();
        }
    }
}
 
Example 3
/**
 * 删除列表中的非译元素
 */
@SuppressWarnings("unchecked")
public void deleteElement() {
	ISelection selection = tableViewer.getSelection();
	if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
		boolean confirm = MessageDialog.openConfirm(getShell(), Messages.getString("qa.preference.NonTranslationQAPage.enter"),
				Messages.getString("qa.preference.NonTranslationQAPage.enterDelete"));
		if (!confirm) {
			return;
		}
		
		IStructuredSelection structuredSelection = (IStructuredSelection) selection;
		Iterator<NontransElementBean> iter = structuredSelection.iterator();
		while (iter.hasNext()) {
			NontransElementBean selectElement = iter.next();
			dataList.remove(selectElement);
		}
		tableViewer.refresh();
	}
}
 
Example 4
private void removeItems() {
	boolean yes = MessageDialog.openConfirm(getShell(), Messages.RouterDependenciesPanel_deleteTitle, Messages.RouterDependenciesPanel_deleteMsg);
	if(!yes){
		return;
	}
	IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
	Collection<? extends ManifestItem> input = getInput();
	Iterator<?> iterator = selection.iterator();
	while(iterator.hasNext()){
		input.remove(iterator.next());
	}
	tableViewer.refresh();
	fireDependenciesChangedListener();
}
 
Example 5
protected void erase(final Expression selectedExpression) {
    final String type = selectedExpression.getType();
    if (ExpressionConstants.SCRIPT_TYPE.equals(type)) {
        if (!MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.cleanExpressionTitle,
                Messages.cleanExpressionMsg)) {
            return;
        }
    }
    clearExpression(selectedExpression);
    validate();
    refresh();
}
 
Example 6
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
	boolean res = MessageDialog.openConfirm(window.getShell(), "删除确认", "确定要删除所有文本段的全部批注吗?");
	if (res) {
		XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
		XLFHandler handler = xliffEditor.getXLFHandler();
		handler.deleteAllSegmentNote();
	}
	return null;
}
 
Example 7
protected void verifyCurrentSelected(int operateType) {
	ISelection selection = fFilteredTree.getViewer().getSelection();
	if (selection.isEmpty()) {
		String messagePattern = Messages.getString("languagecode.LanguageCodesPreferencePage.msg1");
		Object[] values = new String[0];
		if (operateType == EDIT) {
			values = new String[] { Messages.getString("languagecode.LanguageCodesPreferencePage.msg2") };
		} else if (operateType == REMOVE) {
			values = new String[] { Messages.getString("languagecode.LanguageCodesPreferencePage.msg3") };
		}
		String message = MessageFormat.format(messagePattern, values);
		MessageDialog.openInformation(fFilteredTree.getShell(),
				Messages.getString("languagecode.LanguageCodesPreferencePage.msgTitle"), message);
		return;
	} else if (operateType == EDIT && fFilteredTree.getViewer().getTree().getSelectionCount() > 1) {
		MessageDialog.openInformation(fFilteredTree.getShell(),
				Messages.getString("languagecode.LanguageCodesPreferencePage.msgTitle"),
				Messages.getString("languagecode.LanguageCodesPreferencePage.msg4"));
		return;
	}
	if (selection instanceof IStructuredSelection) {
		IStructuredSelection iStructuredSelection = (IStructuredSelection) selection;
		Object object = iStructuredSelection.getFirstElement();
		if (object instanceof Language) {
			if (operateType == EDIT) {
				Language language = (Language) object;
				editLanguage(language);
			} else if (operateType == REMOVE) {
				// 删除所选择的语言
				if(MessageDialog.openConfirm(fFilteredTree.getShell(), Messages.getString("languagecode.LanguageCodesPreferencePage.msgTitle"), 
						Messages.getString("languagecode.LanguageCodesPreferencePage.msg5"))){
					removeLanguage(iStructuredSelection.toList());
				}
			}
		}
	}
}
 
Example 8
@Override
protected void okPressed() {
	String isBreak = isBreakBtn.getSelection() ? "yes" : "no";
	String preBreak = preBreakTxt.getText();
	String afterBreak = afterBreakTxt.getText();

	LanguageRuleBean bean = new LanguageRuleBean(isBreak, preBreak, afterBreak);

	if (isAdd) {
		// 添加之前验证是否重复
		if (langRulesList.indexOf(bean) == -1) {
			langRulesList.add(bean);
			this.curLangRuleBean = bean;
		} else {
			MessageDialog.openInformation(getShell(), Messages.getString("srx.AddOrEditLangRuleOfSrxDialog.msgTitle1"),
					Messages.getString("srx.AddOrEditLangRuleOfSrxDialog.msg1"));
			return;
		}
	} else {
		// 先验证是否该条数据是否已经被修改,如果已经被修改,但是修改后的数据已经存在,那么直接覆盖
		if (!curLangRuleBean.equals(bean)) {
			if (langRulesList.indexOf(bean) != -1) {
				boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("srx.AddOrEditLangRuleOfSrxDialog.msgTitle2"),
						Messages.getString("srx.AddOrEditLangRuleOfSrxDialog.msg2"));
				if (response) {
					langRulesList.remove(curLangRuleBean);
					curLangRuleBean = bean;
				} else {
					return;
				}
			} else {
				// 如果修改后的数据没有重复,那么删除修改之前的数据,并且添加到修改前数据的位置
				langRulesList.add(langRulesList.indexOf(curLangRuleBean), bean);
				langRulesList.remove(curLangRuleBean);
				curLangRuleBean = bean;
			}
		}
	}
	super.okPressed();
}
 
Example 9
/**
 * 编辑
 */
private void edit() {
	String[] filters = customFilterList.getSelection();
	if (filters.length > 0) {
		if (isChange()) {
			if (!MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg1"))) {
				return;
			}
		}
		String key = filters[0];
		filterNameTxt.setText(key);
		String link = XLFHandler.getCustomFilterAdditionMap().get(key);
		if (link.indexOf("and") != -1) {
			andBtn.setSelection(true);
			orBtn.setSelection(false);
		} else {
			andBtn.setSelection(false);
			orBtn.setSelection(true);
		}

		for (Control ctl : conditionList) {
			if (!ctl.isDisposed()) {
				ctl.dispose();
			}
		}
		conditionList.clear();
		ArrayList<String[]> tmpList = XLFHandler.getCustomFilterIndexMap().get(key);
		for (String[] tempIndex : tmpList) {
			String filterIndex = tempIndex[0];
			DynaComposite dyna = new DynaComposite(dynaComp, SWT.NONE);
			dyna.getFilterName().select(Integer.parseInt(filterIndex));
			dyna.getFilterName().notifyListeners(SWT.Selection, null);
			if ("0".equals(filterIndex) || "1".equals(filterIndex)) { // 关键字、批注
				dyna.getConditions().select(Integer.parseInt(tempIndex[1]));
				dyna.getValue().setText(tempIndex[2].replace("0x0020", " "));
				dyna.getValue().setForeground(black);
			} else if ("2".equals(filterIndex)) { // 属性
				dyna.getPropName().setText(tempIndex[1]);
				dyna.getPropValue().setText(tempIndex[2]);
				dyna.getPropName().setForeground(black);
				dyna.getPropValue().setForeground(black);
			}
		}
		scroll.setMinSize(dynaComp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		dynaComp.layout();
	} else {
		MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg4"));
	}
}
 
Example 10
Source Project: nebula   File: QuitHandler.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Execute
public void execute(final IWorkbench workbench, final Shell shell) {
	if (MessageDialog.openConfirm(shell, "Confirmation", "Do you want to exit?")) {
		workbench.close();
	}
}
 
Example 11
@Override
public boolean performOk() {
	if (!isInit) {
		return true;
	}

	if (btnCheckUpdateWithStartup.getSelection()) {
		preferenceStore.setValue(IPreferenceConstants.SYSTEM_AUTO_UPDATE,
				IPreferenceConstants.SYSTEM_CHECK_UPDATE_WITH_STARTUP);
	} else if (btnCheckUpdateWithMonthly.getSelection()) {
		preferenceStore.setValue(IPreferenceConstants.SYSTEM_AUTO_UPDATE,
				IPreferenceConstants.SYSTEM_CHECK_UPDATE_WITH_MONTHLY);
		preferenceStore.setValue(IPreferenceConstants.SYSTEM_CHECK_UPDATE_WITH_MONTHLY_DATE,
				selectDateSpi.getSelection());
	} else if (btnCheckUpdateWithWeekly.getSelection()) {
		preferenceStore.setValue(IPreferenceConstants.SYSTEM_AUTO_UPDATE,
				IPreferenceConstants.SYSTEM_CHECK_UPDATE_WITH_WEEKLY);
		preferenceStore.setValue(IPreferenceConstants.SYSTEM_CHECK_UPDATE_WITH_WEEKLY_DATE,
				cmbSelectWeek.getSelectionIndex() + 1);
	} else if (btnCheckUpdateWithNever.getSelection()) {
		preferenceStore.setValue(IPreferenceConstants.SYSTEM_AUTO_UPDATE,
				IPreferenceConstants.SYSTEM_CHECK_UPDATE_WITH_NEVER);
	}

	preferenceStore.setValue(IPreferenceConstants.SYSTEM_USER,
			txtSystemUser.getText() == null ? "" : txtSystemUser.getText());

	if (btnLanguageWithEN.getSelection()) {
		preferenceStore
				.setValue(IPreferenceConstants.SYSTEM_LANGUAGE, IPreferenceConstants.SYSTEM_LANGUAGE_WITH_EN);
		CommonFunction.setSystemLanguage("en");
		if (initLang != IPreferenceConstants.SYSTEM_LANGUAGE_WITH_EN) {
			changeLocale("en");
			if (MessageDialog.openConfirm(getShell(),
					Messages.getString("preferencepage.SystemPreferencePage.msgTitle"),
					Messages.getString("preferencepage.SystemPreferencePage.msgInfo"))) {
				PlatformUI.getWorkbench().restart();
			}
		}
	} else if (btnLanguageWithZHCN.getSelection()) {
		preferenceStore.setValue(IPreferenceConstants.SYSTEM_LANGUAGE,
				IPreferenceConstants.SYSTEM_LANGUAGE_WITH_ZH_CN);
		CommonFunction.setSystemLanguage("zh");
		if (initLang != IPreferenceConstants.SYSTEM_LANGUAGE_WITH_ZH_CN) {
			changeLocale("zh");
			if (MessageDialog.openConfirm(getShell(),
					Messages.getString("preferencepage.SystemPreferencePage.msgTitle"),
					Messages.getString("preferencepage.SystemPreferencePage.msgInfo"))) {
				PlatformUI.getWorkbench().restart();
			}
		}
	}

	FontData[] fontData = editorFontSetting.getFontSetingFont();
	JFaceResources.getFontRegistry().put(Constants.XLIFF_EDITOR_TEXT_FONT, fontData);
	preferenceStore.setValue(IPreferenceConstants.XLIFF_EDITOR_FONT_NAME, fontData[0].getName());
	preferenceStore.setValue(IPreferenceConstants.XLIFF_EDITOR_FONT_SIZE, fontData[0].getHeight());

	fontData = matchViewFontSetting.getFontSetingFont();
	JFaceResources.getFontRegistry().put(Constants.MATCH_VIEWER_TEXT_FONT, fontData);
	preferenceStore.setValue(IPreferenceConstants.MATCH_VIEW_FONT_NAME, fontData[0].getName());
	preferenceStore.setValue(IPreferenceConstants.MATCH_VIEW_FONT_SIZE, fontData[0].getHeight());
	
	return true;
}
 
Example 12
Source Project: nebula   File: QuitHandler.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Execute
public void execute(final IWorkbench workbench, final Shell shell) {
	if (MessageDialog.openConfirm(shell, "Confirmation", "Do you want to exit?")) {
		workbench.close();
	}
}
 
Example 13
@Override
protected void okPressed() {
	String langModel = langModelTxt.getText().trim();
	String langRuleName = langRuleNameCmb.getText().trim();
	MapRuleBean bean = new MapRuleBean(langModel, langRuleName);

	if ("".equals(langModel) || "".equals(langRuleName)) {
		MessageDialog.openInformation(getShell(), Messages.getString("srx.AddOrEditMapRuleOfSrxDialog.msgTitle1"),
				Messages.getString("srx.AddOrEditMapRuleOfSrxDialog.msg1"));
		return;
	}

	if (isAdd) {
		// 添加之前验证是否重复
		if (mapRulesList.indexOf(bean) == -1) {
			mapRulesList.add(bean);
			this.curMapRuleBean = bean;
		} else {
			MessageDialog.openInformation(getShell(),
					Messages.getString("srx.AddOrEditMapRuleOfSrxDialog.msgTitle1"),
					Messages.getString("srx.AddOrEditMapRuleOfSrxDialog.msg2"));
			return;
		}
	} else {
		// 先验证是否该条数据是否已经被修改,如果已经被修改,但是修改后的数据已经存在,那么直接覆盖
		if (!curMapRuleBean.equals(bean)) {
			if (mapRulesList.indexOf(bean) != -1) {
				boolean response = MessageDialog.openConfirm(getShell(),
						Messages.getString("srx.AddOrEditMapRuleOfSrxDialog.msgTitle2"),
						Messages.getString("srx.AddOrEditMapRuleOfSrxDialog.msg3"));
				if (response) {
					mapRulesList.remove(curMapRuleBean);
					curMapRuleBean = bean;
				} else {
					return;
				}
			} else {
				// 如果修改后的数据没有重复,那么删除修改之前的数据,并且添加到修改前数据的位置
				mapRulesList.add(mapRulesList.indexOf(curMapRuleBean), bean);
				mapRulesList.remove(curMapRuleBean);
				curMapRuleBean = bean;
			}
		}
	}
	super.okPressed();
}
 
Example 14
private void makeActions(){
	markAllAction =
		new RestrictedAction(AccessControlDefaults.LAB_SEEN, Messages.LabNotSeenView_markAll) { //$NON-NLS-1$
			{
				setToolTipText(Messages.LabNotSeenView_markAllToolTip); //$NON-NLS-1$
				setImageDescriptor(Images.IMG_TICK.getImageDescriptor());
			}
			
			@Override
			public void doRun(){
				boolean openConfirm =
					MessageDialog.openConfirm(getViewSite().getShell(),
						Messages.LabNotSeenView_reallyMarkCaption, //$NON-NLS-1$
						Messages.LabNotSeenView_markAllToolTip);
				if (openConfirm) //$NON-NLS-1$
				{
					tv.setAllChecked(true);
					for (LabResult lr : LabResult.getUnseen()) {
						lr.removeFromUnseen();
					}
				}
			}
			
		};
	markPersonAction =
		new RestrictedAction(AccessControlDefaults.LAB_SEEN,
			Messages.LabNotSeenView_markAllofPatient) { //$NON-NLS-1$
			{
				setToolTipText(Messages.LabNotSeenView_markAllOfPatientToolTip); //$NON-NLS-1$
				setImageDescriptor(Images.IMG_PERSON_OK.getImageDescriptor());
			}
			
			@Override
			public void doRun(){
				Patient act = ElexisEventDispatcher.getSelectedPatient();
				for (LabResult lr : unseen) {
					if (lr.getPatient().equals(act)) {
						lr.removeFromUnseen();
						tv.setChecked(lr, true);
					}
				}
			}
		};
}
 
Example 15
public void doSave( IProgressMonitor monitor )
{
	boolean isReselect = false;
	if ( getModel( ) != null
			&& ModuleUtil.compareReportVersion( ModuleUtil.getReportVersion( ),
					getModel( ).getVersion( ) ) > 0 )
	{
		if ( !MessageDialog.openConfirm( UIUtil.getDefaultShell( ),
				Messages.getString( "MultiPageReportEditor.ConfirmVersion.Dialog.Title" ), Messages.getString( "MultiPageReportEditor.ConfirmVersion.Dialog.Message" ) ) ) //$NON-NLS-1$ //$NON-NLS-2$
		{
			return;
		}
		else
		{
			isReselect = true;
		}
	}
	getCurrentPageInstance( ).doSave( monitor );
	fireDesignFileChangeEvent( );
	if ( isReselect )
	{
		Display.getCurrent( ).asyncExec( new Runnable( ) {

			public void run( )
			{
				if ( getActivePageInstance( ) instanceof GraphicalEditorWithFlyoutPalette )
				{
					if ( ( (GraphicalEditorWithFlyoutPalette) getActivePageInstance( ) ).getGraphicalViewer( ) != null )
					{
						GraphicalEditorWithFlyoutPalette editor = (GraphicalEditorWithFlyoutPalette) getActivePageInstance( );
						GraphicalViewer view = editor.getGraphicalViewer( );

						UIUtil.resetViewSelection( view, true );
					}

				}

			}
		} );
	}
}
 
Example 16
private void deletePluginData() {
	ISelection selection = tableViewer.getSelection();
	if (selection != null && !selection.isEmpty() && selection instanceof StructuredSelection) {
		boolean response = MessageDialog.openConfirm(getShell(),
				Messages.getString("dialog.PluginConfigurationDialog.msgTitle2"),
				Messages.getString("dialog.PluginConfigurationDialog.msg2"));
		if (!response) {
			return;
		}

		StructuredSelection structuredSelection = (StructuredSelection) selection;
		@SuppressWarnings("unchecked")
		Iterator<PluginConfigBean> it = structuredSelection.iterator();

		VTDGen vg = new VTDGen();
		vg.parseFile(pluginXmlLocation, true);
		VTDNav vn = vg.getNav();
		AutoPilot ap = new AutoPilot(vn);

		try {
			XMLModifier xm = new XMLModifier(vn);

			while (it.hasNext()) {
				PluginConfigBean configBean = it.next();
				String xpath = manage.buildXpath(configBean);
				ap.selectXPath(xpath);
				while (ap.evalXPath() != -1) {
					xm.remove();
					manage.deletePluginMenu(configBean.getId());
				}
				ap.resetXPath();
			}
			FileOutputStream fos = new FileOutputStream(pluginXmlLocation);
			BufferedOutputStream bos = new BufferedOutputStream(fos);
			xm.output(bos); // 写入文件
			bos.close();
			fos.close();

			refreshTable(null);
		} catch (Exception e) {
			LOGGER.error("", e);
		}
	} else {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.PluginConfigurationDialog.msgTitle"),
				Messages.getString("dialog.PluginConfigurationDialog.msg3"));
	}
}
 
Example 17
protected Optional<Stream<IRepositoryFileStore>> deleteFinish(
        SelectionPage<? extends IRepositoryStore<? extends IRepositoryFileStore>> selectPage, Shell activeShell) {
    return MessageDialog.openConfirm(activeShell, Messages.deleteConfirmation,
            String.format(Messages.deleteConfirmationMessage, getListToDelete(selectPage)))
                    ? Optional.ofNullable(selectPage.getSelection()) : Optional.empty();
}
 
Example 18
@Override
protected void okPressed(){
	final String[] ret = new String[8];
	ret[0] = tName.getText();
	ret[1] = tVorname.getText();
	int idx = cbSex.getSelectionIndex();
	if (idx == 1 || cbSex.getText().contentEquals(Messages.Patient_female_short)) {
		ret[2] = Patient.FEMALE; // German w for weiblich = female
	} else if (idx == 0 || cbSex.getText().contentEquals(Messages.Patient_male_short)) {
		ret[2] = Patient.MALE;
	} else if (idx == -1) {
		SWTHelper.showError(Messages.PatientErfassenDialog_Error_Sex,
				Messages.PatientErfassenDialog_Sex_must_be_specified);
		return;
	}
	ret[3] = tGebDat.getText();
	try {
		TimeTool check = null;
		if (!StringTool.isNothing(ret[3])) {
			check = new TimeTool(ret[3], true);
		}
		ret[4] = tStrasse.getText();
		ret[5] = tPlz.getText();
		ret[6] = tOrt.getText();
		ret[7] = tTel.getText();
		Query<Kontakt> qbe = new Query<Kontakt>(Kontakt.class);
		qbe.add("Bezeichnung1", Query.EQUALS, ret[0], true);
		qbe.add("Bezeichnung2", Query.EQUALS, ret[1], true);
		if (check != null)
			qbe.add(Person.BIRTHDATE, Query.EQUALS, check.toDBString(false), true);
		List<Kontakt> list = qbe.execute();
		if ((list != null) && (!list.isEmpty())) {
			Kontakt k = list.get(0);
			if (k.istPerson()) {
				k.set(Kontakt.FLD_IS_PATIENT, StringConstants.ONE);
				if (MessageDialog.openConfirm(getShell(),
					Messages.PatientErfassenDialog_personExists,
					Messages.PatientErfassenDialog_personWithThisNameExists) == false) { //$NON-NLS-1$ //$NON-NLS-2$
					// abort dialog
					super.cancelPressed();
					return;
				}
			}
		}
		result = new Patient(ret[0], ret[1], check, ret[2]);
		AcquireLockUi.aquireAndRun(result, new ILockHandler() {
			
			@Override
			public void lockFailed(){
				result.delete();
			}
			
			@Override
			public void lockAcquired(){
				result.set(new String[] {
					Kontakt.FLD_STREET, Kontakt.FLD_ZIP, Kontakt.FLD_PLACE, Kontakt.FLD_PHONE1
				}, new String[] {
					ret[4], ret[5], ret[6], ret[7]
				});
				
				ElexisEventDispatcher.fireSelectionEvent(result);
			}
		});
		super.okPressed();
	} catch (TimeFormatException e) {
		ExHandler.handle(e);
		SWTHelper.showError("Falsches Datumsformat",
			"Das Geburtsdatum kann nicht interpretiert werden");
		return;
	} catch (PersonDataException pe) {
		ExHandler.handle(pe);
		SWTHelper.showError("Unplausible Angaben",
			"Bitte überprüfen Sie die Eingabe nochmals: " + pe.getMessage());
	}
}
 
Example 19
Source Project: tlaplus   File: UIHelper.java    License: MIT License 4 votes vote down vote up
/**
 * If there are unsaved modules open, this prompts the user to save the
 * modules with an OK/Cancel dialog. If the user selects OK, this saves the
 * modules before returning, other wise it does not.
 * 
 * @return false if a dialog is opened and the user selects cancel or the
 *         user closes the dialog without pressing OK or cancel, true
 *         otherwise
 */
public static boolean promptUserForDirtyModules() {
	final List<IEditorReference> dirtyEditors = new LinkedList<IEditorReference>();
	IEditorReference[] references = UIHelper.getActivePage().getEditorReferences();
	if (references != null) {
		for (int i = 0; i < references.length; i++) {
			try {
				if (references[i].isDirty()
						&& references[i].getEditorInput().getName().endsWith(TLAConstants.Files.TLA_EXTENSION)) {
					dirtyEditors.add(references[i]);
				}
			} catch (PartInitException e) {
				Activator.getDefault().logError("Error getting unsaved resources.", e);
			}
		}
	}

	if (dirtyEditors.size() > 0) {

		// opens a OK/cancel dialog
		boolean saveFiles = MessageDialog.openConfirm(getShell(), "Modified resources",
				"Some resources are modified.\nDo you want to save the modified resources?");

		if (saveFiles) {
			// User selected OK
			runUISync(new Runnable() {

				public void run() {
					// save modified resources
					Iterator<IEditorReference> it = dirtyEditors.iterator();
					while (it.hasNext()) {
						IEditorReference reference = it.next();
						IEditorPart editor = reference.getEditor(false);
						if (editor != null) {
							editor.doSave(new NullProgressMonitor());
						}
					}
				}
			});
		}

		return saveFiles;
	}

	// no dirty modules
	// no dialog opened
	return true;
}
 
Example 20
Source Project: uima-uimaj   File: TypeSection.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Handle remove type.
 *
 * @param item the item
 */
private void handleRemoveType(final TreeItem item) {

  TypeDescription td = getTypeDescriptionFromTableTreeItem(item);

  String sTypeNameToRemove = td.getName();

  // pop a dialog mentioning typesRequiringThisOne, saying that others must be
  // deleted first....
  if (null == showTypesRequiringThisOneMessage(sTypeNameToRemove, !ALLOWED))
    return;

  boolean bTypeInUseElsewhere = isTypeInUseElsewhere(sTypeNameToRemove);
  if (bTypeInUseElsewhere) {
    String sCascadeDeleteTitle = CASCADE_DELETE_WARNING;
    String sCascadeDeleteMessage = CASCADE_MESSAGE;
    boolean bContinue = MessageDialog.openConfirm(getSection().getShell(), sCascadeDeleteTitle,
            sCascadeDeleteMessage);
    if (!bContinue) {
      return;
    }
  }

  TypeDescription localTd = getLocalTypeDefinition(td);
  removeType(localTd, getTypeSystemDescription());

  if (isImportedType(td)) {
    // although the type itself still remains in the merged type system,
    // features may be removed by this action, so
    // a remerge is needed
    rebuildMergedTypeSystem();
    refresh();
  } else {
    removeType(td, getMergedTypeSystemDescription());
    // update GUI
    setSelectionOneUp(tt, item);
    item.dispose();
  }

  TypeFeature[] featuresToRemove = computeFeaturesToRemove(localTd,
          getMergedTypeSystemDescription().getType(td.getName()));

  if (bTypeInUseElsewhere && !isImportedType(td) && !isBuiltInType(td)) {
    deleteTypeOrFeatureMentions(sTypeNameToRemove, TYPES, null);
  }

  // if removing a type which is also imported or built-in, which is a supertype of something
  // this action can change the feature set.

  if (null != featuresToRemove)
    for (int i = 0; i < featuresToRemove.length; i++) {
      deleteTypeOrFeatureMentions(featuresToRemove[i].featureName, FEATURES,
              featuresToRemove[i].typeName);
    }

  editor.removeDirtyTypeName(sTypeNameToRemove);
  finishAction();
}