private void setPrologInterface(PrologInterface newPif, boolean updateActivePif) { if (currentPif == newPif) { return; } if (currentPif != null) { viewerStates.put(currentPif, viewer.saveState()); } currentPif = newPif; if (currentPif != null) { addHooks(currentPif); try { connect(currentPif); } catch (PrologInterfaceException e) { Debug.report(e); } reconfigureViewer(currentPif); getDefaultPrologConsoleService().fireActivePrologInterfaceChanged(this); if (updateActivePif) { PrologRuntimeUIPlugin.getDefault() .getPrologInterfaceService() .setActivePrologInterface(currentPif); } } else { Debug.debug("no pif (yet)."); } if (automatedSelector != null) { automatedSelector.update(); } writeCurrentProcessPortToFile(); }
private void startServer(PrologInterface pif, PrologSession session) { try { String queryString = bT( PDTConsolePredicates.PDT_START_CONSOLE_SERVER, "Port", Util.quoteAtom( PrologRuntimePlugin.getDefault().getPrologInterfaceRegistry().getKey(pif))); Debug.info("starting console server using: " + queryString); Map<String, ?> result = session.queryOnce(queryString); if (result == null) { Debug.info("starting server failed, which may mean that it is actualy running already."); result = session.queryOnce(bT(PDTConsolePredicates.PDT_CURRENT_CONSOLE_SERVER, "Port")); if (result == null) { throw new RuntimeException("No Server running."); } } int port = Integer.parseInt((String) result.get("Port")); Debug.debug("A server thread seems to be listinging at port " + port); } catch (Throwable e) { Debug.report(e); throw new RuntimeException(e); } }
@Override public void run() { boolean answer = MessageDialog.openQuestion( PrologConsoleView.this.getViewSite().getShell(), "Kill process", "Are you sure you want to kill the process? This will remove all breakpoints and will delete the list of consulted files"); if (answer) { try { Job j = new UIJob("Stopping the PrologInterface") { @Override public IStatus runInUIThread(IProgressMonitor monitor) { try { monitor.beginTask("initializing...", IProgressMonitor.UNKNOWN); PrologInterfaceRegistry registry = PrologRuntimePlugin.getDefault().getPrologInterfaceRegistry(); PrologInterface oldPif = getPrologInterface(); if (oldPif != null) { String currentKey = registry.getKey(oldPif); oldPif.clearConsultedFiles(); oldPif.stop(); if ("true".equals(oldPif.getAttribute(KILLABLE))) { Set<Subscription> subscriptionsForPif = registry.getSubscriptionsForPif(currentKey); for (Subscription s : subscriptionsForPif) { registry.removeSubscription(s); } registry.removePrologInterface(currentKey); getDefaultPrologConsoleService() .fireConsoleVisibilityChanged(PrologConsoleView.this); PrologRuntimeUIPlugin.getDefault() .getPrologInterfaceService() .setActivePrologInterface(null); } } } catch (Throwable e) { Debug.report(e); return Status.CANCEL_STATUS; } finally { monitor.done(); } return Status.OK_STATUS; } }; j.schedule(); } catch (Throwable t) { Debug.report(t); } } }
@Override public void run() { try { getPrologInterface().queryOnce(getQuery()); } catch (PrologInterfaceException e) { Debug.report(e); } }
@Override public void ensureConnectionForCurrentPrologInterface() { try { connect(currentPif); } catch (PrologInterfaceException e) { Debug.report(e); } }
/* * (non-Javadoc) * * @see org.cs3.pl.prolog.LifeCycleHook#afterInit() */ @Override public void afterInit(PrologInterface pif) { try { connect(pif); } catch (PrologInterfaceException e) { Debug.report(e); } }
public DefaultResourceFileLocator(File root) { String rootPath = root.getAbsolutePath(); try { this.root = rootPath.endsWith(File.separator) ? rootPath : rootPath + File.separator; } catch (Exception e) { Debug.report(e); throw new RuntimeException(e.getMessage()); } }
@Override public void setFocus() { if (viewer == null) { Debug.warning("PrologConsoleView.setFocus(): View not instantiated yet."); return; } viewer.getControl().setFocus(); getDefaultPrologConsoleService().fireConsoleRecievedFocus(this); }
private void loadHistory(ConsoleHistory history) { try { FileInputStream in = new FileInputStream(getHistoryFile()); history.loadHistory(in); in.close(); } catch (IOException e) { Debug.report(e); } }
@Override public void createPartControl(Composite parent) { try { createPartControl_impl(parent); } catch (Throwable t) { Debug.report(t); throw new RuntimeException(t.getLocalizedMessage(), t); } }
private void saveHistory(ConsoleHistory history) { if (history == null) { return; } try { FileOutputStream out = new FileOutputStream(getHistoryFile()); history.saveHistory(out); out.close(); } catch (IOException e) { Debug.report(e); } }
@Override public void run() { try { UIJob j = new UIJob(getToolTipText()) { @Override public IStatus runInUIThread(IProgressMonitor monitor) { try { PrologConsole c = getConsole(); int caretOffset = c.getCaretOffset(); int offsetInLineBuffer = caretOffset - c.getStartOfInput(); ConsoleModel model = c.getModel(); String lineBuffer = model.getLineBuffer(); if (offsetInLineBuffer < 0) { offsetInLineBuffer = lineBuffer.length(); caretOffset = c.getStartOfInput() + lineBuffer.length(); } String textToInsert = getTextToInsert(); if (textToInsert == null) { return Status.OK_STATUS; } lineBuffer = lineBuffer.substring(0, offsetInLineBuffer) + textToInsert + lineBuffer.substring(offsetInLineBuffer); model.setLineBuffer(lineBuffer); c.setCaretOffset(caretOffset + textToInsert.length()); } catch (Throwable e) { Debug.report(e); return Status.CANCEL_STATUS; } finally { monitor.done(); } return Status.OK_STATUS; } private PrologConsole getConsole() { return PrologConsoleView.this; } }; j.schedule(); } catch (Throwable t) { Debug.report(t); } }
@Override public void run() { try { Job j = new UIJob("Generating load file") { @Override public IStatus runInUIThread(IProgressMonitor monitor) { try { monitor.beginTask("initializing...", IProgressMonitor.UNKNOWN); if (getPrologInterface() != null) { List<String> consultedFiles = getPrologInterface().getConsultedFiles(); // only create load file if there are consulted files if (consultedFiles != null && consultedFiles.size() > 0) { WizardDialog dialog = new WizardDialog( getViewSite().getShell(), new GenerateLoadFileWizard(consultedFiles)); dialog.open(); } else { MessageDialog.openWarning( PrologConsoleView.this.getViewSite().getShell(), "Generate Load File", "No need for a load file, since no files are consulted."); } } } catch (Throwable e) { Debug.report(e); return Status.CANCEL_STATUS; } finally { monitor.done(); } return Status.OK_STATUS; } }; j.schedule(); } catch (Throwable t) { Debug.report(t); } }
@Override public void dispose() { PrologConsolePlugin.getDefault().getPrologConsoleService().unregisterPrologConsole(this); PrologRuntimeUIPlugin.getDefault() .getPrologInterfaceService() .unRegisterActivePrologInterfaceListener(this); for (Iterator<PrologInterface> it = models.keySet().iterator(); it.hasNext(); ) { PrologInterface pif = it.next(); try { disconnect(pif); removeHooks(pif); } catch (Throwable e) { Debug.report(e); } } models.clear(); contextMenu.dispose(); // viewer.getControl().dispose(); super.dispose(); }
private void ensureConnection(final PrologInterface pif, PrologSocketConsoleModel model) throws PrologInterfaceException { if (model.isConnected()) { return; } PrologSession session = pif.getSession(PrologInterface.NONE); // FileSearchPathConfigurator.configureFileSearchPath(PrologRuntimeUIPlugin.getDefault() // .getLibraryManager(), session, // new String[] { PDTConsole.PL_LIBRARY }); Map<String, ?> result = null; try { // result = session.queryOnce( "consult(lib_pdt_console_pl(loader))."); result = session.queryOnce( bT( PDTConsolePredicates.PDT_START_CONSOLE_SERVER, "Port", Util.quoteAtom( PrologRuntimePlugin.getDefault().getPrologInterfaceRegistry().getKey(pif)))); if (result == null) { startServer(pif, session); result = session.queryOnce(bT(PDTConsolePredicates.PDT_CURRENT_CONSOLE_SERVER, "Port")); } if (result == null) { throw new RuntimeException("could not install console server"); } } catch (Exception e) { Debug.info(e.toString()); } finally { if (session != null) { session.dispose(); } } int port = Integer.parseInt(result.get("Port").toString()); model.setPort(port); model.connect(); }
private boolean ensureFileExists() { String msg = null; String value = getTextControl().getText(); if (value == null) { msg = "History File must not be null"; } if (value.length() == 0) { msg = "History File must not be empty"; } File f = new File(value); if (!f.isAbsolute()) { msg = "History File must be an absolute path"; } if (f.isDirectory()) { msg = "History File exists, but is a directory"; } if (!f.exists()) { try { if (!f.createNewFile()) {} } catch (IOException e) { Debug.report(e); msg = "could not create History File"; } } if (!f.canWrite()) { msg = "History File exists, but is not writable"; } if (msg != null) { // error showErrorMessage(msg); return false; } // OK! clearErrorMessage(); return true; }
@Override public void run() { try { Job j = new Job("Restarting the PrologInterface") { @Override public IStatus run(IProgressMonitor monitor) { try { monitor.beginTask("initializing...", 2); try { if (getPrologInterface() != null) { getPrologInterface().stop(); monitor.worked(1); } // setPrologInterface(getEditorPrologInterface()); } finally { if (getPrologInterface() != null) { if (!getPrologInterface().isDown()) { getPrologInterface().reset(); Thread.sleep(1000); } final String reconsultFiles = PrologConsolePlugin.getDefault() .getPreferenceValue( PDTConsole.PREF_RECONSULT_ON_RESTART, PDTConsole.RECONSULT_NONE); getPrologInterface().start(); if (reconsultFiles.equals(PDTConsole.RECONSULT_NONE)) { getPrologInterface().clearConsultedFiles(); } else { PDTCommonPlugin.getDefault() .reconsultFiles( getPrologInterface(), reconsultFiles.equals(PDTConsole.RECONSULT_ENTRY)); } Display.getDefault() .asyncExec( new Runnable() { @Override public void run() { getDefaultPrologConsoleService() .fireConsoleVisibilityChanged(PrologConsoleView.this); } }); writeCurrentProcessPortToFile(); } } } catch (Throwable e) { Debug.report(e); return Status.CANCEL_STATUS; } finally { monitor.done(); } return Status.OK_STATUS; } }; j.schedule(); } catch (Throwable t) { Debug.report(t); } }
@Override public void run(IMarker marker) { IFile file = (IFile) marker.getResource(); TextFileChange textFileChange = new TextFileChange(file.getName(), file); MultiTextEdit fileChangeRootEdit = new MultiTextEdit(); // a file change contains a tree of edits, first add the root of them textFileChange.setEdit(fileChangeRootEdit); int offset; try { offset = marker.getAttribute(IMarker.CHAR_START, -1); if (offset == -1) { int line = marker.getAttribute(IMarker.LINE_NUMBER, -1); if (line == -1) { return; } offset = UIUtils.getDocument(file).getLineOffset(line - 1); } InsertEdit quickfix = new InsertEdit(offset, marker.getAttribute(PDTMarker.QUICKFIX_ACTION).toString()); fileChangeRootEdit.addChild(quickfix); if (showWizard) { final TextFileChange fChange = textFileChange; Refactoring ref = new Refactoring() { @Override public String getName() { return "PDT Refactoring"; } @Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { return fChange; } @Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { return new RefactoringStatus(); } @Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { return new RefactoringStatus(); } }; RefactoringWizard wizard = new RefactoringWizard(ref, RefactoringWizard.WIZARD_BASED_USER_INTERFACE) { @Override protected void addUserInputPages() {} }; Shell shell = UIUtils.getActiveShell(); RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard); try { if (op.run(shell, "") != IDialogConstants.CANCEL_ID) { // changes are already performed by the dialog file.refreshLocal(IResource.DEPTH_INFINITE, null); PrologRuntimeUIPlugin.getDefault().getPrologInterfaceService().consultFile(file); // PLMarkerUtils.updateFileMarkers(file); } } catch (InterruptedException e) { } } else { textFileChange.perform(new NullProgressMonitor()); file.refreshLocal(IResource.DEPTH_INFINITE, null); PrologRuntimeUIPlugin.getDefault().getPrologInterfaceService().consultFile(file); // PLMarkerUtils.updateFileMarkers(file); } } catch (NumberFormatException e1) { Debug.report(e1); } catch (CoreException e1) { Debug.report(e1); } catch (BadLocationException e) { Debug.report(e); } }