Java Code Examples for org.eclipse.jface.window.Window#CANCEL
The following examples show how to use
org.eclipse.jface.window.Window#CANCEL .
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: PullUpMemberPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void editSelectedMembers() { if (!fEditButton.isEnabled()) return; final ISelection preserved= fTableViewer.getSelection(); try { MemberActionInfo[] selectedMembers= getSelectedMembers(); final String shellTitle= RefactoringMessages.PullUpInputPage1_Edit_members; final String labelText= selectedMembers.length == 1 ? Messages.format(RefactoringMessages.PullUpInputPage1_Mark_selected_members_singular, JavaElementLabels.getElementLabel(selectedMembers[0].getMember(), JavaElementLabels.M_PARAMETER_TYPES)) : Messages.format(RefactoringMessages.PullUpInputPage1_Mark_selected_members_plural, String.valueOf(selectedMembers.length)); final Map<String, Integer> stringMapping= createStringMappingForSelectedMembers(); final String[] keys= stringMapping.keySet().toArray(new String[stringMapping.keySet().size()]); Arrays.sort(keys); final int initialSelectionIndex= getInitialSelectionIndexForEditDialog(stringMapping, keys); final ComboSelectionDialog dialog= new ComboSelectionDialog(getShell(), shellTitle, labelText, keys, initialSelectionIndex); dialog.setBlockOnOpen(true); if (dialog.open() == Window.CANCEL) return; final int action= stringMapping.get(dialog.getSelectedString()).intValue(); setActionForInfos(selectedMembers, action); } finally { updateWizardPage(preserved, true); } }
Example 2
Source File: RotatedTextBuilder.java From birt with Eclipse Public License 1.0 | 6 votes |
public int open( ExtendedItemHandle handle ) { try { IReportItem item = handle.getReportItem( ); if ( item instanceof RotatedTextItem ) { // XXX change to RotatedTextEditor2 for expression support RotatedTextEditor editor = new RotatedTextEditor2( Display.getCurrent( ) .getActiveShell( ), (RotatedTextItem) item ); return editor.open( ); } } catch ( Exception e ) { e.printStackTrace( ); } return Window.CANCEL; }
Example 3
Source File: ExtnlResBindSection.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Bindings can't be edited. They can be removed or new ones bound. External resources can be * edited. Edit button is disabled unles an editable thing is selected. But user could double * click an illegal entry * */ private void handleEdit() { TreeItem item = tree.getSelection()[0]; if (isBoundSpec(item)) return; ExternalResourceDescription xrd = getXRDescriptionFromTreeItem(item); ResourceSpecifier rs = xrd.getResourceSpecifier(); if (!((rs instanceof FileResourceSpecifier) || (rs instanceof FileLanguageResourceSpecifier))) { Utility.popMessage("Can''t edit custom resource", "This resource is a '" + rs.getClass().getName() + "', and any edits have to be done directly in the XML in the Source view.", MessageDialog.INFORMATION); return; } AddExternalResourceDialog dialog = new AddExternalResourceDialog(this, xrd); if (dialog.open() == Window.CANCEL) return; alterExistingXRD(dialog, xrd, item); }
Example 4
Source File: ExternalizeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void openEditButton(ISelection selection) { try { IStructuredSelection sel= (IStructuredSelection) fTableViewer.getSelection(); NLSSubstitution substitution= (NLSSubstitution) sel.getFirstElement(); if (substitution == null) { return; } NLSInputDialog dialog= new NLSInputDialog(getShell(), substitution); if (dialog.open() == Window.CANCEL) return; KeyValuePair kvPair= dialog.getResult(); if (substitution.getState() == NLSSubstitution.EXTERNALIZED) { substitution.setKey(kvPair.getKey()); } substitution.setValue(kvPair.getValue()); validateKeys(false); } finally { fTableViewer.refresh(); fTableViewer.getControl().setFocus(); fTableViewer.setSelection(selection); } }
Example 5
Source File: AddGetterSetterAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private int showQueryDialog(final String message, final String[] buttonLabels, int[] returnCodes) { final Shell shell= getShell(); if (shell == null) { JavaPlugin.logErrorMessage("AddGetterSetterAction.showQueryDialog: No active shell found"); //$NON-NLS-1$ return IRequestQuery.CANCEL; } final int[] result= { Window.CANCEL}; shell.getDisplay().syncExec(new Runnable() { public void run() { String title= ActionMessages.AddGetterSetterAction_QueryDialog_title; MessageDialog dialog= new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, buttonLabels, 0); result[0]= dialog.open(); } }); int returnVal= result[0]; return returnVal < 0 ? IRequestQuery.CANCEL : returnCodes[returnVal]; }
Example 6
Source File: AggregateSection.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Handle add. */ private void handleAdd() { MultiResourceSelectionDialogWithFlowOption dialog = new MultiResourceSelectionDialogWithFlowOption( getSection().getShell(), editor.getFile().getProject().getParent(), "Component Engine Selection", editor.getFile().getLocation(), editor); dialog.setTitle("Component Engine Selection"); dialog.setMessage("Select one or more component engines from the workspace:"); if (Window.CANCEL == dialog.open()) { return; } Object[] files = dialog.getResult(); if (files != null && files.length > 0) { for (int i = 0; i < files.length; i++) { FileAndShortName fsn = new FileAndShortName(files[i]); produceKeyAddDelegate(fsn.shortName, fsn.fileName, dialog.getAutoAddToFlow(), dialog.isImportByName); } } }
Example 7
Source File: ExtendedElementToolExtends.java From birt with Eclipse Public License 1.0 | 5 votes |
public boolean postHandleCreation( ) { // TODO check extension setting here to decide if popup the builder IReportItemBuilderUI builder = getbuilder( ); if ( builder != null ) { // Open the builder for new element if ( builder.open( (ExtendedItemHandle) getModel( ) ) == Window.CANCEL ) { return false; } } else { PaletteEntryExtension[] extensions = EditpartExtensionManager.getPaletteEntries( ); for ( int i = 0; i < extensions.length; i++ ) { if ( extensions[i].getLabel( ).equals( this.extensionName ) ) { try { CommandUtils.setVariable( "targetEditPart", //$NON-NLS-1$ getTargetEditPart( ) ); setModel( extensions[i].executeCreate( ) ); return super.preHandleMouseUp( ); } catch ( Exception e ) { ExceptionHandler.handle( e ); } return false; } } } return super.postHandleCreation( ); }
Example 8
Source File: SofaMapSection.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Removes the aggr. * * @param selected the selected */ private void removeAggr(TreeItem selected) { if (Window.CANCEL == Utility .popOkCancel( "Confirm delete of sofa mappings", "Please confirm deletion of all sofa mappings for this Aggregate Sofa name. Note this will not delete the Sofa name. To do that, remove the name from the Component Capabilities panel (the other panel on this page).", MessageDialog.WARNING)) return; removeAggr(selected.getText()); removeChildren(selected); setFileDirty(); }
Example 9
Source File: AbstractSection.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Revert or continue. * * @param msg the msg * @param msgDetails the msg details * @return true to revert, false to continue */ public static boolean revertOrContinue(String msg, String msgDetails) { if (Window.CANCEL == Utility.popMessage(msg, msgDetails + "\nDo you want to continue, or Abort the last action?", MessageDialog.QUESTION, new String[] { "Continue", "Abort" })) return true; // for closing the window or hitting Undo return false; }
Example 10
Source File: CapabilitySection.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Handle add type. * * @param selItem the sel item * @param itemKind the item kind */ private void handleAddType(TreeItem selItem, int itemKind) { if (itemKind == LANG || itemKind == TYPE || itemKind == SOFA) selItem = selItem.getParentItem(); else if (itemKind == LANG_ITEM || itemKind == FEAT || itemKind == SOFA_ITEM) selItem = selItem.getParentItem().getParentItem(); Capability c = getCapabilityFromTreeItem(selItem); AddCapabilityTypeDialog dialog = new AddCapabilityTypeDialog(this, c); if (dialog.open() == Window.CANCEL) return; for (int i = 0; i < dialog.types.length; i++) { if (dialog.inputs[i]) c.addInputType(dialog.types[i], dialog.inputs[i]); if (dialog.outputs[i]) c.addOutputType(dialog.types[i], dialog.outputs[i]); TreeItem item = new TreeItem(selItem, SWT.NONE); setGuiTypeName(item, dialog.types[i]); item.setText(INPUT_COL, dialog.inputs[i] ? INPUT : ""); item.setText(OUTPUT_COL, dialog.outputs[i] ? OUTPUT : ""); TreeItem fItem = new TreeItem(item, SWT.NONE); fItem.setData(FEAT_TITLE); fItem.setText(NAME_COL, ALL_FEATURES); fItem.setText(INPUT_COL, dialog.inputs[i] ? INPUT : ""); fItem.setText(OUTPUT_COL, dialog.outputs[i] ? OUTPUT : ""); item.setExpanded(true); } pack04(); selItem.setExpanded(true); finishAction(); }
Example 11
Source File: IpcDialog.java From olca-app with Mozilla Public License 2.0 | 5 votes |
public static int show() { if (Database.get() == null) { MsgBox.error(M.NoDatabaseOpened, M.NeedOpenDatabase); return Window.CANCEL; } return new IpcDialog().open(); }
Example 12
Source File: ExtnlResBindSection.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Add new external resource, with no bindings. */ private void handleAdd() { AddExternalResourceDialog dialog = new AddExternalResourceDialog(this); if (dialog.open() == Window.CANCEL) return; ExternalResourceDescription xrd = new ExternalResourceDescription_impl(); TreeItem item = new TreeItem(tree, SWT.NONE); alterExistingXRD(dialog, xrd, item); getResourceManagerConfiguration().addExternalResource(xrd); }
Example 13
Source File: UIUtil.java From birt with Eclipse Public License 1.0 | 4 votes |
private static boolean addGroup( DesignElementHandle parent, int position ) throws SemanticException { GroupHandle groupHandle = null; SlotHandle slotHandle = null; // ElementFactory factory = parent.getElementFactory( ); DesignElementFactory factory = DesignElementFactory.getInstance( parent.getModuleHandle( ) ); if ( parent instanceof TableHandle ) { groupHandle = factory.newTableGroup( ); slotHandle = ( (TableHandle) parent ).getGroups( ); int columnCount = ( (TableHandle) parent ).getColumnCount( ); groupHandle.getHeader( ).add( factory.newTableRow( columnCount ) ); groupHandle.getFooter( ).add( factory.newTableRow( columnCount ) ); } else if ( parent instanceof ListHandle ) { groupHandle = factory.newListGroup( ); slotHandle = ( (ListHandle) parent ).getGroups( ); } if ( groupHandle != null && slotHandle != null ) { String collapseLevel = parent.getStringProperty( AC_GROUP_COLLAPSE_LEVEL_PROPERTY ); if ( collapseLevel != null && collapseLevel.trim( ).length( ) > 0 && position >= 0 ) { String[] levels = collapseLevel.split( "," ); //$NON-NLS-1$ List<Integer> levelList = new ArrayList<Integer>( ); for ( int i = 0; i < levels.length; i++ ) { try { int level = Integer.parseInt( levels[i] ); if ( level >= position ) { level++; } levelList.add( level ); } catch ( NumberFormatException e ) { } } StringBuffer buffer = new StringBuffer( ); for ( int i = 0; i < levelList.size( ); i++ ) { buffer.append( levelList.get( i ) ); if ( i < levelList.size( ) - 1 ) buffer.append( "," ); //$NON-NLS-1$ } String value = buffer.toString( ).trim( ).length( ) > 0 ? buffer.toString( ) .trim( ) : null; parent.setStringProperty( AC_GROUP_COLLAPSE_LEVEL_PROPERTY, value ); } slotHandle.add( groupHandle, position ); // if ( !DEUtil.getDataSetList( parent ).isEmpty( ) ) {// If data set can be found or a blank group will be inserted. GroupDialog dialog = new GroupDialog( getDefaultShell( ), GroupDialog.GROUP_DLG_TITLE_NEW ); // dialog.setDataSetList( DEUtil.getDataSetList( parent ) ); dialog.setInput( groupHandle ); if ( dialog.open( ) == Window.CANCEL ) {// Cancel the action return false; } } return true; } return false; }
Example 14
Source File: CrossflowDiagramEditor.java From scava with Eclipse Public License 2.0 | 4 votes |
/** * @generated */ protected void performSaveAs(IProgressMonitor progressMonitor) { Shell shell = getSite().getShell(); IEditorInput input = getEditorInput(); SaveAsDialog dialog = new SaveAsDialog(shell); IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null; if (original != null) { dialog.setOriginalFile(original); } dialog.create(); IDocumentProvider provider = getDocumentProvider(); if (provider == null) { // editor has been programmatically closed while the dialog was open return; } if (provider.isDeleted(input) && original != null) { String message = NLS.bind(Messages.CrossflowDiagramEditor_SavingDeletedFile, original.getName()); dialog.setErrorMessage(null); dialog.setMessage(message, IMessageProvider.WARNING); } if (dialog.open() == Window.CANCEL) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IPath filePath = dialog.getResult(); if (filePath == null) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile file = workspaceRoot.getFile(filePath); final IEditorInput newInput = new FileEditorInput(file); // Check if the editor is already open IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy(); IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getEditorReferences(); for (int i = 0; i < editorRefs.length; i++) { if (matchingStrategy.matches(editorRefs[i], newInput)) { MessageDialog.openWarning(shell, Messages.CrossflowDiagramEditor_SaveAsErrorTitle, Messages.CrossflowDiagramEditor_SaveAsErrorMessage); return; } } boolean success = false; try { provider.aboutToChange(newInput); getDocumentProvider(newInput).saveDocument(progressMonitor, newInput, getDocumentProvider().getDocument(getEditorInput()), true); success = true; } catch (CoreException x) { IStatus status = x.getStatus(); if (status == null || status.getSeverity() != IStatus.CANCEL) { ErrorDialog.openError(shell, Messages.CrossflowDiagramEditor_SaveErrorTitle, Messages.CrossflowDiagramEditor_SaveErrorMessage, x.getStatus()); } } finally { provider.changed(newInput); if (success) { setInput(newInput); } } if (progressMonitor != null) { progressMonitor.setCanceled(!success); } }
Example 15
Source File: ParameterSection.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * Removes the items. * * @param itemsToRemove the items to remove * @param giveWarningMsg the give warning msg * @return true, if successful */ private boolean removeItems(TreeItem[] itemsToRemove, boolean giveWarningMsg) { String[] namesToRemove = new String[itemsToRemove.length]; boolean[] isGroup = new boolean[itemsToRemove.length]; StringBuffer msgGroup = new StringBuffer(); StringBuffer msg = new StringBuffer(); StringBuffer oMsg = new StringBuffer(); for (int i = 0; i < itemsToRemove.length; i++) { namesToRemove[i] = getName(itemsToRemove[i].getText()); isGroup[i] = isGroup(itemsToRemove[i]); if (isGroup[i]) { if (NOT_IN_ANY_GROUP.equals(namesToRemove[i])) msgGroup .append("\nThis action removes all parameter descriptions in the <Not in any group> section."); else { if (i > 0) msgGroup.append(", "); else if (COMMON_GROUP.equals(namesToRemove[i])) msgGroup .append("\nThis action removes all parameter descriptions in the <Common> section."); else msgGroup .append("\nGroups being removed, together with their parameter definitions defined here: \n"); if (!COMMON_GROUP.equals(namesToRemove[i])) msgGroup.append(namesToRemove[i]); } } else if (isParameter(itemsToRemove[i])) { if (i > 0) msg.append(", "); else msg.append("\nParameters being removed: \n"); msg.append(namesToRemove[i]); } else if (isOverride(itemsToRemove[i])) { if (i > 0) oMsg.append(", "); else oMsg.append("\nOverride being removed: \n"); oMsg.append(namesToRemove[i]); } else throw new InternalErrorCDE("invalid state"); } if (giveWarningMsg && Window.CANCEL == Utility.popOkCancel("Confirm Remove", "Please confirm remove, or Cancel.\n" + msgGroup.toString() + msg.toString() + oMsg.toString(), MessageDialog.WARNING)) return false; // loop thru all things being removed, and remove them for (int i = 0; i < itemsToRemove.length; i++) { if (isGroup[i]) { removeGroup(itemsToRemove[i], namesToRemove[i]); } else if (isParameter(itemsToRemove[i])) { // just a plain parameter being // removed removeParameter(itemsToRemove[i], namesToRemove[i]); } else if (isOverride(itemsToRemove[i])) { TreeItem parentItem = itemsToRemove[i].getParentItem(); ConfigurationParameter cp = getCorrespondingModelParm(parentItem); cp.setOverrides(removeOverride(cp, getItemIndex(parentItem, itemsToRemove[i]))); itemsToRemove[i].dispose(); if (cp.getOverrides().length == 0) { removeParameter(parentItem, getName(parentItem)); } } else throw new InternalErrorCDE("Invalid state"); } return true; }
Example 16
Source File: GeneralSection.java From uima-uimaj with Apache License 2.0 | 4 votes |
@Override public void handleEvent(Event event) { if (event.widget == primitiveButton || event.widget == aggregateButton) { boolean isPrimitive = primitiveButton.getSelection(); // Note: events occur when button is selected or deselected if (event.widget == primitiveButton && !isPrimitive) return; // deselecting if (event.widget == aggregateButton && isPrimitive) return; // deselecting if (isPrimitive && isPrimitive()) return; // nothing changed if (!isPrimitive && isAggregate()) return; // nothing changed if (isPrimitive) { if (Window.CANCEL == Utility.popOkCancel("Switching from Aggregate", "This action will clear the capabilities, reset the delegates, " + "reset the flow, reset the parameters, reset any resource information " + "and start with an empty type system. Are you sure?", MessageDialog.WARNING)) { aggregateButton.setSelection(true); primitiveButton.setSelection(false); return; } editor.getAeDescription().setAnnotatorImplementationName(""); } else { // if (isLocalProcessingDescriptor() && !isAeDescriptor()) { // Utility.popMessage("Not Allowed", // "Cas Consumers, Cas Initializers, Collection Readers, and Flow Controllers cannot be // Aggregates.", // MessageDialog.ERROR); // primitiveButton.setSelection(true); // aggregateButton.setSelection(false); // return; // } if (Window.CANCEL == Utility.popOkCancel("Switching from Primitive AE", "This action will clear the capabilities, reset the delegates, " + "reset the parameters, reset any resource information " + "and reset the type system. Are you sure?", MessageDialog.WARNING)) { primitiveButton.setSelection(true); aggregateButton.setSelection(false); return; } editor.getAeDescription().setAnnotatorImplementationName(null); } editor.getAeDescription().setPrimitive(isPrimitive); commonResets(); try { editor.setAeDescription(editor.getAeDescription()); } catch (ResourceInitializationException e) { throw new InternalErrorCDE("invalid state", e); } javaButton.setEnabled(isPrimitive); cppButton.setEnabled(isPrimitive); HeaderPage page = editor.getAggregatePage(); if (null != page) page.markStale(); page = editor.getParameterPage(); if (null != page) page.markStale(); page = editor.getSettingsPage(); if (null != page) page.markStale(); page = editor.getTypePage(); if (null != page) markRestOfPageStale(page.getManagedForm(), null); page = editor.getCapabilityPage(); if (null != page) page.markStale(); page = editor.getIndexesPage(); if (null != page) page.markStale(); page = editor.getResourcesPage(); if (null != page) page.markStale(); } if (event.widget == javaButton || event.widget == cppButton) { valueChanged = false; if (cppButton.getSelection()) { editor.getAeDescription().setFrameworkImplementation( setValueChanged(Constants.CPP_FRAMEWORK_NAME, editor.getAeDescription() .getFrameworkImplementation())); } else { editor.getAeDescription().setFrameworkImplementation( setValueChanged(Constants.JAVA_FRAMEWORK_NAME, editor.getAeDescription() .getFrameworkImplementation())); } if (!valueChanged) return; } PrimitiveSection s = editor.getOverviewPage().getPrimitiveSection(); if (null != s) { s.refresh(); // next line makes the bounding rectangle show up s.getSection().getClient().redraw(); } setFileDirty(); }
Example 17
Source File: CapabilitySection.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * Handle remove. * * @param removeItem the remove item * @param itemKind the item kind */ private void handleRemove(TreeItem removeItem, int itemKind) { int selectionIndex = tt.indexOf(tt.getSelection()[0]); Capability c = getCapability(removeItem); switch (itemKind) { case CS: { if (Window.CANCEL == Utility.popOkCancel("Confirm Remove", "This action will remove an entire capability set. Please confirm.", MessageDialog.WARNING)) { maybeSetSelection(tt, selectionIndex + 1); return; } removeCapabilitySet(c); removeItem.dispose(); break; } case LANG_ITEM: { c.setLanguagesSupported(stringArrayRemove(c.getLanguagesSupported(), removeItem .getText(NAME_COL))); removeItem.dispose(); break; } case SOFA_ITEM: { if (Window.CANCEL == Utility .popOkCancel( "Confirm Removal of Sofa", "This action will remove this Sofa as a capability, and delete its mappings if no other capability set declares this Sofa." + " Please confirm.", MessageDialog.WARNING)) { maybeSetSelection(tt, selectionIndex + 1); return; } String sofaName = removeItem.getText(NAME_COL); boolean isInput = INPUT.equals(removeItem.getText(INPUT_COL)); if (isInput) c.setInputSofas((String[]) Utility.removeElementFromArray(c.getInputSofas(), sofaName, String.class)); else c.setOutputSofas((String[]) Utility.removeElementFromArray(c.getOutputSofas(), sofaName, String.class)); removeItem.dispose(); if (!anyCapabilitySetDeclaresSofa(sofaName, isInput)) { Comparator comparator = new Comparator() { @Override public int compare(Object o1, Object o2) { String name = (String) o1; SofaMapping sofaMapping = (SofaMapping) o2; if (name.equals(sofaMapping.getAggregateSofaName())) return 0; return 1; } }; editor.getAeDescription().setSofaMappings( (SofaMapping[]) Utility.removeElementsFromArray(getSofaMappings(), sofaName, SofaMapping.class, comparator)); sofaMapSection.markStale(); } break; } case TYPE: { if (Window.CANCEL == Utility.popOkCancel("Confirm Removal of Type", "This action will remove this type as a capability. Please confirm.", MessageDialog.WARNING)) { maybeSetSelection(tt, selectionIndex + 1); return; } TreeItem[] features = removeItem.getItems(); if (null != features) for (int i = 0; i < features.length; i++) { removeFeature(c, features[i]); } String typeNameToRemove = getFullyQualifiedName(removeItem); if (isInput(removeItem)) c.setInputs(typeOrFeatureArrayRemove(c.getInputs(), typeNameToRemove)); if (isOutput(removeItem) /* || isUpdate(removeItem) */) c.setOutputs(typeOrFeatureArrayRemove(c.getOutputs(), typeNameToRemove)); removeItem.dispose(); break; } case FEAT: { removeFeature(c, removeItem); break; } default: throw new InternalErrorCDE("invalid state"); } maybeSetSelection(tt, selectionIndex - 1); finishAction(); }
Example 18
Source File: TypeSection.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * Handle add feature. * * @param parent the parent */ // disabled unless type is selected public void handleAddFeature(TreeItem parent) { TypeDescription td = getTypeDescriptionFromTableTreeItem(parent); // guaranteed non-null - otherwise add button disabled TypeDescription localTd = getLocalTypeDefinition(td); // AddFeatureDialog dialog = new AddFeatureDialog(this, td, null); if (dialog.open() == Window.CANCEL) { return; } FeatureDescription fd = localTd.addFeature(null, null, null); featureUpdate(fd, dialog); editor.addDirtyTypeName(td.getName()); // update the GUI // if this type is merged with an import or with a built-in, // need to "refresh" if (isImportedType(td) || isBuiltInType(td)) { if (!isImportedFeature(dialog.featureName, td)) { // don't need to check builtin Feature because gui doesn't let you // define a built-in feature again fd = td.addFeature(null, null, null); featureUpdate(fd, dialog); } refresh(); selectTypeInGui(td); finishAction(); } else { fd = td.addFeature(null, null, null); featureUpdate(fd, dialog); TreeItem item = new TreeItem(parent, SWT.NONE); updateGuiFeature(item, fd, td); parent.setExpanded(true); finishActionPack(); } }
Example 19
Source File: ConvertJavaCode.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public void runJavaConverter(final Set<ICompilationUnit> compilationUnits, Shell activeShell) throws ExecutionException { Map<ICompilationUnit, ConversionResult> conversionResults = newHashMap(); boolean canceled = convertAllWithProgress(activeShell, compilationUnits, conversionResults); if (canceled) { return; } boolean hasConversionFailures = any(conversionResults.values(), new Predicate<ConversionResult>() { @Override public boolean apply(ConversionResult input) { return input.getProblems().iterator().hasNext(); } }); if (hasConversionFailures) { ConversionProblemsDialog problemsDialog = new ConversionProblemsDialog(activeShell, conversionResults); problemsDialog.open(); if (problemsDialog.getReturnCode() == Window.CANCEL) { return; } } final String storedValue = dialogs.getUserDecision(DELETE_JAVA_FILES_AFTER_CONVERSION); boolean deleteJavaFiles = false; if (MessageDialogWithToggle.PROMPT.equals(storedValue)) { int userAnswer = dialogs.askUser("Delete Java source files?", "Xtend converter", DELETE_JAVA_FILES_AFTER_CONVERSION, activeShell); if (userAnswer == IDialogConstants.CANCEL_ID) { //cancel return; } else if (userAnswer == IDialogConstants.YES_ID) { deleteJavaFiles = true; } } else if (MessageDialogWithToggle.ALWAYS.equals(storedValue)) { deleteJavaFiles = true; } for (final Entry<ICompilationUnit, ConversionResult> result : conversionResults.entrySet()) { ICompilationUnit compilationUnit = result.getKey(); ConversionResult conversionResult = result.getValue(); String xtendCode = conversionResult.getXtendCode(); IFile xtendFileToCreate = xtendFileToCreate(compilationUnit); if (!conversionResult.getProblems().iterator().hasNext()) { String formattedCode = formatXtendCode(xtendFileToCreate, xtendCode); if (formattedCode != null) { xtendCode = formattedCode; } } writeToFile(xtendFileToCreate, xtendCode); if (deleteJavaFiles) { try { compilationUnit.delete(true, null); } catch (JavaModelException e) { handleException("Unable to delete Java file.", e, compilationUnit.getResource()); } } } }
Example 20
Source File: Controller.java From arx with Apache License 2.0 | 4 votes |
/** * File->Import hierarchy. */ public void actionMenuFileImportHierarchy() { if (model == null) { main.showInfoDialog(main.getShell(), Resources.getMessage("Controller.54"), //$NON-NLS-1$ Resources.getMessage("Controller.55")); //$NON-NLS-1$ return; } else if (model.getInputConfig().getInput() == null) { main.showInfoDialog(main.getShell(), Resources.getMessage("Controller.56"), //$NON-NLS-1$ Resources.getMessage("Controller.57")); //$NON-NLS-1$ return; } final String path = actionShowOpenFileDialog(main.getShell(), "*.csv"); //$NON-NLS-1$ if (path != null) { // Determine separator DialogOpenHierarchy dialog = null; try { dialog = new DialogOpenHierarchy(main.getShell(), this, path, false); dialog.create(); if (dialog.open() == Window.CANCEL) { return; } } catch (Throwable error) { if (error instanceof RuntimeException) { if (error.getCause() != null) { error = error.getCause(); } } if ((error instanceof IllegalArgumentException) || (error instanceof IOException)) { main.showInfoDialog(main.getShell(), Resources.getMessage("Controller.37"), error.getMessage()); //$NON-NLS-1$ } else { main.showErrorDialog(main.getShell(), Resources.getMessage("Controller.78"), error); //$NON-NLS-1$ } return; } // Load hierarchy final char separator = dialog.getSeparator(); final Charset charset = dialog.getCharset(); final Hierarchy hierarchy = actionImportHierarchy(path, charset, separator); if (hierarchy != null) { String attr = model.getSelectedAttribute(); model.getInputConfig().setMaximumGeneralization(attr, null); model.getInputConfig().setMinimumGeneralization(attr, null); model.getInputConfig().setHierarchy(attr, hierarchy); update(new ModelEvent(this, ModelPart.HIERARCHY, hierarchy)); } } }