Package org.eclipse.ui.texteditor

Examples of org.eclipse.ui.texteditor.IDocumentProvider


    }
  }

  public IDocument getImplementationDocument() {
    if (this.implementationDocument == null){
      IDocumentProvider provider = new TextFileDocumentProvider();
        try
        {
          IFile implFile = getFile();
            provider.connect(implFile);
            this.implementationDocument = provider.getDocument(implFile);
        }
        catch (CoreException e)
        {
        }
    }
View Full Code Here


        if (describer.describe(modelFile.getContents(), null) != IContentDescriber.VALID)
          return null;
        ToolInterface inter = new ToolInterface();
        inter.setFile(modelFile);
        inter.setPlanName(plan);
        IDocumentProvider provider = new TextFileDocumentProvider();
        provider.connect(modelFile);
        IDocument document = provider.getDocument(modelFile);
        inter.parse(document);
        getTypeCache(project).put((plan + "." + interfaceName).toUpperCase(), model);
        model = inter;
      } catch (CoreException e) {
        ToolPlugin.log(IStatus.ERROR,"Error updating Interface Model.", e);
View Full Code Here

          return null;
        model = new ToolServiceObject();
        model.setFile(modelFile);
        model.setPlanName(planName);
        model.setParent(model.getPlan());
        IDocumentProvider provider = new TextFileDocumentProvider();
        provider.connect(modelFile);
        model.document = provider.getDocument(modelFile);
        model.parse(model.document);
        addToCache(model.getProject(), model);
        model.setDirty(false);

      } catch (CoreException e) {
View Full Code Here

        if (describer.describe(modelFile.getContents(), null) != IContentDescriber.VALID)
          return null;
        ToolInterface inter = new ToolInterface();
        inter.setFile(modelFile);
        inter.setPlanName(plan);
        IDocumentProvider provider = new TextFileDocumentProvider();
        provider.connect(modelFile);
        IDocument document = provider.getDocument(modelFile);
        inter.parse(document);
        getTypeCache(project).put((plan + "." + interfaceName).toUpperCase(), model);
        model = inter;
      } catch (CoreException e) {
        ToolModelActivator.log(IStatus.ERROR,"Error updating Interface Model.", e);
View Full Code Here

      final IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
      if (activeEditor != null) { // If it's null then there is no editor connected to the java file extension
        final IEditorInput editorInput = activeEditor.getEditorInput();
        final IFile htmlFile = ResourceUtil.getFile(editorInput);
        final IFile javaFile = WicketHyperlink.getJavaFile(htmlFile);
        final IDocumentProvider provider = new TextFileDocumentProvider();
        provider.connect(javaFile);

        final IDocument jdoc = provider.getDocument(javaFile);
        int nol = jdoc.getNumberOfLines();
        for (int lidx = 0; lidx < nol; lidx++) {
          IRegion li = jdoc.getLineInformation(lidx);
          String line = jdoc.get(li.getOffset(), li.getLength());
          String[] ss = line.split("\"");
          if (ss.length > 1) {
            for (int i = 1; i < ss.length; i += 2) {
              final String proposedWid = ss[i];
              if (proposedWid.length() > 0 && !proposedWid.contains(":") && !proposedWid.contains("~")) {
                final CompletionProposal proposal = new CompletionProposal(proposedWid, rtr.getOffset(), existingWid.length(), rtr.getOffset(), img, proposedWid, null, line.replaceAll("\"" + proposedWid + "\"", "\"<b>" + proposedWid + "</b>\""));
                proposals.put(proposedWid, proposal);
              }
            }
          }
        }
        provider.disconnect(javaFile);
      }
    } catch (Exception e) {
    }

    return new ArrayList<CompletionProposal>(proposals.values());
