How can I create a custom project layout based on another eclipse plugin? - eclipse

My ultimate goal is to create an eclipse plugin that sets up a PDT project, but with some added builders (and custom build scripts) as well as a specific folder layout (and different folders should be treated as source and some as regular folders).
I've looked at / followed eclipse plugin development tutorials, and ok. I get the gist of creating a wizard that creates a file, but I'm having trouble trying to figure out how to create a project, and more importantly, make that project associated with the PDT (PHP Development Tools) feature.
Answer:
I did stumble upon a solution myself before the answer was given, but it's quite similar.
First, WizardNewProjectCreationPage was used as the first page of my wizard.
Second, on performFinish() I ran the following code:
IProgressMonitor m = new NullProgressMonitor();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(_pageOne.getProjectName());
if (!project.exists())
{
IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName());
URI projectLocation = _pageOne.getLocationURI();
// desc.setLocationURI(projectLocation);
String[] natures = desc.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = PHPNature.ID;
desc.setNatureIds(newNatures);
project.create(desc, m);
project.open(m);
}

how to create a project
Take a look at BasicNewProjectResourceWizard.createNewProject() method.
make that project associated with the PDT (PHP Development Tools) feature
You need to add "org.eclipse.php.core.PHPNature" to the project (that's what Add PHP Support... action does). Use IProjectDescription.setNatureIds().

Related

issue changing properties on project items using multi-project vstemplate with IWizard

I am creating a VSIX extension that generates a multi-project solution to be distributed. I would like to do several things to individual items I include in each projects vstemplate but think I may be taking the wrong approach. I have created a IWizard and am able to debug the solution. I added a custom item type to the project items in vstemplate in order to identify which ones I want to flag. I am then doing the following to change a ProjectItems Build Action from Content to Compile. I am still learning Visual Studio Extensability and have very limited experience using the objects so I apologize if the below is horrendous!
public void ProjectFinishedGenerating(Project project)
{
var myproject = (VSProject)project.Object;
foreach (ProjectItem pi in myproject.ProjectItems)
{
var myBuildAction = pi.Properties.Item("ItemType").Value;
if myBuildAction == "CompileContent")
pi.Properties.Item("ItemType").Value = "Compile";
}
}
This is my item in vstemplate
<VSTemplate Version="3.0.0" Type="Project" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
<ProjectItem TargetFileName="MyFolder\$ext_safeprojectname$\$ext_safeprojectname$_CodeFile.cs" ReplaceParameters="true" ItemType="CompileContent">CodeFile.cs</ProjectItem>

How to open my TopComponent in "explorer" mode?

I am doing netBeans platform application.when I creating top component I give it as "explorer" mode to start.But in default it start in "editor" mode.Here the annotations which top component automatically generated.
#ConvertAsProperties(
dtd = "-//MyApplication.windows//MyViewer//EN",
autostore = false)
#TopComponent.Description(
preferredID = "MyViewerTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
#TopComponent.Registration(mode = "explorer", openAtStartup = true)
#ActionID(category = "Window", id = "MyApplication.windows.MyViewerTopComponent")
#ActionReference(path = "Menu/Window" /*, position = 333 */)
#TopComponent.OpenActionRegistration(
displayName = "#CTL_MyViewerAction",
preferredID = "MyViewerTopComponent")
#Messages(
{
"CTL_MyViewerAction=MyViewer",
"CTL_MyViewerTopComponent=MyViewer Window",
"HINT_MyViewerTopComponent=This is a MyViewer window"
})
Please give me any suggestion for this problem.
I just had this problem. I unchecked a module dependency called RCP Platform and the windows would only open in editor position. I was trying to find the minimum modules needed to run my program.
You can see which modules are used by right clicking the project node and choosing properties. Look at libraries and expand the Platform node. Make sure RCP Platform is checked. If it gives an error, just click resolve. Make sure you do a clean and build afterwords.
There is one easier thing you should check first. When you run a NB platform program, it opens windows in the last used position. If you moved a window, it will reopen where you last moved it to. You have to do a clean and build to reset this.

Can't save state in windows 8 [ Error The type or namespace name 'Common'

Can't save state in windows 8
{
Error The type or namespace name 'Common' ...does not exist in the namespace 'ProjectName' (are you missing an assembly reference?)
}
Everything below is the default code in my App.Xaml.cs file the only line I added was
ProjectNameSpace.Common.SuspensionManager.RegisterFrame(rootFrame, "appframe");
which is from the windows 8 tutorial here and I have followed part 1 before attempting this http://msdn.microsoft.com/en-us/library/windows/apps/hh986968.aspx. I have it working in another project that has the same references and using statements. There is only one namespace in the project and I even Rebuilt/Cleaned. Does anybody have any extra information?
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
ProjectNameSpace.Common.SuspensionManager.RegisterFrame(rootFrame, "appframe");
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
}
Window.Current.Content = rootFrame;
EDIT:
The problem was that I needed to add a basic page in my blank template. This auto generates some classes needed to do basic functionality. Below is a screenshot of the minimum items that the common folder needs to contain.
Do you have the Common folder present in your project? This folder is usually included in the Visual Studio 2012 App project templates (except the Blank App template) which contains a bunch of classes with boilerplate code for layout, styles and other functionality.
If you created your project with a Blank App template, you may not have this. To get it included, create a new Basic Page (Right-click on your Project > Add > New Item > (Visual C#)* > Basic Page), and Visual Studio will ask if you would like to create these files.
*I'm not sure what this is for VB .NET or WinJS, but I assume it would be the same structure.

Finding currently open files in Eclipse plugin

I'm trying to create a plugin that annotates eclipse java projects based on external output. Currently, I'm traversing all of the open projects based on this tutorial: http://www.vogella.de/articles/EclipseJDT/article.html However, I'm looking for a way to get a full list of only the files that are currently open in the java editor. Is there a way or command for me to get that?
//get all active editor references,check if reference is of type java editor
IEditorReference[] ref = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.getEditorReferences();
List<IEditorReference> javaEditors = new ArrayList<IEditorReference>();
for (IEditorReference reference : ref) {
if ("org.eclipse.jdt.ui.CompilationUnitEditor".equals(reference.getId())){
javaEditors.add(reference);
}
}

eclipse jdt automatic method stub generation

i am creating java source files using eclipse JDT & AST. There are cases that generated source files are implementing or extending something.
is it possible to add method stubs automatically before actually creating them? like invoking this "Add unimplemented methods" quick fix via JDT.
i know i can add them myself via those API's, but i want to tweak.
i found solution after a couple of hours; code is roughly like this. there are also many good code manipulation classes in this package "org.eclipse.jdt.internal.corext.codemanipulation.*"
ICompilationUnit createCompilationUnit = getItSomeHow();
RefactoringASTParser parser1 = new RefactoringASTParser(AST.JLS3);
CompilationUnit unit = parser1.parse(createCompilationUnit, true);
AbstractTypeDeclaration declaration = (AbstractTypeDeclaration) ASTNodes.getParent(
NodeFinder.perform(unit, createCompilationUnit.getTypes()[0].getNameRange()),
AbstractTypeDeclaration.class);
ITypeBinding binding = declaration.resolveBinding();
IMethodBinding[] overridableMethods = StubUtility2.getOverridableMethods(unit.getAST(), binding, false);
AddUnimplementedMethodsOperation op = new AddUnimplementedMethodsOperation(unit, binding,
null/* overridableMethods */, -1, true, true, true);