diff --git a/build.properties b/build.properties index 0080a1b3..f70bb3f0 100644 --- a/build.properties +++ b/build.properties @@ -1,2 +1,2 @@ -java_source = 17 -java_target = 17 +java_source = 1.8 +java_target = 1.8 diff --git a/core/source/org/libreoffice/ide/eclipse/core/editors/pack/ContentsSection.java b/core/source/org/libreoffice/ide/eclipse/core/editors/pack/ContentsSection.java index bc8e21d9..64c06373 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/editors/pack/ContentsSection.java +++ b/core/source/org/libreoffice/ide/eclipse/core/editors/pack/ContentsSection.java @@ -53,7 +53,7 @@ import org.eclipse.ui.model.WorkbenchLabelProvider; import org.libreoffice.ide.eclipse.core.editors.Messages; import org.libreoffice.ide.eclipse.core.model.pack.PackagePropertiesModel; -import org.libreoffice.ide.eclipse.core.model.utils.IModelChangedListener; +import org.libreoffice.ide.eclipse.core.model.utils.IModelTreeListener; /** * Content section of the Package Contents editor page. @@ -62,6 +62,10 @@ public class ContentsSection extends SectionPart { private PackageFormPage mPage; private ContainerCheckedTreeViewer mTreeViewer; + + private ViewerFilter mTreeFilter; + private ICheckStateListener mCheckListener; + private IModelTreeListener mTreeListener; /** * Constructor. @@ -74,7 +78,7 @@ public ContentsSection(PackageFormPage page) { ExpandableComposite.TITLE_BAR); mPage = page; - PackagePropertiesModel model = ((PackagePropertiesEditor) mPage.getEditor()).getModel(); + PackagePropertiesModel model = getModel(); Section section = getSection(); @@ -88,10 +92,10 @@ public ContentsSection(PackageFormPage page) { mTreeViewer.setContentProvider(provider); mTreeViewer.setComparator(new ViewerComparator(String.CASE_INSENSITIVE_ORDER)); - addChangeListener(model); + addTreeListener(model); addCheckStateListener(model); - setCheckStateProvider(model); addFilter(model); + setCheckStateProvider(model); section.setClient(mTreeViewer.getControl()); } @@ -102,24 +106,35 @@ public void setContents() { } } - private void addChangeListener(PackagePropertiesModel model) { - model.addChangeListener(new IModelChangedListener() { + @Override + public void dispose() { + mTreeViewer.removeFilter(mTreeFilter); + mTreeViewer.removeCheckStateListener(mCheckListener); + getModel().removeTreeListener(mTreeListener); + super.dispose(); + } + + private PackagePropertiesModel getModel() { + return ((PackagePropertiesEditor) mPage.getEditor()).getModel(); + } + + private void addTreeListener(PackagePropertiesModel model) { + IModelTreeListener listener = new IModelTreeListener() { @Override - public void modelChanged() { + public void modelRefreshed() { if (mTreeViewer != null) { mTreeViewer.refresh(); } } - @Override - public void modelSaved() { - } - }); + }; + model.addTreeListener(listener); + mTreeListener = listener; } private void addCheckStateListener(PackagePropertiesModel model) { - mTreeViewer.addCheckStateListener(new ICheckStateListener() { + ICheckStateListener listener = new ICheckStateListener() { @Override public void checkStateChanged(CheckStateChangedEvent event) { @@ -132,7 +147,41 @@ public void checkStateChanged(CheckStateChangedEvent event) { } } } - }); + }; + mTreeViewer.addCheckStateListener(listener); + mCheckListener = listener; + } + + private void addFilter(PackagePropertiesModel model) { + ViewerFilter filter = new ViewerFilter() { + + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + /* + * Files to exclude: .* Folders to exclude: build, bin + */ + boolean selected = true; + if (element instanceof IAdaptable) { + IResource res = ((IAdaptable) element).getAdapter(IResource.class); + if (res != null) { + // FIXME: If we want to be able to see soft link pointing outside + // FIXME: the Package we need to accept resource not contained in package + if (model.isHidden(res) || + res.getName().equals("build") || //$NON-NLS-1$ + res.getName().equals("bin")) { //$NON-NLS-1$ + selected = false; + } else if (model.getBasicLibraries().contains(res) || + model.getDialogLibraries().contains(res) || + model.getDescriptionFiles().containsValue(res)) { + selected = false; + } + } + } + return selected; + } + }; + mTreeViewer.addFilter(filter); + mTreeFilter = filter; } private void setCheckStateProvider(PackagePropertiesModel model) { @@ -160,34 +209,4 @@ public boolean isGrayed(Object element) { }); } - private void addFilter(PackagePropertiesModel model) { - mTreeViewer.addFilter(new ViewerFilter() { - - @Override - public boolean select(Viewer viewer, Object parentElement, Object element) { - /* - * Files to exclude: .* Folders to exclude: build, bin - */ - boolean selected = true; - if (element instanceof IAdaptable) { - IResource resource = ((IAdaptable) element).getAdapter(IResource.class); - if (resource != null) { - // FIXME: If we want to be able to see soft link pointing outside - // FIXME: the Package we need to accept resource not contained in package - if (resource.getName().startsWith(".") || //$NON-NLS-1$ - resource.getName().equals("build") || //$NON-NLS-1$ - resource.getName().equals("bin")) { //$NON-NLS-1$ - selected = false; - } else if (model.getBasicLibraries().contains(resource) || - model.getDialogLibraries().contains(resource) || - model.getDescriptionFiles().containsValue(resource)) { - selected = false; - } - } - } - return selected; - } - }); - } - } diff --git a/core/source/org/libreoffice/ide/eclipse/core/editors/pack/PackageFormPage.java b/core/source/org/libreoffice/ide/eclipse/core/editors/pack/PackageFormPage.java index 744590a6..e964a41f 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/editors/pack/PackageFormPage.java +++ b/core/source/org/libreoffice/ide/eclipse/core/editors/pack/PackageFormPage.java @@ -103,11 +103,16 @@ protected void createFormContent(IManagedForm managedForm) { // Get the Libs and Descriptions properties from the document - PackagePropertiesModel model = ((PackagePropertiesEditor) getEditor()).getModel(); + PackagePropertiesModel model = getModel(); model.setQuiet(true); mContents.setContents(); mLibs.setLibraries(model); mDescriptions.setDescriptions(model.getDescriptionFiles()); model.setQuiet(false); } + + private PackagePropertiesModel getModel() { + return ((PackagePropertiesEditor) getEditor()).getModel(); + } + } diff --git a/core/source/org/libreoffice/ide/eclipse/core/editors/pack/PackagePropertiesEditor.java b/core/source/org/libreoffice/ide/eclipse/core/editors/pack/PackagePropertiesEditor.java index 39b04511..5aabb5bb 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/editors/pack/PackagePropertiesEditor.java +++ b/core/source/org/libreoffice/ide/eclipse/core/editors/pack/PackagePropertiesEditor.java @@ -36,7 +36,7 @@ ************************************************************************/ package org.libreoffice.ide.eclipse.core.editors.pack; -import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; @@ -49,7 +49,7 @@ import org.eclipse.ui.forms.editor.FormEditor; import org.libreoffice.ide.eclipse.core.editors.utils.SourcePage; import org.libreoffice.ide.eclipse.core.model.pack.PackagePropertiesModel; -import org.libreoffice.ide.eclipse.core.model.utils.IModelChangedListener; +import org.libreoffice.ide.eclipse.core.model.utils.IModelDataListener; /** @@ -61,7 +61,8 @@ public class PackagePropertiesEditor extends FormEditor { private PackageFormPage mContentsPage; private PackagePropertiesModel mModel; - private boolean mIgnoreSourceChanges = false; + private IModelDataListener mDataListener; + private IDocumentListener mDocListener; /** * {@inheritDoc} @@ -78,28 +79,14 @@ protected void addPages() { // Add the text page for package.properties mSourcePage = new SourcePage(this, "source", "package.properties"); //$NON-NLS-1$ //$NON-NLS-2$ mSourcePage.init(getEditorSite(), getEditorInput()); + addPage(mSourcePage); // Add listener to be notified when the document content has be changed - if (mSourcePage.getDocumentProvider() instanceof TextFileDocumentProvider) { - TextFileDocumentProvider provider = (TextFileDocumentProvider) mSourcePage.getDocumentProvider(); - IDocument doc = provider.getDocument(mSourcePage.getEditorInput()); - if (doc != null) { - doc.addDocumentListener(new IDocumentListener() { - - @Override - public void documentAboutToBeChanged(DocumentEvent event) { - } - @Override - public void documentChanged(DocumentEvent event) { - mIgnoreSourceChanges = true; - mModel.reloadFromString(event.getDocument().get()); - mIgnoreSourceChanges = false; - } - }); - } + IDocument doc = getDocument(); + if (doc != null) { + addDocumentListener(doc); } - addPage(mSourcePage); } catch (PartInitException e) { // log ? } @@ -114,29 +101,12 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException if (input instanceof IFileEditorInput) { - IFileEditorInput fileInput = (IFileEditorInput) input; - IProject prj = fileInput.getFile().getProject(); - String projectName = prj.getName(); - setPartName(projectName); + IFile file = ((IFileEditorInput) input).getFile(); + setPartName(file.getProject().getName()); // Create the package properties - mModel = new PackagePropertiesModel(fileInput.getFile()); - mModel.addChangeListener(new IModelChangedListener() { - - @Override - public void modelChanged() { - if (!mIgnoreSourceChanges) { - writeToSource(mModel.writeToString()); - } - editorDirtyStateChanged(); - } + mModel = getPackagePropertiesModel(file); - @Override - public void modelSaved() { - editorDirtyStateChanged(); - } - - }); } } @@ -154,7 +124,13 @@ public boolean isDirty() { @Override public void doSave(IProgressMonitor monitor) { try { - writeToSource(mModel.write()); + // If the template has pending changes, + // they should be pushed to the document + if (mModel.write()) { + mModel.setModified(true); + writeToSource(mModel.writeToString()); + mModel.setModified(false); + } } catch (Exception e) { // Log ? } @@ -176,6 +152,19 @@ public boolean isSaveAsAllowed() { return false; } + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + IDocument doc = getDocument(); + if (doc != null) { + doc.removeDocumentListener(mDocListener); + } + mModel.removeDataListener(mDataListener); + super.dispose(); + } + /** * @return the project packaging properties file content. */ @@ -184,32 +173,72 @@ public PackagePropertiesModel getModel() { } /** - * Write the properties model to the source editor page. - * - * @param content - * the content to write + * @return the IDocument. */ - public void writeToSource(String content) { + private IDocument getDocument() { + IDocument doc = null; if (mSourcePage.getDocumentProvider() instanceof TextFileDocumentProvider) { - TextFileDocumentProvider docProvider = (TextFileDocumentProvider) mSourcePage.getDocumentProvider(); - IDocument doc = docProvider.getDocument(mSourcePage.getEditorInput()); - if (doc != null) { - doc.set(content); - } + TextFileDocumentProvider provider = (TextFileDocumentProvider) mSourcePage.getDocumentProvider(); + doc = provider.getDocument(mSourcePage.getEditorInput()); } + return doc; } - /** - * Loads the properties model from the source editor page. - */ - public void loadFromSource() { + private void addDocumentListener(IDocument doc) { + IDocumentListener listener = new IDocumentListener() { - if (mSourcePage.getDocumentProvider() instanceof TextFileDocumentProvider) { - TextFileDocumentProvider docProvider = (TextFileDocumentProvider) mSourcePage.getDocumentProvider(); - IDocument doc = docProvider.getDocument(mSourcePage.getEditorInput()); - if (doc != null) { - mModel.reloadFromString(doc.get()); + @Override + public void documentAboutToBeChanged(DocumentEvent event) { + } + + @Override + public void documentChanged(DocumentEvent event) { + if (!mModel.isModified()) { + mModel.reloadFromString(event.getDocument().get()); + mModel.fireTreeRefresh(); + editorDirtyStateChanged(); + } + } + + }; + doc.addDocumentListener(listener); + mDocListener = listener; + } + + private PackagePropertiesModel getPackagePropertiesModel(IFile file) { + PackagePropertiesModel model = new PackagePropertiesModel(file); + IModelDataListener listener = new IModelDataListener() { + + @Override + public void modelChanged() { + if (model.isModified()) { + writeToSource(model.writeToString()); + } + editorDirtyStateChanged(); } + + @Override + public void modelSaved() { + editorDirtyStateChanged(); + } + + }; + model.addDataListener(listener); + mDataListener = listener; + return model; + } + + /** + * Write the properties model to the source editor page. + * + * @param content + * the content to write + */ + private void writeToSource(String content) { + IDocument doc = getDocument(); + if (doc != null) { + doc.set(content); } } + } diff --git a/core/source/org/libreoffice/ide/eclipse/core/editors/utils/AbstractSection.java b/core/source/org/libreoffice/ide/eclipse/core/editors/utils/AbstractSection.java index cdc888bf..e446f316 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/editors/utils/AbstractSection.java +++ b/core/source/org/libreoffice/ide/eclipse/core/editors/utils/AbstractSection.java @@ -5,7 +5,7 @@ import org.eclipse.ui.forms.SectionPart; import org.eclipse.ui.forms.editor.FormPage; import org.libreoffice.ide.eclipse.core.model.utils.IModel; -import org.libreoffice.ide.eclipse.core.model.utils.IModelChangedListener; +import org.libreoffice.ide.eclipse.core.model.utils.IModelDataListener; /** * Abstract section class providing mechanisms to suspend the dirty state change notifications. @@ -13,7 +13,7 @@ * @param * the type of the model object for the section */ -public abstract class AbstractSection extends SectionPart implements IModelChangedListener { +public abstract class AbstractSection extends SectionPart implements IModelDataListener { private ModelType mModel; diff --git a/core/source/org/libreoffice/ide/eclipse/core/export/AntScriptExportWizard.java b/core/source/org/libreoffice/ide/eclipse/core/export/AntScriptExportWizard.java index 83aaa2c8..46a57b87 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/export/AntScriptExportWizard.java +++ b/core/source/org/libreoffice/ide/eclipse/core/export/AntScriptExportWizard.java @@ -44,7 +44,6 @@ import org.libreoffice.ide.eclipse.core.model.IUnoidlProject; import org.libreoffice.ide.eclipse.core.model.ProjectsManager; import org.libreoffice.ide.eclipse.core.Messages; -import org.libreoffice.plugin.core.model.UnoPackage; /** * Class for the new Ant Script Generation wizard. @@ -75,10 +74,10 @@ public AntScriptExportWizard() { * {@inheritDoc} */ @Override - public void init(IWorkbench pWorkbench, IStructuredSelection pSelection) { + public void init(IWorkbench workbench, IStructuredSelection selection) { // Try hard to find a selected UNO project IUnoidlProject prj = null; - Iterator it = pSelection.iterator(); + Iterator it = selection.iterator(); while (it.hasNext() && prj == null) { Object o = it.next(); if (o instanceof IAdaptable) { @@ -103,24 +102,20 @@ public void init(IWorkbench pWorkbench, IStructuredSelection pSelection) { public boolean performFinish() { boolean finished = false; String directory = mAntScriptPage.getPath(); - String tempPath = directory + "/temporary/temp.oxt"; - UnoPackage model = mAntScriptPage.getPackageModel(tempPath); - if (model != null) { - try { - mAntScriptPage.createBuildScripts(model); - - mAntScriptPage.refreshProject(); - - if (mHasNewDialogSettings) { - IDialogSettings workbenchSettings = OOEclipsePlugin.getDefault().getDialogSettings(); - IDialogSettings section = workbenchSettings.getSection(ANT_EXPORT_SETTINGS_KEY); - section = workbenchSettings.addNewSection(ANT_EXPORT_SETTINGS_KEY); - setDialogSettings(section); - } + try { + mAntScriptPage.createBuildScripts(); + + mAntScriptPage.refreshProject(); - } catch (Exception e) { - PluginLogger.error("The Ant Script couldn't be built", e); + if (mHasNewDialogSettings) { + IDialogSettings workbenchSettings = OOEclipsePlugin.getDefault().getDialogSettings(); + IDialogSettings section = workbenchSettings.getSection(ANT_EXPORT_SETTINGS_KEY); + section = workbenchSettings.addNewSection(ANT_EXPORT_SETTINGS_KEY); + setDialogSettings(section); } + + } catch (Exception e) { + PluginLogger.error("The Ant Script couldn't be built", e); } File antFile = new File(directory + "/build.xml"); diff --git a/core/source/org/libreoffice/ide/eclipse/core/export/AntScriptExportWizardPage.java b/core/source/org/libreoffice/ide/eclipse/core/export/AntScriptExportWizardPage.java index 980106d8..37726fac 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/export/AntScriptExportWizardPage.java +++ b/core/source/org/libreoffice/ide/eclipse/core/export/AntScriptExportWizardPage.java @@ -87,11 +87,9 @@ public AntScriptExportWizardPage(String pageName, IUnoidlProject project) { /** * Create the build scripts for the package model. * - * @param model - * the model to be used to build script */ - public void createBuildScripts(UnoPackage model) { - mLangPart.doFinish(model); + public void createBuildScripts() { + mLangPart.doFinish(); mCheckAntSectionDisplay = false; ProjectExportPart.setCheckAntSectionDisplay(mCheckAntSectionDisplay); } @@ -104,11 +102,11 @@ public IUnoidlProject getProject() { } /** - * @param pProject + * @param project * the UNO project selected for the wizard. */ - public void setProject(IUnoidlProject pProject) { - mSelectedProject = pProject; + public void setProject(IUnoidlProject project) { + mSelectedProject = project; reloadLanguagePart(); } @@ -116,9 +114,9 @@ public void setProject(IUnoidlProject pProject) { * {@inheritDoc} */ @Override - public void createControl(Composite pParent) { + public void createControl(Composite parent) { - Composite body = new Composite(pParent, SWT.NONE); + Composite body = new Composite(parent, SWT.NONE); body.setLayout(new GridLayout()); body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); setControl(body); @@ -226,16 +224,16 @@ private void reloadLanguagePart() { } /** - * @param pTempPath + * @param tempPath * the t. * @return the package model built from the data provided by the user or null if something blocked the * process. */ - public UnoPackage getPackageModel(String pTempPath) { + public UnoPackage getPackageModel(String tempPath) { UnoPackage pack = null; try { - File destFile = new File(pTempPath); + File destFile = new File(tempPath); pack = PackageContentSelector.createPackage(mSelectedProject, destFile, new ArrayList()); } catch (Exception e) { PluginLogger.error(Messages.getString("AntScriptExportWizard.LibraryCreationError"), e); //$NON-NLS-1$ diff --git a/core/source/org/libreoffice/ide/eclipse/core/export/ProjectExportPart.java b/core/source/org/libreoffice/ide/eclipse/core/export/ProjectExportPart.java index ddbc9afc..79d15d51 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/export/ProjectExportPart.java +++ b/core/source/org/libreoffice/ide/eclipse/core/export/ProjectExportPart.java @@ -52,7 +52,6 @@ import org.libreoffice.ide.eclipse.core.model.SDKContainer; import org.libreoffice.ide.eclipse.core.Messages; import org.libreoffice.ide.eclipse.core.utils.TemplatesHelper; -import org.libreoffice.plugin.core.model.UnoPackage; /** * Dialog part for the Ant scripts export configuration. @@ -91,17 +90,17 @@ public static void setCheckAntSectionDisplay(boolean antSectionDisplay) { * {@inheritDoc} */ @Override - public void createControls(Composite pParent) { + public void createControls(Composite parent) { mController = new ProjectExportPageControl(); mController.setSaveAntScript(true); if (!sAntSectionDisplay) { - mTitleLbl = new Label(pParent, SWT.NONE); + mTitleLbl = new Label(parent, SWT.NONE); mTitleLbl.setText(Messages.getString("ProjectExportPart.Title")); //$NON-NLS-1$ mTitleLbl.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false)); - Composite content = new Composite(pParent, SWT.NONE); + Composite content = new Composite(parent, SWT.NONE); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.horizontalIndent = HORIZONTAL_INDENT; content.setLayoutData(gd); @@ -139,7 +138,7 @@ public void dispose() { * {@inheritDoc} */ @Override - public void doFinish(UnoPackage model) { + public void doFinish() { String directory = sAntScriptPage.getPath(); File antFile = new File(directory + "/build.xml"); diff --git a/core/source/org/libreoffice/ide/eclipse/core/export/build.xml.tpl b/core/source/org/libreoffice/ide/eclipse/core/export/build.xml.tpl index 74d4f68e..aa1a4796 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/export/build.xml.tpl +++ b/core/source/org/libreoffice/ide/eclipse/core/export/build.xml.tpl @@ -1,5 +1,5 @@ - + + + + - + + + + + + + + + @@ -94,17 +104,33 @@ - + + + + + + + + + + + + + + + + + - + @@ -113,29 +139,33 @@ $'{'contents} - application/vnd.openofficeorg.extension - + + + + + + application/vnd.openofficeorg.extension - - - + + - + + + - - + @@ -147,13 +177,12 @@ - + - - + diff --git a/core/source/org/libreoffice/ide/eclipse/core/model/description/DescriptionModel.java b/core/source/org/libreoffice/ide/eclipse/core/model/description/DescriptionModel.java index 45357da4..1401d308 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/model/description/DescriptionModel.java +++ b/core/source/org/libreoffice/ide/eclipse/core/model/description/DescriptionModel.java @@ -41,7 +41,7 @@ import java.util.Set; import org.libreoffice.ide.eclipse.core.model.utils.IModel; -import org.libreoffice.ide.eclipse.core.model.utils.IModelChangedListener; +import org.libreoffice.ide.eclipse.core.model.utils.IModelDataListener; import org.libreoffice.plugin.core.utils.XMLWriter; /** @@ -49,7 +49,7 @@ */ public class DescriptionModel implements IModel { - private ArrayList mListeners; + private ArrayList mListeners; private boolean mDirty; private boolean mSuspendEvents; @@ -79,7 +79,7 @@ public class DescriptionModel implements IModel { * Default constructor. */ public DescriptionModel() { - mListeners = new ArrayList(); + mListeners = new ArrayList(); mDisplayNames = new HashMap<>(); mDescriptions = new HashMap<>(); @@ -93,7 +93,7 @@ public DescriptionModel() { * {@inheritDoc} */ @Override - public void addListener(IModelChangedListener listener) { + public void addListener(IModelDataListener listener) { mListeners.add(listener); } @@ -101,7 +101,7 @@ public void addListener(IModelChangedListener listener) { * {@inheritDoc} */ @Override - public void removeListener(IModelChangedListener listener) { + public void removeListener(IModelDataListener listener) { mListeners.remove(listener); } @@ -931,7 +931,7 @@ private void appendNew(ArrayList locales, Set newLocales) { protected void fireModelChanged() { if (!mSuspendEvents) { mDirty = true; - for (IModelChangedListener listener : mListeners) { + for (IModelDataListener listener : mListeners) { listener.modelChanged(); } } @@ -943,7 +943,7 @@ protected void fireModelChanged() { protected void fireModelSaved() { if (!mSuspendEvents) { mDirty = false; - for (IModelChangedListener listener : mListeners) { + for (IModelDataListener listener : mListeners) { listener.modelSaved(); } } diff --git a/core/source/org/libreoffice/ide/eclipse/core/model/language/LanguageExportPart.java b/core/source/org/libreoffice/ide/eclipse/core/model/language/LanguageExportPart.java index 278b6610..e52506e2 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/model/language/LanguageExportPart.java +++ b/core/source/org/libreoffice/ide/eclipse/core/model/language/LanguageExportPart.java @@ -32,7 +32,6 @@ import org.eclipse.swt.widgets.Composite; import org.libreoffice.ide.eclipse.core.wizards.pages.ManifestExportPage; -import org.libreoffice.plugin.core.model.UnoPackage; /** * Abstract class for the language specific controls part in the OXT export wizard. @@ -44,10 +43,10 @@ public abstract class LanguageExportPart { /** * Create the controls in the part. * - * @param pParent + * @param parent * the parent composite where to create the controls */ - public abstract void createControls(Composite pParent); + public abstract void createControls(Composite parent); /** * Cleans the controls. @@ -59,10 +58,8 @@ public abstract class LanguageExportPart { * * Note that the controls might be disposed when this methods is called. * - * @param model - * the model of the exported package */ - public abstract void doFinish(UnoPackage model); + public abstract void doFinish(); /** * @param page diff --git a/core/source/org/libreoffice/ide/eclipse/core/model/messages.properties b/core/source/org/libreoffice/ide/eclipse/core/model/messages.properties index f6002da1..1671c3c1 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/model/messages.properties +++ b/core/source/org/libreoffice/ide/eclipse/core/model/messages.properties @@ -5,3 +5,7 @@ PackagePropertiesModel.FileReadException=Can't read file: PackagePropertiesModel.Comment=Written by the OOEclipseIntegration PackagePropertiesModel.NoLocaleException=The locale has to be defined for each package description PackagePropertiesModel.NoDescriptionFileException=No existing description file to add +PackagePropertiesModel.DeserializeContent=Deserializing <%1$s> files and <%2$s> empty folders from package.properties file. +PackagePropertiesModel.DeserializeAsMissingResource=Deserializing has missing resources: <%1$s> +PackagePropertiesModel.DeserializeAsModifiedResource=Deserializing has modified resources: <%1$s> +PackagePropertiesModel.SerializeContent=Serializing <%1$s> files and <%2$s> empty folders in package.properties file. diff --git a/core/source/org/libreoffice/ide/eclipse/core/model/pack/PackagePropertiesModel.java b/core/source/org/libreoffice/ide/eclipse/core/model/pack/PackagePropertiesModel.java index e7f6a818..56db711e 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/model/pack/PackagePropertiesModel.java +++ b/core/source/org/libreoffice/ide/eclipse/core/model/pack/PackagePropertiesModel.java @@ -41,6 +41,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -50,7 +52,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; -import java.util.Set; import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -63,7 +64,8 @@ import org.eclipse.core.runtime.CoreException; import org.libreoffice.ide.eclipse.core.PluginLogger; import org.libreoffice.ide.eclipse.core.model.Messages; -import org.libreoffice.ide.eclipse.core.model.utils.IModelChangedListener; +import org.libreoffice.ide.eclipse.core.model.utils.IModelDataListener; +import org.libreoffice.ide.eclipse.core.model.utils.IModelTreeListener; /** * @@ -81,9 +83,11 @@ public class PackagePropertiesModel { private List mFiles = null; private Map mFolders = null; - private boolean mIsDirty = false; + private short mDirty = 0; private boolean mIsQuiet = false; - private Vector mListeners = new Vector(); + private boolean mIsModified = false; + private Vector mDataListeners = new Vector(); + private Vector mTreeListeners = new Vector(); /** * Create a new package.properties model for a given file. If the file can be read, the existing properties will be @@ -103,33 +107,81 @@ public PackagePropertiesModel(IFile file) throws IllegalArgumentException { mPropertiesFile = file; } catch (FileNotFoundException e) { mPropertiesFile = null; - String msg = Messages.getString("PackagePropertiesModel.NullFileException"); + String msg = Messages.getString("PackagePropertiesModel.NullFileException"); //$NON-NLS-1$ throw new IllegalArgumentException(msg); //$NON-NLS-1$ } try { mProperties.load(is); } catch (IOException e) { - PluginLogger.warning(Messages.getString("PackagePropertiesModel.FileReadException") - + file.getLocation()); //$NON-NLS-1$ + String msg = Messages.getString("PackagePropertiesModel.FileReadException"); //$NON-NLS-1$ + PluginLogger.warning(msg + file.getLocation()); //$NON-NLS-1$ } finally { try { is.close(); } catch (Exception e) { } - mFiles = deserializeContent(); - mFolders = getFolderCheckState(); + } + Map paths = new HashMap<>(); + Map folders = new HashMap<>(); + mFiles = deserializeContent(folders, paths); + mFolders = getFolderCheckState(folders); + // If some resources are missing or modified, we need to log these resources. + if (!paths.isEmpty()) { + logMissingPaths(paths, true); + logMissingPaths(paths, false); + firePackageChanged(); + // the model is marked as dirty with pending changes. + mDirty = 2; } } /** * Set whether the changes should be notified to the listeners or not. * - * @param pQuiet + * @param quiet * true if the changes should be notified, false otherwise. */ - public void setQuiet(boolean pQuiet) { - mIsQuiet = pQuiet; + public void setQuiet(boolean quiet) { + mIsQuiet = quiet; + } + + /** + * Set whether the changes should come from this data model or not. + * + * @param modified + * true if the changes come from this data model, false otherwise. + */ + public void setModified(boolean modified) { + mIsModified = modified; + } + + /** + * Get whether the changes come from this data model or not. + * + * @return true if the changes come from this data model, false otherwise. + */ + public boolean isModified() { + return mIsModified; + } + + /** + * Get whether the resource is hidden or not. + * + * @param res + * the resource to check. + * + * @return true if resource is hidden, false otherwise. + */ + public boolean isHidden(IResource res) { + return res.getName().startsWith("."); //$NON-NLS-1$ + } + + /** + * @return true if the properties model has changed but isn't saved, false otherwise. + */ + public boolean isDirty() { + return mDirty != 0; } /** @@ -138,8 +190,8 @@ public void setQuiet(boolean pQuiet) { * @param listener * the listener to add. */ - public void addChangeListener(IModelChangedListener listener) { - mListeners.add(listener); + public void addDataListener(IModelDataListener listener) { + mDataListeners.add(listener); } /** @@ -148,19 +200,42 @@ public void addChangeListener(IModelChangedListener listener) { * @param listener * the listener to remove */ - public void removeChangedListener(IModelChangedListener listener) { - if (mListeners.contains(listener)) { - mListeners.remove(listener); + public void removeDataListener(IModelDataListener listener) { + if (mDataListeners.contains(listener)) { + mDataListeners.remove(listener); } } /** + * Add a listener notified of the TreeView changes. + * + * @param listener + * the listener to add. + */ + public void addTreeListener(IModelTreeListener listener) { + mTreeListeners.add(listener); + } + + /** + * Removes a class listening the TreeView changes. + * + * @param listener + * the listener to remove + */ + public void removeTreeListener(IModelTreeListener listener) { + if (mTreeListeners.contains(listener)) { + mTreeListeners.remove(listener); + } + } + + + /**IModelChangedListener * Notify that the package properties model has been saved. */ public void firePackageSaved() { if (!mIsQuiet) { - mIsDirty = false; - for (IModelChangedListener listener : mListeners) { + mDirty = 0; + for (IModelDataListener listener : mDataListeners) { listener.modelSaved(); } } @@ -171,31 +246,36 @@ public void firePackageSaved() { */ public void firePackageChanged() { if (!mIsQuiet) { - mIsDirty = true; - for (IModelChangedListener listener : mListeners) { + mDirty = 1; + for (IModelDataListener listener : mDataListeners) { listener.modelChanged(); } } } /** - * @return true if the properties model has changed but isn't saved, false otherwise. + * Notify that the tree view must do a refresh. */ - public boolean isDirty() { - return mIsDirty; + public void fireTreeRefresh() { + mDirty = 2; + for (IModelTreeListener listener : mTreeListeners) { + listener.modelRefreshed(); + } } /** * Writes the Package properties to the file. * - * @return the content of the package properties under the form of a string - * as it would have been written to the file. - * * @throws Exception * if the data can't be written + * + * @return true if pending change exist, false otherwise. */ - public String write() throws Exception { - String content = writeToString(); + public boolean write() throws Exception { + boolean hasChanges = hasPendingChanges(); + if (hasChanges) { + mProperties.setProperty(CONTENTS, serializeContent()); + } FileOutputStream os = new FileOutputStream(mPropertiesFile.getLocation().toFile()); try { mProperties.store(os, Messages.getString("PackagePropertiesModel.Comment")); //$NON-NLS-1$ @@ -209,7 +289,7 @@ public String write() throws Exception { // Nothing to log } } - return content; + return hasChanges; } /** @@ -220,21 +300,20 @@ public String write() throws Exception { * the string describing the data */ public void reloadFromString(String content) { - String initContent = writeToString(); - if (!content.equals(initContent)) { + if (!content.equals(writeToString())) { mProperties.clear(); try { mProperties.load(new StringReader(content)); } catch (IOException e) { // Nothing to log return; - } - mFiles.clear(); - mFiles.addAll(deserializeContent()); + } + Map folders = new HashMap<>(); + mFiles.clear(); + mFiles.addAll(deserializeContent(folders, null)); mFolders.clear(); - mFolders.putAll(getFolderCheckState()); + mFolders.putAll(getFolderCheckState(folders)); - firePackageChanged(); } } @@ -243,15 +322,13 @@ public void reloadFromString(String content) { * as it would have been written to the file. */ public String writeToString() { - String fileContent = ""; //$NON-NLS-1$ - mProperties.setProperty(CONTENTS, serializeContent()); - Set> entries = mProperties.entrySet(); - Iterator> iter = entries.iterator(); - while (iter.hasNext()) { - Entry entry = iter.next(); - fileContent += (String) entry.getKey() + "=" + (String) entry.getValue() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ + Writer writer = new StringWriter(); + try { + mProperties.store(writer, Messages.getString("PackagePropertiesModel.Comment")); //$NON-NLS-1$ + } catch (IOException e) { + // Nothing to log } - return fileContent; + return writer.toString(); } /** @@ -371,75 +448,100 @@ public void clearDialogLibraries() { /** * add resource entry if not already in. * - * @param pRes the resource entry to add + * @param res + * the resource (ie: file or folder) to add */ - public void addResource(IResource pRes) { + public void addResource(IResource res) { // If it's a folder we need to add all children resources try { - if (pRes.getType() == IResource.FOLDER) { - addFolderResource(pRes); - } else if (!mFiles.contains(pRes)) { - addFileResource(pRes); + if (res.getType() == IResource.FOLDER) { + addFolderResource(res); + } else if (res.getType() == IResource.FILE) { + addFileResource(res); } + mProperties.setProperty(CONTENTS, serializeContent()); + mIsModified = true; firePackageChanged(); + mIsModified = false; } catch (CoreException e) { - // Log ? + // Nothing to log } } /** * remove resource entry if already in. * - * @param pRes the resource entry to remove + * @param res + * the resource (ie: file or folder) to add */ - public void removeResource(IResource pRes) { + public void removeResource(IResource res) { // If it's a folder we need to remove all children resources to try { - if (pRes.getType() == IResource.FOLDER) { - removeFolderResource(pRes); - } else if (mFiles.contains(pRes)) { - removeFileResource(pRes); + if (res.getType() == IResource.FOLDER) { + removeFolderResource(res); + } else if (res.getType() == IResource.FILE) { + removeFileResource(res); } + mProperties.setProperty(CONTENTS, serializeContent()); + mIsModified = true; firePackageChanged(); + mIsModified = false; } catch (CoreException e) { - // Log ? + // Nothing to log } } /** - * @param pRes the resource entry to check + * @return if resource is checked. * - * @return if resource is checked + * @param res + * the resource (ie: file or folder) to check */ - public boolean isChecked(IResource pRes) { + public boolean isChecked(IResource res) { boolean checked = false; - if (pRes.getType() == IResource.FILE) { - checked = mFiles.contains(pRes); - } else if (pRes.getType() == IResource.FOLDER) { - checked = mFolders.containsKey(pRes); + if (res.getType() == IResource.FILE) { + checked = mFiles.contains(res); + } else if (res.getType() == IResource.FOLDER) { + checked = mFolders.containsKey(res); } return checked; } /** - * @param pRes the resource entry to check + * @return if resource is grayed. * - * @return if resource is grayed + * @param res + * the resource (ie: file or folder) to check */ - public boolean isGrayed(IResource pRes) { + public boolean isGrayed(IResource res) { boolean grayed = false; - if (pRes.getType() == IResource.FOLDER) { - grayed = mFolders.getOrDefault(pRes, false); + if (res.getType() == IResource.FOLDER) { + grayed = mFolders.getOrDefault(res, false); } return grayed; } /** - * @return the list of the the files and directories added to the package properties that are not dialog or basic - * libraries or package descriptions + * @return the list of the the files and selected empty folders added to the package properties + * that are not dialog or basic libraries or package descriptions */ public List getContents() { - return mFiles; + List contents = new ArrayList<>(); + contents.addAll(mFiles); + try { + for (Entry entry : mFolders.entrySet()) { + if (entry.getValue()) { + continue; + } + IResource folder = entry.getKey(); + if (!hasVisibleMembers(folder)) { + contents.add(folder); + } + } + } catch (CoreException e) { + // Nothing to log + } + return contents; } /** @@ -468,12 +570,12 @@ public void clearContents() { public void addDescriptionFile(IFile description, Locale locale) throws IllegalArgumentException { if (locale == null) { - String msg = Messages.getString("PackagePropertiesModel.NoLocaleException"); + String msg = Messages.getString("PackagePropertiesModel.NoLocaleException"); //$NON-NLS-1$ throw new IllegalArgumentException(msg); //$NON-NLS-1$ } if (description == null || !description.exists()) { - String msg = Messages.getString("PackagePropertiesModel.NoDescriptionFileException"); + String msg = Messages.getString("PackagePropertiesModel.NoDescriptionFileException"); //$NON-NLS-1$ throw new IllegalArgumentException(msg); //$NON-NLS-1$ } @@ -541,19 +643,32 @@ public void clearDescriptions() { } /** - * Add all files that are members of a folder resource recursively. + * Get pending change status. * - * @param folder the resource folder entry + * @return true if pending change exist, false otherwise. + */ + private boolean hasPendingChanges() { + return mDirty == 2; + } + + /** + * Add all files that are members of a folder resource recursively. * + * @param folder + * the folder resource */ private void addFolderResource(IResource folder) throws CoreException { mFolders.put(folder, false); IResource[] members = ((IContainer) folder).members(); - for (IResource res :members) { + for (IResource res : members) { if (res.getType() == IResource.FOLDER) { - addFolderResource(res); + if (!isHidden(res)) { + addFolderResource(res); + } } else if (!mFiles.contains(res)) { - mFiles.add(res); + if (!isHidden(res)) { + mFiles.add(res); + } } } } @@ -561,8 +676,8 @@ private void addFolderResource(IResource folder) throws CoreException { /** * Remove all files that are members of a folder resource recursively. * - * @param folder the resource folder entry - * + * @param folder + * the folder resource */ private void removeFolderResource(IResource folder) throws CoreException { if (mFolders.containsKey(folder)) { @@ -581,159 +696,271 @@ private void removeFolderResource(IResource folder) throws CoreException { /** * Add a files and updated folders. * - * @param file the resource file entry - * + * @param file + * the folder resource */ private void addFileResource(IResource file) throws CoreException { - mFiles.add(file); - IProject prj = mPropertiesFile.getProject(); - IContainer parent = file.getParent(); - while (parent != null && parent != prj) { - parent = getParentCheckState(parent); + if (!mFiles.contains(file)) { + mFiles.add(file); } + setFileCheckState(file); } /** * Remove a files and updated folders. * - * @param file the resource file entry - * + * @param file + * the folder resource */ private void removeFileResource(IResource file) throws CoreException { if (mFiles.contains(file)) { mFiles.remove(file); } - IProject prj = mPropertiesFile.getProject(); - IContainer parent = file.getParent(); - while (parent != null && parent != prj) { - if (mFolders.containsKey(parent)) { - if (parent.members().length == 1) { - mFolders.remove(parent); - } else { - mFolders.put(parent, true); - } - } - parent = parent.getParent(); - } + setFileCheckState(file); } /** * Serialize all files resource to the package properties. * - * @return a string corresponding to the value of the contents property of the package.properties file + * @return a string of all files and empty folder. */ private String serializeContent() { - List result = new ArrayList<>(); - for (IResource res : mFiles) { - if (res.getType() == IResource.FILE && res.exists()) { - result.add(res.getProjectRelativePath().toString()); + List results = new ArrayList<>(); + int nbFiles = 0; + int nbFolders = 0; + try { + for (IResource file : mFiles) { + if (file.getType() == IResource.FILE && file.exists()) { + results.add(file.getProjectRelativePath().toString()); + nbFiles++; + } + } + for (Entry entry : mFolders.entrySet()) { + nbFolders += serializeFolder(results, entry); + } + + } catch (CoreException e) { + e.printStackTrace(); + } + String template = Messages.getString("PackagePropertiesModel.SerializeContent"); //$NON-NLS-1$ + PluginLogger.info(String.format(template, nbFiles, nbFolders)); //$NON-NLS-1$ + Collections.sort(results, String.CASE_INSENSITIVE_ORDER); + return String.join(SEPARATOR, results); + } + + private int serializeFolder(List results, Entry entry) throws CoreException { + // Only empty folder will be saved if checked + int nbFolders = 0; + IResource folder = entry.getKey(); + if (folder.getType() == IResource.FOLDER && folder.exists() && !isHidden(folder)) { + if (!entry.getValue() && !hasVisibleMembers(folder)) { + results.add(folder.getProjectRelativePath().toString()); + nbFolders++; } } - Collections.sort(result, String.CASE_INSENSITIVE_ORDER); - return String.join(SEPARATOR, result); + return nbFolders; } /** * De-serialize all files resource from the package properties. * - * @return a list of resource corresponding to the value of the contents property of the package.properties file + * @param folders + * the folder + * + * @param paths + * the path of missing resource + * + * @return a list of the file resource */ - private List deserializeContent() { - List resources = new ArrayList<>(); + private List deserializeContent(Map folders, Map paths) { + List files = new ArrayList<>(); + IProject prj = mPropertiesFile.getProject(); + int nbFiles = 0; + int nbFolders = 0; try { - String libs = mProperties.getProperty(CONTENTS); - IProject prj = mPropertiesFile.getProject(); + String contents = mProperties.getProperty(CONTENTS); - if (libs != null && !libs.equals("")) { //$NON-NLS-1$ - for (String path : libs.split(SEPARATOR)) { + if (contents != null && !contents.equals("")) { //$NON-NLS-1$ + for (String path : contents.split(SEPARATOR)) { if (prj.getFile(path).exists()) { - resources.add(prj.getFile(path)); + IFile file = prj.getFile(path); + if (!files.contains(file)) { + files.add(file); + nbFiles++; + } + } else if (prj.getFolder(path).exists()) { + nbFolders += deserializeFolder(prj, folders, paths, path); + } else if (paths != null) { + paths.put(path, true); } } } - } catch (NullPointerException e) { + } catch (NullPointerException | CoreException e) { // Nothing to do nor return } - return resources; + String template = Messages.getString("PackagePropertiesModel.DeserializeContent"); //$NON-NLS-1$ + PluginLogger.info(String.format(template, nbFiles, nbFolders)); //$NON-NLS-1$ + return files; } - /** - * Get project check state from files resource. + private int deserializeFolder(IProject prj, Map folders, + Map paths, String path) throws CoreException { + // Only empty folder will be restored + int nbFolders = 0; + IFolder folder = prj.getFolder(path); + if (!hasVisibleMembers(folder)) { + folders.put(folder, false); + nbFolders++; + } else if (paths != null) { + paths.put(path, false); + } + return nbFolders; + } + + /** + * Get project folder check state from file resources. * - * @return a map of resource / boolean corresponding to the folder resources + * @param folders + * the folders (ie: map ) + * + * @return a map of the folder resource / check state */ - private Map getFolderCheckState() { - Map resources = new HashMap<>(); + private Map getFolderCheckState(Map folders) { try { - IResource [] members = mPropertiesFile.getProject().members(); - for (IResource res : members) { - if (res.getType() == IResource.FOLDER) { - getSubFolderCheckState(resources, res); - } - } - } catch (NullPointerException | CoreException e) { + IContainer parent = mPropertiesFile.getProject(); + setFolderCheckState(folders, parent); + } catch (CoreException e) { // Nothing to do nor return } - return resources; + return folders; } /** - * Get folder check state from files resource. + * Set folder check state from files resource. * - * @param folders the map resource / boolean to update + * @param folders + * the folders (ie: map ) * - * @param parent the folder resource entry + * @param parent + * the parent resource */ - private void getSubFolderCheckState(Map folders, IResource parent) throws CoreException { - IResource[] members = ((IContainer) parent).members(); - boolean checked = true; - boolean grayed = false; + private void setFolderCheckState(Map folders, IContainer parent) throws CoreException { + IResource[] members = parent.members(); + boolean all = true; + boolean any = false; for (IResource res : members) { - if (res.getType() == IResource.FOLDER) { - getSubFolderCheckState(folders, res); - } else if (mFiles.contains(res)) { - grayed = true; - } else { - checked = false; + // We need to consider only non-hidden resource + if (isHidden(res)) { + continue; + } + if (res.getType() == IResource.FILE) { + if (mFiles.contains(res)) { + any = true; + } else { + all = false; + } + } else if (res.getType() == IResource.FOLDER) { + setFolderCheckState(folders, (IContainer) res); + if (!folders.containsKey(res)) { + all = false; + } else if (folders.get(res)) { + any = true; + } } } - if (members.length == 0) { - folders.put(parent, false); - } else if (checked || grayed) { - folders.put(parent, grayed && !checked); + if (isCheckStateSetable(folders, parent)) { + if (members.length == 0) { + all = false; + } + setCheckState(folders, parent, all, any); + } + } + + private boolean isCheckStateSetable(Map folders, IContainer res) { + // We must exclude empty folders already present otherwise they will be lost + return res.getType() != IResource.PROJECT && !folders.containsKey(res); + } + + private void setFileCheckState(IResource file) throws CoreException { + IContainer parent = file.getParent(); + while (parent.getType() != IResource.PROJECT) { + setParentCheckState(parent); + parent = parent.getParent(); } } /** - * Get parent check state from files resource. - * - * @param pParent the folder resource entry + * Set parent check state from files resource. * - * @return the parent resource of the folder resource entry or null + * @param parent + * the parent resource */ - private IContainer getParentCheckState(IResource pParent) throws CoreException { - IResource[] members = ((IContainer) pParent).members(); - boolean checked = true; - boolean grayed = false; + private void setParentCheckState(IContainer parent) throws CoreException { + IResource[] members = parent.members(); + boolean all = true; + boolean any = false; for (IResource res : members) { - if (res.getType() == IResource.FOLDER) { - if (mFolders.containsKey(res)) { - grayed = mFolders.get(res); + // We need to consider only non-hidden resource + if (isHidden(res)) { + continue; + } + if (res.getType() == IResource.FILE) { + if (mFiles.contains(res)) { + any = true; } else { - checked = false; + all = false; + } + } else if (res.getType() == IResource.FOLDER) { + if (!mFolders.containsKey(res)) { + all = false; + } else if (mFolders.get(res)) { + any = true; } - } else if (mFiles.contains(res)) { - grayed = true; - } else { - checked = false; } } if (members.length == 0) { - mFolders.put(pParent, false); - } else if (checked || grayed) { - mFolders.put(pParent, grayed && !checked); + all = false; + } + setCheckState(mFolders, parent, all, any); + } + + private boolean hasVisibleMembers(IResource folder) throws CoreException { + boolean hasMembers = false; + IResource[] members = ((IContainer) folder).members(); + for (IResource res : members) { + if (!isHidden(res)) { + hasMembers = true; + break; + } + } + return hasMembers; + } + + private void setCheckState(Map folders, IResource parent, boolean all, boolean any) { + if (all || any) { + folders.put(parent, any && !all); + } else if (folders.containsKey(parent)) { + folders.remove(parent); + } + } + + private void logMissingPaths(Map paths, boolean missing) { + List resources = new ArrayList<>(); + for (Entry entry : paths.entrySet()) { + if (entry.getValue() == missing) { + resources.add(entry.getKey()); + } + } + if (!resources.isEmpty()) { + String template; + if (missing) { + template = Messages.getString("PackagePropertiesModel.DeserializeAsMissingResource"); //$NON-NLS-1$ + } else { + template = Messages.getString("PackagePropertiesModel.DeserializeAsModifiedResource"); //$NON-NLS-1$ + } + String msg = String.join(SEPARATOR, resources.toArray(new String[0])); //$NON-NLS-1$ + PluginLogger.warning(String.format(template, msg)); //$NON-NLS-1$ //$NON-NLS-2$ } - return pParent.getParent(); } } diff --git a/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModel.java b/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModel.java index 479679e6..b30e005f 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModel.java +++ b/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModel.java @@ -41,7 +41,7 @@ public interface IModel { * @param listener * the listener to add */ - public void addListener(IModelChangedListener listener); + public void addListener(IModelDataListener listener); /** * Remove a model listener. @@ -49,7 +49,7 @@ public interface IModel { * @param listener * the listener to remove */ - public void removeListener(IModelChangedListener listener); + public void removeListener(IModelDataListener listener); /** * @return whether the model has been changed without being saved or not. diff --git a/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModelChangedListener.java b/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModelDataListener.java similarity index 97% rename from core/source/org/libreoffice/ide/eclipse/core/model/utils/IModelChangedListener.java rename to core/source/org/libreoffice/ide/eclipse/core/model/utils/IModelDataListener.java index 5fe749c3..ea66a0f8 100644 --- a/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModelChangedListener.java +++ b/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModelDataListener.java @@ -40,7 +40,7 @@ * Generic interface to listen to models. * */ -public interface IModelChangedListener { +public interface IModelDataListener { /** * Method called each time the listened model has changed. diff --git a/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModelTreeListener.java b/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModelTreeListener.java new file mode 100644 index 00000000..9d8214df --- /dev/null +++ b/core/source/org/libreoffice/ide/eclipse/core/model/utils/IModelTreeListener.java @@ -0,0 +1,51 @@ +/************************************************************************* + * The Contents of this file are made available subject to the terms of + * the GNU Lesser General Public License Version 2.1 + * + * Sun Microsystems Inc., October, 2000 + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): Cedric Bosdonnat + * + * + ************************************************************************/ +package org.libreoffice.ide.eclipse.core.model.utils; + +/** + * Generic interface to listen to models. + * + */ +public interface IModelTreeListener { + + /** + * Method called each time the listened model has been refreshed. + * + */ + public void modelRefreshed(); + +}