/** * Forces a version into plugin/fragment .xml */ private void forceVersion(final String targetVersion, IModel modelBase, IProgressMonitor monitor) { IFile file = (IFile) modelBase.getUnderlyingResource(); if (file == null) return; PDEModelUtility.modifyModel(new ModelModification(file) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { if (model instanceof IBundlePluginModelBase) { modifyVersion(((IBundlePluginModelBase) model).getBundleModel(), targetVersion); } else if (model instanceof IPluginModelBase) { modifyVersion((IPluginModelBase) model, targetVersion); } } }, monitor); }
public boolean equals(Object obj) { if (obj instanceof ModelChange) { ModelChange change = (ModelChange)obj; IProject project = change.model.getUnderlyingResource().getProject(); int type = change.type; return model.getUnderlyingResource().getProject().equals(project) && this.type == type; } return false; } }
@Override public boolean equals(Object obj) { if (obj instanceof ModelChange) { ModelChange change = (ModelChange) obj; IProject project = change.model.getUnderlyingResource().getProject(); int type = change.type; return model.getUnderlyingResource().getProject().equals(project) && this.type == type; } return false; } }
public ProductExportAction(PDEFormEditor editor) { IResource resource = null; if (editor != null) { IModel model = (IModel) editor.getAggregateModel(); resource = model == null ? null : model.getUnderlyingResource(); } fSelection = resource != null ? new StructuredSelection(resource) : new StructuredSelection(); fProject = editor.getCommonProject(); }
protected void loadModel(IModel model, boolean reload) { IFile file = (IFile) model.getUnderlyingResource(); InputStream stream = null; try { stream = new BufferedInputStream(file.getContents(true)); if (reload) model.reload(stream, false); else model.load(stream, false); } catch (CoreException e) { PDECore.logException(e); } finally { try { if (stream != null) stream.close(); } catch (IOException e) { PDECore.log(e); } } } }
@Override protected void flushModel(IDocument doc) { // if model is dirty, flush its content into // the document so that the source editor will // pick up the changes. if (!(getModel() instanceof IEditable)) return; IEditable editableModel = (IEditable) getModel(); if (editableModel.isDirty() == false) return; try (StringWriter swriter = new StringWriter(); PrintWriter writer = new PrintWriter(swriter)) { editableModel.save(writer); writer.flush(); String content = swriter.toString(); content = AbstractModel.fixLineDelimiter(content, (IFile) ((IModel) getModel()).getUnderlyingResource()); doc.set(content); } catch (IOException e) { PDEPlugin.logException(e); } }
protected void loadModel(IModel model, boolean reload) { IFile file = (IFile) model.getUnderlyingResource(); InputStream stream = null; try { stream = new BufferedInputStream(file.getContents(true)); if (reload) model.reload(stream, false); else model.load(stream, false); } catch (CoreException e) { PDECore.logException(e); } finally { try { if (stream != null) stream.close(); } catch (IOException e) { PDECore.log(e); } } }
@Override protected void flushModel(IDocument doc) { if (!(getModel() instanceof IEditable)) return; IEditable editableModel = (IEditable) getModel(); if (editableModel.isDirty() == false) return; try (StringWriter swriter = new StringWriter(); PrintWriter writer = new PrintWriter(swriter)) { editableModel.save(writer); writer.flush(); String content = swriter.toString(); content = AbstractModel.fixLineDelimiter(content, (IFile) ((IModel) getModel()).getUnderlyingResource()); doc.set(content); } catch (IOException e) { PDEPlugin.logException(e); } }
@Override protected void flushModel(IDocument doc) { // if model is dirty, flush its content into // the document so that the source editor will // pick up the changes. if (!(getModel() instanceof IEditable)) return; IEditable editableModel = (IEditable) getModel(); if (editableModel.isEditable() == false) return; if (editableModel.isDirty() == false) return; try (StringWriter swriter = new StringWriter(); PrintWriter writer = new PrintWriter(swriter)) { editableModel.save(writer); writer.flush(); String content = swriter.toString(); content = AbstractModel.fixLineDelimiter(content, (IFile) ((IModel) getModel()).getUnderlyingResource()); doc.set(content); } catch (IOException e) { PDEPlugin.logException(e); } }
@Override protected void flushModel(IDocument doc) { // if model is dirty, flush its content into // the document so that the source editor will // pick up the changes. if (!(getModel() instanceof IEditable)) return; IEditable editableModel = (IEditable) getModel(); if (editableModel.isEditable() == false) return; if (editableModel.isDirty() == false) return; try (StringWriter swriter = new StringWriter(); PrintWriter writer = new PrintWriter(swriter)) { editableModel.save(writer); writer.flush(); String content = swriter.toString(); content = AbstractModel.fixLineDelimiter(content, (IFile) ((IModel) getModel()).getUnderlyingResource()); doc.set(content); } catch (IOException e) { PDEPlugin.logException(e); } }
public static String generateAttributeValue(ISchemaAttribute attribute, IBaseModel baseModel, String defaultValue) { if (baseModel instanceof IModel) { IResource resource = ((IModel) baseModel).getUnderlyingResource(); if (resource != null) { int counter = 1; if (attribute.getParent() instanceof ISchemaElement) { ISchemaElement sElement = (ISchemaElement) attribute.getParent(); if (sElement instanceof ISchemaRootElement) { // The parent element is either a extension or an // extension-point // Do not auto-generate attribute values for those // elements return defaultValue; } // Generate a unique number for IDs counter = XMLUtil.getCounterValue(sElement); } return generateAttributeValue(resource.getProject(), counter, attribute); } } return defaultValue; }
/** * Constructs a link with the given model, parent and file. * * @param model * The model associated with the new link. * @param parent * The parent TocObject of the new link. * @param file * The TOC file to link to. */ public TocLink(TocModel model, IFile file) { super(model, ELEMENT_LINK); IPath path = file.getFullPath(); if (file.getProject().equals( getSharedModel().getUnderlyingResource().getProject())) { // If // the // file // is // from // the // same // project, // remove the project name segment setFieldTocPath(path.removeFirstSegments(1).toString()); //$NON-NLS-1$ } else { // If the file is from another project, add ".." // to traverse outside this model's project setFieldTocPath(".." + path.toString()); //$NON-NLS-1$ } }
/** * Constructs a link with the given model, parent and file. * * @param model * The model associated with the new link. * @param file * The TOC file to link to. */ public TocLink(TocModel model, IFile file) { super(model, ELEMENT_LINK); IPath path = file.getFullPath(); if (file.getProject().equals( getSharedModel().getUnderlyingResource().getProject())) { // If // the // file // is // from // the // same // project, // remove the project name segment setFieldTocPath(path.removeFirstSegments(1).toString()); //$NON-NLS-1$ } else { // If the file is from another project, add ".." // to traverse outside this model's project setFieldTocPath(".." + path.toString()); //$NON-NLS-1$ } }
private void configureSourceBuildEntry(IBuildModel bmodel, String oldPath, String newPath) throws CoreException { IBuild build = bmodel.getBuild(); IBuildEntry entry = build.getEntry(PROPERTY_SOURCE_PREFIX + (oldPath != null ? oldPath : newPath)); try { if (newPath != null) { if (entry == null) { IProject project = ((IModel) getPage().getModel()).getUnderlyingResource().getProject(); IJavaProject jproject = JavaCore.create(project); ArrayList<String> tokens = new ArrayList<>(); IClasspathEntry[] entries = jproject.getRawClasspath(); for (IClasspathEntry cpe : entries) if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) tokens.add(cpe.getPath().removeFirstSegments(1).addTrailingSeparator().toString()); if (tokens.isEmpty()) return; entry = bmodel.getFactory().createEntry(PROPERTY_SOURCE_PREFIX + newPath); for (int i = 0; i < tokens.size(); i++) entry.addToken(tokens.get(i)); build.add(entry); } else entry.setName(PROPERTY_SOURCE_PREFIX + newPath); } else if (entry != null) build.remove(entry); } catch (JavaModelException e) { } }
/** * Constructs a topic with the given model, parent and file. * * @param model * The model associated with the new link. * @param file * The page to link to. */ public TocTopic(TocModel model, IFile file) { super(model, ELEMENT_TOPIC); IPath path = file.getFullPath(); if (file.getProject().equals( getSharedModel().getUnderlyingResource().getProject())) { // If // the // file // is // from // the // same // project, // remove the project name segment setFieldRef(path.removeFirstSegments(1).toString()); //$NON-NLS-1$ } else { // If the file is from another project, add ".." // to traverse outside this model's project setFieldRef(".." + path.toString()); //$NON-NLS-1$ } }
protected boolean isCustomBuild(IModel model) throws CoreException { IBuildModel buildModel = null; IFile buildFile = model.getUnderlyingResource().getProject().getFile("build.properties"); //$NON-NLS-1$ if (buildFile.exists()) { buildModel = new WorkspaceBuildModel(buildFile); buildModel.load(); } if (buildModel != null) { IBuild build = buildModel.getBuild(); if (build == null) return false; IBuildEntry entry = build.getEntry("custom"); //$NON-NLS-1$ if (entry != null) { String[] tokens = entry.getTokens(); for (int i = 0; i < tokens.length; i++) { if (tokens[i].equals("true")) //$NON-NLS-1$ return true; } } } return false; }
protected boolean isCustomBuild(IModel model) throws CoreException { IBuildModel buildModel = null; IFile buildFile = model.getUnderlyingResource().getProject().getFile("build.properties"); //$NON-NLS-1$ if (buildFile.exists()) { buildModel = new WorkspaceBuildModel(buildFile); buildModel.load(); } if (buildModel != null) { IBuild build = buildModel.getBuild(); if (build == null) return false; IBuildEntry entry = build.getEntry("custom"); //$NON-NLS-1$ if (entry != null) { String[] tokens = entry.getTokens(); for (int i = 0; i < tokens.length; i++) { if (tokens[i].equals("true")) //$NON-NLS-1$ return true; } } } return false; }
protected boolean isCustomBuild(IModel model) throws CoreException { IBuildModel buildModel = null; IFile buildFile = PDEProject.getBuildProperties(model.getUnderlyingResource().getProject()); if (buildFile.exists()) { buildModel = new WorkspaceBuildModel(buildFile); buildModel.load(); } if (buildModel != null) { IBuild build = buildModel.getBuild(); if (build == null) return false; IBuildEntry entry = build.getEntry("custom"); //$NON-NLS-1$ if (entry != null) { String[] tokens = entry.getTokens(); for (int i = 0; i < tokens.length; i++) { if (tokens[i].equals("true")) //$NON-NLS-1$ return true; } } } return false; }
protected void handleBuild(ISiteFeature[] sFeatures) { if (sFeatures.length == 0) { return; } IFeatureModel[] models = getFeatureModels(sFeatures); if (models.length == 0) { return; } ensureContentSaved(); IModel model = (IModel) getAggregateModel(); if (model == null) { return; } ISiteModel buildSiteModel = new WorkspaceSiteModel((IFile) model.getUnderlyingResource()); try { buildSiteModel.load(); } catch (CoreException e) { PDEPlugin.logException(e); return; } Job job = new SiteBuildOperation(models, buildSiteModel, PDEUIMessages.BuildSiteJob_name); job.setUser(true); job.schedule(); }
@Override protected void fillContextMenu(IMenuManager manager) { IStructuredSelection selection = fImportViewer.getStructuredSelection(); manager.add(fAddAction); if (!selection.isEmpty()) { manager.add(fOpenAction); } manager.add(new Separator()); getPage().contextMenuAboutToShow(manager); if (!selection.isEmpty()) manager.add(fRemoveAction); getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager); manager.add(new Separator()); PluginSearchActionGroup actionGroup = new PluginSearchActionGroup(); actionGroup.setContext(new ActionContext(selection)); actionGroup.fillContextMenu(manager); if (((IModel) getPage().getModel()).getUnderlyingResource() != null) { manager.add(new UnusedDependenciesAction((IPluginModelBase) getPage().getModel(), false)); } if (fPropertiesAction != null && !fImportViewer.getStructuredSelection().isEmpty()) { manager.add(new Separator()); manager.add(fPropertiesAction); } manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); }