View Full Code Here

      if (isExcluded(javaFile)) {
        return;
      }

      try {
        final IDocumentProvider provider = new TextFileDocumentProvider();
        provider.connect(htmlFile);
        final IDocument document = provider.getDocument(htmlFile);
        LDL = document.getLineDelimiter(0).length();
        int sc = 0;
        boolean commented = false;
        String wid_const = DocumentHelper.WICKET;
        for (int i = 0; i < document.getNumberOfLines(); i++) {
          final IRegion li = document.getLineInformation(i);
          final String line = document.get(li.getOffset(), li.getLength());

          if (line.contains("<!--")) {
            commented = true;
            continue;
          }
          if (line.contains("-->")) {
            commented = false;
            continue;
          }

          if (line.contains(QWickieActivator.WICKET_DTD)) {
            wid_const = DocumentHelper.getWicketNamespace(line);
          }

          final String wid_const_id = wid_const + ":id=\"";
          if (line.contains(wid_const_id) && !commented) {
            final String wid = line.split(wid_const_id)[1].split("\"")[0];
            int jlc = getJavaLine(javaFile, wid);
            if (jlc == -1) { // wicket id was not found in this java file
              // get the supertypes for the WebPage (maybe it's added in a BasePage?)
              final List<Object> superTypes = TypeHelper.getSupertypes(javaFile);
              for (final Object superType : superTypes) {
                if (superType instanceof IFile) {
                  jlc = getJavaLine((IFile) superType, wid);
                } else if (superType instanceof IClassFile) {
                  jlc = getJavaLine((IClassFile) superType, wid);
                }
                if (jlc == -1) {
                  // not found, then search in the used types
                  final List<JavaElement> wcts = TypeHelper.getWicketComponentTypes(javaFile);
                  for (final JavaElement wct : wcts) {
                    jlc = getJavaLine(wct, wid);
                    if (jlc > -1) {
                      break;
                    }
                  }
                  if (jlc == -1) {
                    // not found, then search in the used models
                    final List<IVariableBinding> wmts = TypeHelper.getWicketModelTypes(javaFile);
                    for (final IVariableBinding wmt : wmts) {
                      if (wid.equals(wmt.getName())) {
                        jlc = 0;
                        break;
                      }
                    }
                  }
                }
                if (jlc > -1) { // found, so don't go further
                  break;
                }
              }
              if (jlc == -1) {
                final int widPos = sc + line.indexOf("\"" + wid + "\"") + 1;
                FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
                IRegion tagBegin = frda.find(widPos, "<", false, true, false, false);
                IRegion tagEnd = frda.find(tagBegin.getOffset(), " ", true, true, false, false);
                String htmlTag = document.get(tagBegin.getOffset() + 1, tagEnd.getOffset() - tagBegin.getOffset() - 1);
                String htmlSnippet = htmlTag.toLowerCase();
                if (htmlFile != null && "input".equals(htmlSnippet)) {
                  tagEnd = frda.find(tagBegin.getOffset(), ">", true, true, false, false);
                  htmlSnippet = document.get(tagBegin.getOffset() + 1, tagEnd.getOffset() - tagBegin.getOffset() - 1).toLowerCase().trim();
                  if (htmlSnippet.contains("type")) {
                    final String[] hss = htmlSnippet.split(" ");
                    if (hss != null) {
                      for (int j = 0; j < hss.length; j++) {
                        String hs = hss[j];
                        if (hs.startsWith("type")) {
                          htmlSnippet = htmlTag + " " + hs.replace("type=", "").split("\"")[1];
                        }
                      }
                    }
                  } else {
                    htmlSnippet = htmlTag.toLowerCase();
                  }
                }
                addMarker(htmlFile, getErrorText(wid), wid, htmlSnippet, i, widPos, wid.length());
                markJava(javaFile, wid, htmlSnippet);
              }
            }
          }
          sc += li.getLength() + LDL;
        }
        provider.disconnect(htmlFile);
      } catch (final Exception e) {
        QWickieActivator.getDefault().getLog().log(new Status(Status.ERROR, QWickieActivator.PLUGIN_ID, "Error in builder", e));
      }
    }
View Full Code Here

  /**
   * mark an error in a java file
   */
  private void markJava(final IFile javaFile, final String wid, final String htmlSnippet) {
    final IDocumentProvider provider = new TextFileDocumentProvider();
    try {
      provider.connect(javaFile);
      final IDocument document = provider.getDocument(javaFile);
      final String className = javaFile.getName().replaceAll(".java", "");
      final FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
      final IRegion region = frda.find(0, "class " + className, true, true, true, false);
      if (region != null) {
        addMarker(javaFile, getErrorText(wid), wid, htmlSnippet, document.getLineOfOffset(region.getOffset()), region.getOffset() + 6,
            className.length());
      }
      provider.disconnect(javaFile);
    } catch (final Exception e) {
    }
  }
