I need to invoke eclipse importwizard from the eclipse plugin project programmatically. i follow the example from , seems not work
https://resheim.net/2010/07/invoking-eclipse-wizard.html
then in my code , it shows wizards array is empty, do i need to register importwizard ? and how?
IWizardDescriptor[] wizards= PlatformUI.getWorkbench().getImportWizardRegistry().getPrimaryWizards();
The import dialog doesn't use 'primary' wizards. You need to know the id of the wizard you want to use and call the wizard registry findWizard method.
The Import Projects wizard id is org.eclipse.ui.wizards.import.ExternalProject so the code would look like:
String id = "org.eclipse.ui.wizards.import.ExternalProject"
IWizardDescriptor descriptor = PlatformUI.getWorkbench().getImportWizardRegistry().findWizard(id);
IWizard wizard = descriptor.createWizard();
WizardDialog wd = new WizardDialog(display.getActiveShell(), wizard);
wd.setTitle(wizard.getWindowTitle());
wd.open();
private void openProject(String projectfolder) throws CoreException {
//TODO: check if project is already created and open, if yes do nothing or just refresh
IProjectDescription description = null;
IProject project = null;
description = ResourcesPlugin.getWorkspace().loadProjectDescription(
new Path(new File(projectfolder).getAbsolutePath()
+ "/.project"));
project = ResourcesPlugin.getWorkspace().getRoot()
.getProject(description.getName());
project.create(description, null);
project.open(null);
}
Related
I develop Eclipse plugin.
I want to show highlighted java code in my ViewPart.
I try to use integrated Eclipse classes (SourceViewer with JavaSourceViewerConfiguration). Here is my code:
#Override
public void createPartControl(Composite parent) {
String code = "int a = 5;\n" +
"//not-working comment\n" +
"/* not working single line comment */ \n" +
"not-working multi-line comment\n";
JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools();
SourceViewer sv = new SourceViewer(parent, null, SWT.NONE);
JavaSourceViewerConfiguration config =
new JavaSourceViewerConfiguration(
tools.getColorManager(),
JavaPlugin.getDefault().getCombinedPreferenceStore(),
null,
null
);
sv.configure(config);
Document d = new Document();
d.set(code);
sv.setDocument(d);
}
It successfully highlights all code, but doesn't highlight any comments. What I do wrong?
UPD:
I'm not sure if it is important, but there is list of plugins/packages marked in manifest file as required:
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jdt.ui,
org.eclipse.ui.workbench.texteditor,
org.eclipse.jface.text
Import-Package: org.eclipse.jface.text.source
Looks like you need to specify the partitioning parameter (last argument of the JavaSourceViewerConfiguration constructor) as IJavaPartitions.JAVA_PARTITIONING.
You have to define a partitioner for the document:
IDocumentPartitioner partitioner = new FastPartitioner(new FastJavaPartitionScanner(), new String[] {
IJavaPartitions.JAVA_DOC,
IJavaPartitions.JAVA_MULTI_LINE_COMMENT,
IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
IJavaPartitions.JAVA_STRING, IJavaPartitions.JAVA_CHARACTER });
and then connect both of them:
d.setDocumentPartitioner(partitioner);
partitioner.connect(d);
I need help with update workflowTask, add file to existing workflow.
My code is:
List<NodeRef> addNodes = new ArrayList<NodeRef>();
addNodes.add(addNodeRef);
Map<QName, List<NodeRef>> nodesAdd = new HashMap<QName, List<NodeRef>>();
nodesAdd.put(WorkflowModel.ASSOC_PACKAGE, addNodes);
workflowService.updateTask(currentTask.getId(), null, nodesAdd, null); //nullpointer
currentTask is not null, is actual task in workflow, where I want add item
addNodes is list actual NodeRef uploaded to alfresco folder
addNodeRef is only one item uploaded to alfresco
Is there any other way an item is added to the already running workflow?
Where's my mistake?
Thanks in advance
You have to add children to the package. Like this:
NodeRef packageNodeRef = ((ActivitiScriptNode)variables.get(bpm_package")).getNodeRef();
QName qname = nodeService.getPrimaryParent(toAddNodeRef).getQName();
QName assocTypeQName = WorkflowModel.ASSOC_PACKAGE_CONTAINS;
nodeService.addChild(packageNodeRef, toAddNodeRef, assocTypeQName, qname);
Is it possible to retrieve an IDocument from an IFile or IPath? I have tried this:
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(hFilePath);
TextFileDocumentProvider provider = new TextFileDocumentProvider();
IDocument doc = provider.getDocument(file);
but getDocument seems to return null.
Thanks
I was having this same issue and I found a post here that helped. Give this a shot:
IDocumentProvider provider = new TextFileDocumentProvider();
provider.connect(ifile);
document = provider.getDocument(ifile);
That's not the right kind of argument for getDocument(), but you should instead be using the headless FileBuffers APIs, starting from FileBuffers itself, getting the ITextFileBufferManager, and then using it to open a text file buffer and its IDocument: http://help.eclipse.org/juno/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/filebuffers/FileBuffers.html .
Don't forget to disconnect from the file buffer when you're done.
You can do something like this:
IFile file = (IFile) resource;
IPath filePath = file.getLocation();
filePath = FileBuffers.normalizeLocation(filePath);
IDocument document = FileBuffers.getTextFileBufferManager().getTextFileBuffer(filePath , LocationKind.NORMALIZE).getDocument();
Where does Eclipse store its user preferences? Specifically the keyboard bindings?
When you close Eclipse, any local settings regarding key shortcuts (settings that differ from the default configuration) are saved in
</path/to/workspace>\.metadata\.plugins\org.eclipse.core.runtime\.settings\
org.eclipse.ui.workbench.prefs
You can actually just copy the whole line in the org.eclipse.ui.workbech.prefs file that starts with: org.eclipse.ui.commands=
and paste it into the other corresponding eclipse workspace prefs file you want to update - at least in Eclipse Neon, and you'll get them all at once.
You can extract the bindings using the following groovy script. I'm not a groovy developer so please excuse my hack.
Groovy Script Used (substitute in a correct path to the workbench xmi file):
workbench = new XmlSlurper().parse("<path to eclipse>/workspace/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi")
List bindingTables
workbench.bindingTables.each
{ it->
//println "\tContributorURI: ${it.#contributorURI} | \tElementID : it.#elementId";
def command = "command";
def commandName = "commandname";
def description = "description";
def category;
def name = "name";
def keys = "keys";
it.bindings.each
{bindingIt->
//loop through every binding entry
command = bindingIt.#command;
keys = bindingIt.#keySequence;
workbench.commands.each
{commandIt->
def thisCommand = commandIt.attributes()['{http://www.omg.org/XMI}id'];
if(thisCommand.equals(command.toString()) )
{
commandName = commandIt.#commandName;
description = commandIt.#description;
category = commandIt.#category;
workbench.categories.each
{workbenchIt->
if(workbenchIt.attributes()['{http://www.omg.org/XMI}id'].equals(category.toString()) )
{
name = workbenchIt.#name;
}
}
}
}
println "\t\tKeys: ${keys}\tCommand: ${commandName}"+
"\tDescription: "+description+"\tName: "+name;
}
}
I'm trying to create a new file in an eclipse plugin. It's not necessarily a Java file, it can be an HTML file for example.
Right now I'm doing this:
IProject project = ...;
IFile file = project.getFile("/somepath/somefilename"); // such as file.exists() == false
String contents = "Whatever";
InputStream source = new ByteArrayInputStream(contents.getBytes());
file.create(source, false, null);
The file gets created, but the problem is that it doesn't get recognized as any type; I can't open it in any internal editor. That's until I restart Eclipse (refresh or close then open the project doesn't help). After a restart, the file is perfectly usable and opens in the correct default editor for its type.
Is there any method I need to call to get the file outside of that "limbo" state?
That thread does mention the createFile call, but also refers to a FileEditorInput to open it:
Instead of java.io.File, you should use IFile.create(..) or IFile.createLink(..). You will need to get an IFile handle from the project using IProject.getFile(..) first, then create the file using that handle.
Once the file is created you can create FileEditorInput from it and use IWorkbenchPage.openEditor(..) to open the file in an editor.
Now, would that kind of method (from this AbstractExampleInstallerWizard) be of any help in this case?
protected void openEditor(IFile file, String editorID) throws PartInitException
{
IEditorRegistry editorRegistry = getWorkbench().getEditorRegistry();
if (editorID == null || editorRegistry.findEditor(editorID) == null)
{
editorID = getWorkbench().getEditorRegistry().getDefaultEditor(file.getFullPath().toString()).getId();
}
IWorkbenchPage page = getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.openEditor(new FileEditorInput(file), editorID, true, IWorkbenchPage.MATCH_ID);
}
See also this SDOModelWizard opening an editor on a new IFile:
// Open an editor on the new file.
//
try
{
page.openEditor
(new FileEditorInput(modelFile),
workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
}
catch (PartInitException exception)
{
MessageDialog.openError(workbenchWindow.getShell(), SDOEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
return false;
}