/** * @return an instanciation of the given content-type class name, or null if class wasn't found */ public static ContentType getContentTypeFromClassName(String contentTypeClassName) { if (contentTypeClassName == null) contentTypeClassName = getAvailableContentTypes()[DEFAULT_CONTENT_TYPE_INDEX]; ContentType ct = null; try { Class clazz = Class.forName(contentTypeClassName); ct = (ContentType) clazz.newInstance(); } catch (ClassNotFoundException cnfex) { if (jpicedt.Log.DEBUG) cnfex.printStackTrace(); JPicEdt.getMDIManager() .showMessageDialog( "The pluggable content-type you asked for (class " + cnfex.getLocalizedMessage() + ") isn't currently installed, using default instead...", Localizer.currentLocalizer().get("msg.LoadingContentTypeClass"), JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { if (jpicedt.Log.DEBUG) ex.printStackTrace(); JPicEdt.getMDIManager() .showMessageDialog( ex.getLocalizedMessage(), Localizer.currentLocalizer().get("msg.LoadingContentTypeClass"), JOptionPane.ERROR_MESSAGE); } return ct; }
void browse(String urlStr) { try { Desktop.getDesktop().browse(new URI(urlStr)); } catch (Exception ex) { showDialog(); statusBar.setText(ex.getLocalizedMessage()); if (JConsole.isDebug()) { ex.printStackTrace(); } } }
/** Change the state of the main frame in the swing thread */ @Override public void run() { try { mainFrame.setVisible(true); } catch (Exception ex) { LOGGER.error(ex.getLocalizedMessage(), ex); dispose(); } finally { progress.setCancelled(true); } }
private void reportProblem(final String qualifiedName, @Nullable Exception ex) { String reason = null; if (ex != null) { reason = ex.getLocalizedMessage(); } if (reason == null || reason.length() == 0) { reason = DebuggerBundle.message("error.io.error"); } final StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { buf.append(qualifiedName).append(" : ").append(reason); myProgress.addMessage(myDebuggerSession, MessageCategory.ERROR, buf.toString()); } finally { StringBuilderSpinAllocator.dispose(buf); } }
private void doImportAction(final DataContext dataContext) { final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, false) { @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE); } @Override public boolean isFileSelectable(VirtualFile file) { return file.getFileType() == StdFileTypes.XML; } }; descriptor.setDescription( "Please select the configuration file (usually named IntelliLang.xml) to import."); descriptor.setTitle("Import Configuration"); descriptor.putUserData(LangDataKeys.MODULE_CONTEXT, LangDataKeys.MODULE.getData(dataContext)); final SplitterProportionsData splitterData = new SplitterProportionsDataImpl(); splitterData.externalizeFromDimensionService( "IntelliLang.ImportSettingsKey.SplitterProportions"); final VirtualFile file = FileChooser.chooseFile(descriptor, myProject, null); if (file == null) return; try { final Configuration cfg = Configuration.load(file.getInputStream()); if (cfg == null) { Messages.showWarningDialog( myProject, "The selected file does not contain any importable configuration.", "Nothing to Import"); return; } final CfgInfo info = getDefaultCfgInfo(); final Map<String, Set<InjInfo>> currentMap = ContainerUtil.classify( info.injectionInfos.iterator(), new Convertor<InjInfo, String>() { public String convert(final InjInfo o) { return o.injection.getSupportId(); } }); final List<BaseInjection> originalInjections = new ArrayList<BaseInjection>(); final List<BaseInjection> newInjections = new ArrayList<BaseInjection>(); //// remove duplicates // for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { // final Set<BaseInjection> currentInjections = currentMap.get(supportId); // if (currentInjections == null) continue; // for (BaseInjection injection : currentInjections) { // Configuration.importInjections(newInjections, Collections.singleton(injection), // originalInjections, newInjections); // } // } // myInjections.clear(); // myInjections.addAll(newInjections); for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { ArrayList<InjInfo> list = new ArrayList<InjInfo>( ObjectUtils.notNull(currentMap.get(supportId), Collections.<InjInfo>emptyList())); final List<BaseInjection> currentInjections = getInjectionList(list); final List<BaseInjection> importingInjections = cfg.getInjections(supportId); if (currentInjections == null) { newInjections.addAll(importingInjections); } else { Configuration.importInjections( currentInjections, importingInjections, originalInjections, newInjections); } } info.replace(originalInjections, newInjections); myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos)); final int n = newInjections.size(); if (n > 1) { Messages.showInfoMessage( myProject, n + " entries have been successfully imported", "Import Successful"); } else if (n == 1) { Messages.showInfoMessage( myProject, "One entry has been successfully imported", "Import Successful"); } else { Messages.showInfoMessage(myProject, "No new entries have been imported", "Import"); } } catch (Exception ex) { Configuration.LOG.error(ex); final String msg = ex.getLocalizedMessage(); Messages.showErrorDialog( myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Import Failed"); } }
public void run() { if (!goOn) return; for (int i = 0; i < entries.length; i++) { BibtexEntry entry = entries[i]; // Make a list of all PDFs linked from this entry: List<File> files = new ArrayList<File>(); // First check the (legacy) "pdf" field: String pdf = entry.getField("pdf"); String dir = panel.metaData().getFileDirectory("pdf"); File f = Util.expandFilename(pdf, new String[] {dir, "."}); if (f != null) files.add(f); // Then check the "file" field: dir = panel.metaData().getFileDirectory(GUIGlobals.FILE_FIELD); String field = entry.getField(GUIGlobals.FILE_FIELD); if (field != null) { FileListTableModel tm = new FileListTableModel(); tm.setContent(field); for (int j = 0; j < tm.getRowCount(); j++) { FileListEntry flEntry = tm.getEntry(j); if ((flEntry.getType() != null) && (flEntry.getType().getName().toLowerCase().equals("pdf"))) { f = Util.expandFilename(flEntry.getLink(), new String[] {dir, "."}); if (f != null) files.add(f); } } } optDiag.progressArea.append(entry.getCiteKey() + "\n"); if (files.size() == 0) { skipped++; optDiag.progressArea.append(" " + Globals.lang("Skipped - No PDF linked") + ".\n"); } else for (File file : files) { if (!file.exists()) { skipped++; optDiag.progressArea.append( " " + Globals.lang("Skipped - PDF does not exist") + ":\n"); optDiag.progressArea.append(" " + file.getPath() + "\n"); } else { try { XMPUtil.writeXMP(file, entry, database); optDiag.progressArea.append(" " + Globals.lang("Ok") + ".\n"); entriesChanged++; } catch (Exception e) { optDiag.progressArea.append( " " + Globals.lang("Error while writing") + " '" + file.getPath() + "':\n"); optDiag.progressArea.append(" " + e.getLocalizedMessage() + "\n"); errors++; } } } if (optDiag.canceled) { optDiag.progressArea.append("\n" + Globals.lang("Operation canceled.\n")); break; } } optDiag.progressArea.append( "\n" + Globals.lang( "Finished writing XMP for %0 file (%1 skipped, %2 errors).", String.valueOf(entriesChanged), String.valueOf(skipped), String.valueOf(errors))); optDiag.done(); }