/** * Creates the dialog according to the Eclipse version we have (on 3.2, the old API is used) * * @param pythonNatures */ public static SelectionDialog create( Shell shell, List<AbstractAdditionalTokensInfo> additionalInfo, String selectedText) { boolean expectedError = true; try { GlobalsTwoPanelElementSelector2 newDialog = new GlobalsTwoPanelElementSelector2(shell, true, selectedText); // If we were able to instance it, the error is no longer expected! expectedError = false; newDialog.setElements(additionalInfo); return newDialog; } catch (Throwable e) { // That's OK: it's only available for Eclipse 3.3 onwards. if (expectedError) { Log.log(e); } } // If it got here, we were unable to create the new dialog (show the old -- compatible with 3.2) GlobalsTwoPaneElementSelector dialog; dialog = new GlobalsTwoPaneElementSelector(shell); dialog.setMessage("Filter"); if (selectedText != null && selectedText.length() > 0) { dialog.setFilter(selectedText); } List<IInfo> lst = new ArrayList<IInfo>(); for (AbstractAdditionalTokensInfo info : additionalInfo) { lst.addAll(info.getAllTokens()); } dialog.setElements(lst.toArray()); return dialog; }
/** * Restores the info for a module manager * * @param monitor a monitor to keep track of the progress * @param m the module manager * @param nature the associated nature (may be null if there is no associated nature -- as is the * case when restoring system info). * @return the info generated from the module manager */ public static AbstractAdditionalTokensInfo restoreInfoForModuleManager( IProgressMonitor monitor, IModulesManager m, String additionalFeedback, AbstractAdditionalTokensInfo info, IPythonNature nature, int grammarVersion) { if (monitor == null) { monitor = new NullProgressMonitor(); } // TODO: Check if keeping a zip file open makes things faster... // Timer timer = new Timer(); ModulesKey[] allModules = m.getOnlyDirectModules(); int i = 0; FastStringBuffer msgBuffer = new FastStringBuffer(); for (ModulesKey key : allModules) { if (monitor.isCanceled()) { return null; } i++; if (PythonPathHelper.canAddAstInfoFor( key)) { // otherwise it should be treated as a compiled module (no ast generation) if (i % 17 == 0) { msgBuffer.clear(); msgBuffer.append("Creating "); msgBuffer.append(additionalFeedback); msgBuffer.append(" additional info ("); msgBuffer.append(i); msgBuffer.append(" of "); msgBuffer.append(allModules.length); msgBuffer.append(") for "); msgBuffer.append(key.file.getName()); monitor.setTaskName(msgBuffer.toString()); monitor.worked(1); } try { if (info.addAstInfo(key, false) == null) { String str = "Unable to generate ast -- using %s.\nError:%s"; ErrorDescription errorDesc = null; throw new RuntimeException( com.aptana.shared_core.string.StringUtils.format( str, PyParser.getGrammarVersionStr(grammarVersion), (errorDesc != null && errorDesc.message != null) ? errorDesc.message : "unable to determine")); } } catch (Throwable e) { Log.log(IStatus.ERROR, "Problem parsing the file :" + key.file + ".", e); } } } // timer.printDiff("Time to restore additional info"); return info; }