Package org.eclipse.core.resources

Examples of org.eclipse.core.resources.IFile


          fMonitor.beginTask("Validating resources", IProgressMonitor.UNKNOWN);
          fResource.accept(new IResourceVisitor() {
           
            public boolean visit(IResource resource) throws CoreException {
              if (resource instanceof IFile) {
                IFile file = (IFile) resource;
                if (WGADesignResourceValidator.shouldBeValidated(file)) {
                  try {
                    fMonitor.setTaskName("Validating '" + file.getLocation().toString() + "'.");
                    WGADesignResourceValidator.validate(file);
                    fMonitor.worked(1);                     
                  } catch (Exception e) { 
                  }
                }
View Full Code Here


  @Override
  public void init(IEditorSite site, IEditorInput input)
      throws PartInitException {
    super.init(site, input);
    IFile syncInfoFile = ((IFileEditorInput)input).getFile();
    try {
        if (getSite().getShell().isVisible()) {
              // check if design is compatible
              if (syncInfoFile != null) {
                  if (!WGADesignStructureHelper.isWGAVersionComplianceCompatible(syncInfoFile)) {
                      MessageDialog.openWarning(getSite().getShell(), "Incompatible design version", "This design uses an incompatible compliance level. Please upgrade to the latest WDS version to work on this design with full feature support.");       
                  }
              }             
          }
       
      _model =new WGADesignConfigurationModelWrapper(syncInfoFile);
      _model.addListener(this);
      _persistedVersionComliance = _model.getVersionCompliance();
      _persistedDesignEncoding = _model.getDesignEncoding();
      setPartName("Design (" + syncInfoFile.getParent().getName() + ")");
      try {
        // model might have create default files, so refresh project
        ((IFileEditorInput)input).getFile().getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
      } catch (CoreException e) {
        Plugin.getDefault().logError("Unable to refresh project.", e);
View Full Code Here

  }

  public void resourceChanged(IResourceChangeEvent event) {
    try {
     
      final IFile fSyncInfo = ((IFileEditorInput)getEditorInput()).getFile();
      final IFile fCsConfig = new WGADesignStructureHelper(fSyncInfo).getCsConfig();
      IFile schema = null;
      if (fSyncInfo != null && fSyncInfo.exists()) {
          schema = fSyncInfo.getParent().getFolder(new Path("files").append("system")).getFile("schema.xml");
      }
      final IFile fSchema = schema;
      event.getDelta().accept(new IResourceDeltaVisitor() {

        public boolean visit(IResourceDelta delta) throws CoreException {
          // check if editor files (syninfo.xml/csconfig.xml) has been changed external for e.g. by an plugin export
          // in this case we can refresh the editor
View Full Code Here

    if (_compliance.toWGAVersion().isAtLeast(5, 0)){
      IContainer container = (IContainer) resource;
      if(!container.getName().startsWith(".")){
        if (WGADesignStructureHelper.isMediaKeyContainer(container)) {
          IFile syncInfo = WGADesignStructureHelper.determineSyncInfo(container);       
          WGADesignConfigurationModelWrapper conf;
          try {
            conf = new WGADesignConfigurationModelWrapper(syncInfo);
            List<String> mediaKeyStrings = new ArrayList<String>();
            mediaKeyStrings.addAll(WGADesignStructureHelper.DEFAULT_MEDIA_KEYS);
View Full Code Here

        try {
          delta.accept(new IResourceDeltaVisitor() {

            public boolean visit(IResourceDelta delta) throws CoreException {
              if (delta.getResource() instanceof IFile) {
                IFile file = (IFile) delta.getResource();
                if (file != null && file.getLocation() != null && file.getLocation().getFileExtension() != null &&
                    file.getLocation().getFileExtension().equals("tml")) {
                  // a tml file changed
                  if (delta.getKind() == IResourceDelta.REMOVED) {
                    // tml file removed
                    IFile metadataFile = WGADesignStructureHelper.getMetadataFile(file);
                    if (metadataFile.exists()) {
                      _metaDataFilesToRemove.add(metadataFile);
                    }
                   
                  } else if (delta.getKind() == IResourceDelta.ADDED && delta.getMovedFromPath() != null) {
                    // tml file moved from another location
                    IFile orgFile = ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getMovedFromPath());
                    IFile metadataFileFrom = WGADesignStructureHelper.getMetadataFile(orgFile);
                    if (metadataFileFrom.exists()) {
                      IFile metadataFileTo = WGADesignStructureHelper.getMetadataFile(file);
                      _metaDataFilesToMove.put(metadataFileFrom, metadataFileTo);
                    }
                  }
                }                  
              }
              return true;
            }
           
          });
        } catch (CoreException e) {
          Plugin.getDefault().logError("Unable to execute TMLMetadataMaintenance." , e);
        }
      }
    } else if (event.getType() == IResourceChangeEvent.PRE_BUILD) {
      Iterator<IFile> moveFromFiles = _metaDataFilesToMove.keySet().iterator();
      while (moveFromFiles.hasNext()) {
        IFile moveFrom = moveFromFiles.next();
        IFile moveToFile = _metaDataFilesToMove.get(moveFrom);
        try {
          if (moveToFile.getParent() instanceof IFolder) {
            IFolder folder = (IFolder) moveToFile.getParent();
            if (!folder.exists()) {
              folder.create(true,true, new NullProgressMonitor());
            }
            moveFrom.move(moveToFile.getFullPath(), true, new NullProgressMonitor());
          }         
        } catch (CoreException e) {
          Plugin.getDefault().logError("Unable to execute TMLMetadataMaintenance." , e);
        }           
      }
View Full Code Here

  @Override
  protected IDocument createDocument(Object element) throws CoreException {
    // determine design encoding
    if (element instanceof IFileEditorInput) {
      IFile file = ((IFileEditorInput) element).getFile();
      if (file != null) {
        if (file.getFileExtension().equalsIgnoreCase(".properties")) {
          _encoding = "ISO-8859-1";
        } else if (file.getName().toLowerCase().endsWith(".metadata.xml")) {
          _encoding = "UTF-8";
        } else {
          _encoding = new WGADesignStructureHelper(((IFileEditorInput) element).getFile()).determineDesignEncoding();         
        }
        return super.createDocument(element)
View Full Code Here

      IFileEditorInput input= (IFileEditorInput) element;
      String encoding= null;

      FileInfo info= (FileInfo) getElementInfo(element);
      IFile file= input.getFile();
      encoding= retrieveCharsetForNewFile(file, document, info);
     
      /*
      if (info != null && info.fBOM == IContentDescription.BOM_UTF_16LE && CHARSET_UTF_16.equals(encoding))
        encoding= CHARSET_UTF_16LE;*/

      Charset charset;
      try {
        charset= Charset.forName(encoding);
      } catch (UnsupportedCharsetException ex) {
        String message= "Unsupported encoding '" + encoding + "'.";
        IStatus s= new Status(IStatus.ERROR, Plugin.PLUGIN_ID, IStatus.OK, message, ex);
        throw new CoreException(s);
      } catch (IllegalCharsetNameException ex) {
        String message= "Unsupported encoding '" + encoding + "'.";
        IStatus s= new Status(IStatus.ERROR, Plugin.PLUGIN_ID, IStatus.OK, message, ex);
        throw new CoreException(s);
      }

      CharsetEncoder encoder= charset.newEncoder();
      encoder.onMalformedInput(CodingErrorAction.REPLACE);
      encoder.onUnmappableCharacter(CodingErrorAction.REPORT);

      InputStream stream;

      try {
        byte[] bytes;
        ByteBuffer byteBuffer= encoder.encode(CharBuffer.wrap(document.get()));
        if (byteBuffer.hasArray())
          bytes= byteBuffer.array();
        else {
          bytes= new byte[byteBuffer.limit()];
          byteBuffer.get(bytes);
        }
        stream= new ByteArrayInputStream(bytes, 0, byteBuffer.limit());
      } catch (CharacterCodingException ex) {
        Assert.isTrue(ex instanceof UnmappableCharacterException);
        String message= "Charset mapping failed.";
        IStatus s= new Status(IStatus.ERROR, Plugin.PLUGIN_ID, EditorsUI.CHARSET_MAPPING_FAILED, message, null);
        throw new CoreException(s);
      }

      if (file.exists()) {

        if (info != null && !overwrite)
          checkSynchronizationState(info.fModificationStamp, file);

        // inform about the upcoming content change
        fireElementStateChanging(element);
        try {
          file.setContents(stream, overwrite, true, monitor);
        } catch (CoreException x) {
          // inform about failure
          fireElementStateChangeFailed(element);
          throw x;
        } catch (RuntimeException x) {
          // inform about failure
          fireElementStateChangeFailed(element);
          throw x;
        }

        // If here, the editor state will be flipped to "not dirty".
        // Thus, the state changing flag will be reset.

        if (info != null) {

          ResourceMarkerAnnotationModel model= (ResourceMarkerAnnotationModel) info.fModel;
          if (model != null)
            model.updateMarkers(info.fDocument);

          info.fModificationStamp= computeModificationStamp(file);
        }

      } else {
        try {
          monitor.beginTask("Saving document", 2000);
          ContainerCreator creator = new ContainerCreator(file.getWorkspace(), file.getParent().getFullPath());
          creator.createContainer(new SubProgressMonitor(monitor, 1000));
          file.create(stream, false, new SubProgressMonitor(monitor, 1000));
        }
        finally {
          monitor.done();
        }
      }
View Full Code Here

        _detailSection.setVisible(false);
    }

    protected void handleBrowserLayout(Text textControl) {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(Display.getCurrent().getActiveShell(), new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
        IFile syncInfo = ((IFileEditorInput)getEditorInput()).getFile();
        WGADesignStructureHelper helper = new WGADesignStructureHelper(syncInfo);       
        dialog.setInput(helper.getTmlRoot());
        dialog.setAllowMultiple(false);
        dialog.setHelpAvailable(false);
        dialog.setTitle("TML layout selection");
        dialog.setValidator(new ISelectionStatusValidator() {
           
            public IStatus validate(Object[] selection) {
                if (selection != null && selection.length == 1) {
                    if (selection[0] instanceof IFile) {
                        return new Status(Status.OK, Plugin.PLUGIN_ID, ((IFile)selection[0]).getFullPath().toString());
                    }
                }
                return new Status(Status.ERROR, Plugin.PLUGIN_ID, "Please select a tml layout file.");
            }
        });
        // first try to find reference in medium "html" - otherwise check all available mediaKeys in design
        IFile preSelection = helper.findReferencedTMLModule(textControl.getText(), "html");
        if (preSelection == null) {
            for (String mediaKey : helper.getMediaKeys()) {
                preSelection = helper.findReferencedTMLModule(textControl.getText(), mediaKey);
                if (preSelection != null) {
                    break;
                }
            }
        }
        if (preSelection != null) {
            dialog.setInitialSelection(preSelection);
        }
        int result = dialog.open();
        if (result == Dialog.OK) {
            IFile selection = (IFile) dialog.getFirstResult();
            textControl.setText(helper.computeTMLReference(selection));
        }
    }
View Full Code Here

              }
          }
               
        if (designContainer != null && WGADesignStructureHelper.isDesignFolder(designContainer)) {
          WGADesignStructureHelper helper = new WGADesignStructureHelper(designContainer);
          IFile file = helper.findReferencedTMLModule(_warning.getResource(), _warning.getMedium());
          if (file != null && file.exists()) {
            IEditorPart editor = WorkbenchUtils.openEditor(WGADesignerPlugin.getDefault().getWorkbench(), file);
            if (editor instanceof ITextEditor) {
              ITextEditor textEditor = (ITextEditor) editor;
              int offset = 0;
              if (_warning.getLine() != -1) {
View Full Code Here

        } else {
          return WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_DESIGN);
        }
      } else if (container.isAccessible()) {
        // we might have to resolve dirlinks
        IFile dirlink = container.getFile(new Path("dirlink.xml"));
        if (dirlink.exists()) {
          File target = WGUtils.resolveDirLink(dirlink.getParent().getLocation().toFile());
          if (WGADesignStructureHelper.isDesignFolder(target)) {
            IContainer targets[] = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation(new Path(target.getAbsolutePath()));
            if (targets != null && targets.length >= 1) {
              WGADesignStructureHelper helper = new WGADesignStructureHelper(targets[0]);
              if (helper.hasPluginConfig()) {
View Full Code Here

TOP

Related Classes of org.eclipse.core.resources.IFile

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.