use of com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput in project convertigo by convertigo.
the class MobileUIComponentTreeObject method editFunction.
private void editFunction(final UIComponent uic, final String functionMarker, final String propertyName) {
try {
IScriptComponent main = uic.getMainScriptComponent();
if (main == null) {
return;
}
// Refresh project resources for editor
String projectName = uic.getProject().getName();
IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
project.refreshLocal(IResource.DEPTH_INFINITE, null);
// Close editor and Reopen it after file has been rewritten
String relativePath = uic.getProject().getMobileBuilder().getFunctionTempTsRelativePath(uic);
IFile file = project.getFile(relativePath);
if (!(uic instanceof UICustomAction)) {
closeComponentFileEditor(file);
}
if (main instanceof ApplicationComponent) {
if (uic.compareToTplVersion("7.5.2.0") < 0) {
ConvertigoPlugin.logError("The ability to use forms or actions inside a menu is avalaible since 7.5.2 version." + "\nPlease change your Template project for the 'mobilebuilder_tpl_7_5_2' template.", true);
return;
}
}
uic.getProject().getMobileBuilder().writeFunctionTempTsFile(uic, functionMarker);
file.refreshLocal(IResource.DEPTH_ZERO, null);
// Open file in editor
if (file.exists()) {
IEditorInput input = new ComponentFileEditorInput(file, uic);
if (input != null) {
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String editorId = desc.getId();
IEditorPart editorPart = activePage.openEditor(input, editorId);
addMarkers(file, editorPart);
editorPart.addPropertyListener(new IPropertyListener() {
boolean isFirstChange = false;
@Override
public void propertyChanged(Object source, int propId) {
if (source instanceof ITextEditor) {
if (propId == IEditorPart.PROP_DIRTY) {
if (!isFirstChange) {
isFirstChange = true;
return;
}
isFirstChange = false;
ITextEditor editor = (ITextEditor) source;
IDocumentProvider dp = editor.getDocumentProvider();
IDocument doc = dp.getDocument(editor.getEditorInput());
String marker = MobileBuilder.getMarker(doc.get(), functionMarker);
String content = MobileBuilder.getFormatedContent(marker, functionMarker);
FormatedContent formated = new FormatedContent(content);
MobileUIComponentTreeObject.this.setPropertyValue(propertyName, formated);
}
}
}
});
}
}
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to edit function for '" + uic.getName() + "' component!");
}
}
use of com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput in project convertigo by convertigo.
the class MobileComponentTreeObject method closeAllEditors.
public void closeAllEditors(boolean save) {
MobileComponent mc = getObject();
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (activePage != null) {
IEditorReference[] editorRefs = activePage.getEditorReferences();
for (int i = 0; i < editorRefs.length; i++) {
IEditorReference editorRef = (IEditorReference) editorRefs[i];
try {
IEditorInput editorInput = editorRef.getEditorInput();
if (editorInput != null && editorInput instanceof ComponentFileEditorInput) {
if (((ComponentFileEditorInput) editorInput).is(mc) || ((ComponentFileEditorInput) editorInput).isChildOf(mc)) {
activePage.closeEditor(editorRef.getEditor(false), save);
}
}
} catch (Exception e) {
}
}
}
}
Aggregations