public void testGetContentType() throws IOException, CoreException {
   IStructuredModel model = getTestModel();
   try {
     String ct = model.getContentTypeIdentifier();
     assertTrue(
         "model has wrong content type:" + ct + " != " + ContentTypeIdForXML.ContentTypeID_XML,
         ct.equals(ContentTypeIdForXML.ContentTypeID_XML));
   } finally {
     if (model != null) {
       model.releaseFromEdit();
     }
   }
 }
예제 #2
0
    /**
     * Returns the content type of document
     *
     * @param document - assumes document is not null
     * @return String content type of given document
     */
    private String getContentType() {
      String type = null;

      IModelManager mgr = StructuredModelManager.getModelManager();
      IStructuredModel model = null;
      try {
        model = mgr.getExistingModelForRead(document);
        if (model != null) {
          type = model.getContentTypeIdentifier();
        }
      } finally {
        if (model != null) {
          model.releaseFromRead();
        }
      }
      return type;
    }
예제 #3
0
 private void tryConnectTo(IWorkbenchPart part) {
   if (part instanceof IEditorPart) {
     IStructuredModel model = (IStructuredModel) part.getAdapter(IStructuredModel.class);
     if (part != swtXmlEditorPart
         && model != null
         && SwtXmlModelHandler.associatedContentTypeID.equals(model.getContentTypeIdentifier())) {
       connectTo(part);
     } else if (((IEditorPart) part).getEditorInput() instanceof FileEditorInput) {
       if (((FileEditorInput) (((IEditorPart) part).getEditorInput()))
           .getFile()
           .toString()
           .endsWith(".properties")) {
         propertiesFileEditorPart = (IEditorPart) part;
         propertiesFileEditorPart.addPropertyListener(updatePreviewOnSavePropertiesFile);
       }
     }
   }
 }