View Full Code Here

    if(input instanceof IFileEditorInput &&
        ((IFileEditorInput) input).getFile().isLinked() &&
        ((IFileEditorInput) input).getFile().getProject().getName().equals(
          ExtLinkedFileHelper.AUTOLINK_PROJECT_NAME)) {
      final IEditorInput newInput;
      IDocumentProvider provider = getDocumentProvider();

      // 1. If file is "untitled" suggest last save location
      // 2. ...otherwise use the file's location (i.e. likely to be a rename in same folder)
      // 3. If a "last save location" is unknown, use user's home
      //
      String suggestedName = null;
      String suggestedPath = null;
      {
        // is it "untitled"
        java.net.URI uri = ((IURIEditorInput) input).getURI();
        String tmpProperty = null;
        try {
          tmpProperty = ((IFileEditorInput) input).getFile().getPersistentProperty(
            TmpFileStoreEditorInput.UNTITLED_PROPERTY);
        }
        catch(CoreException e) {
          // ignore - tmpProperty will be null
        }
        boolean isUntitled = tmpProperty != null && "true".equals(tmpProperty);

        // suggested name
        IPath oldPath = URIUtil.toPath(uri);
        // TODO: input.getName() is probably always correct
        suggestedName = isUntitled
            ? input.getName()
            : oldPath.lastSegment();

        // suggested path
        try {
          suggestedPath = isUntitled
              ? ((IFileEditorInput) input).getFile().getWorkspace().getRoot().getPersistentProperty(
                LAST_SAVEAS_LOCATION)
              : oldPath.toOSString();
        }
        catch(CoreException e) {
          // ignore, suggestedPath will be null
        }

        if(suggestedPath == null) {
          // get user.home
          suggestedPath = System.getProperty("user.home");
        }
      }
      FileDialog dialog = new FileDialog(shell, SWT.SAVE);
      if(suggestedName != null)
        dialog.setFileName(suggestedName);
      if(suggestedPath != null)
        dialog.setFilterPath(suggestedPath);

      dialog.setFilterExtensions(new String[] { "*.b3", "*.*" });
      String path = dialog.open();
      if(path == null) {
        if(progressMonitor != null)
          progressMonitor.setCanceled(true);
        return;
      }

      // Check whether file exists and if so, confirm overwrite
      final File localFile = new File(path);
      if(localFile.exists()) {
        MessageDialog overwriteDialog = new MessageDialog(shell, "Save As", null, path +
            " already exists.\nDo you want to replace it?", MessageDialog.WARNING, new String[] {
            IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
        if(overwriteDialog.open() != Window.OK) {
          if(progressMonitor != null) {
            progressMonitor.setCanceled(true);
            return;
          }
        }
      }

      IFileStore fileStore;
      try {
        fileStore = EFS.getStore(localFile.toURI());
      }
      catch(CoreException ex) {
        EditorsPlugin.log(ex.getStatus());
        String title = "Problems During Save As...";
        String msg = "Save could not be completed. " + ex.getMessage();
        MessageDialog.openError(shell, title, msg);
        return;
      }

      IFile file = getWorkspaceFile(fileStore);
      if(file != null)
        newInput = new FileEditorInput(file);
      else {
        IURIEditorInput uriInput = new FileStoreEditorInput(fileStore);
        java.net.URI uri = uriInput.getURI();
        IFile linkedFile = ExtLinkedFileHelper.obtainLink(uri, false);

        newInput = new FileEditorInput(linkedFile);
      }

      if(provider == null) {
        // editor has been closed while the dialog was open
        return;
      }

      boolean success = false;
      try {

        provider.aboutToChange(newInput);
        provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
        success = true;

      }
      catch(CoreException x) {
        final IStatus status = x.getStatus();
        if(status == null || status.getSeverity() != IStatus.CANCEL) {
          String title = "Problems During Save As...";
          String msg = "Save could not be completed. " + x.getMessage();
          MessageDialog.openError(shell, title, msg);
        }
      }
      finally {
        provider.changed(newInput);
        if(success)
          setInput(newInput);
        // the linked file must be removed (esp. if it is an "untitled" link).
        ExtLinkedFileHelper.unlinkInput(((IFileEditorInput) input));
        // remember last saveAs location
View Full Code Here

    private void checkForEssentialChanges()
    {
        try
        {
            IDocumentProvider dp = getDocumentProvider();
            IDocument doc = dp.getDocument( getEditorInput() );
            String bufferedCopy = doc.get();
            File file = new File( ( (FileStoreEditorInput) getEditorInput() ).getURI() );

            SettingsXpp3Reader settingsReader = new SettingsXpp3Reader();
View Full Code Here

            else
              textEditor = (ITextEditor) editorPart.getAdapter(ITextEditor.class);

            if (textEditor != null) {
              IEditorInput input = editorPart.getEditorInput();
              IDocumentProvider provider = textEditor.getDocumentProvider();
              try {
                provider.connect(input);
              } catch (CoreException e) {
                e.printStackTrace();
                // unable to link
                //DebugUIPlugin.log(e);
                return;
              }
              IDocument document = provider.getDocument(input);
              int offset = -1, lenght = -1;

              try {
                IRegion region= document.getLineInformation(this.line - 1);
                offset = region.getOffset();
                lenght = region.getLength();
              } catch (BadLocationException e) {
                // unable to link
                //DebugUIPlugin.log(e);
                e.printStackTrace();
              }
              provider.disconnect(input);
              if (offset >= 0 && lenght >=0) {
                textEditor.selectAndReveal(offset, lenght);
              }
            }
View Full Code Here

TOP

Related Classes of org.eclipse.ui.texteditor.IDocumentProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.