diff --git a/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/actions/RestoreCommitAction.java b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/actions/RestoreCommitAction.java index 6b5cfa5..cd15b89 100644 --- a/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/actions/RestoreCommitAction.java +++ b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/actions/RestoreCommitAction.java @@ -35,7 +35,7 @@ public class RestoreCommitAction extends AbstractModelAction { public RestoreCommitAction(IWorkbenchWindow window) { super(window); - setImageDescriptor(IModelRepositoryImages.ImageFactory.getImageDescriptor(IModelRepositoryImages.ICON_SYNCED)); + setImageDescriptor(IModelRepositoryImages.ImageFactory.getImageDescriptor(IModelRepositoryImages.ICON_RESET)); setText(Messages.RestoreCommitAction_0); setToolTipText(Messages.RestoreCommitAction_0); } diff --git a/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/grafico/GraficoFileConventions.java b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/grafico/GraficoFileConventions.java new file mode 100644 index 0000000..5c74484 --- /dev/null +++ b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/grafico/GraficoFileConventions.java @@ -0,0 +1,40 @@ +package org.archicontribs.modelrepository.grafico; + +import java.io.File; + +import org.eclipse.emf.ecore.EObject; + +import com.archimatetool.model.FolderType; +import com.archimatetool.model.IFolder; +import com.archimatetool.model.IIdentifier; + +public final class GraficoFileConventions { + + private GraficoFileConventions() { + // utility class + } + + public static File forFolder(File parentFolder, IFolder iFolder) { + return new File(parentFolder, GraficoFileConventions.getNameFor(iFolder)); + } + + public static File forElement(File modelFolder, IFolder iFolder, EObject elem) { + File elemFolder = new File(modelFolder, GraficoFileConventions.getNameFor(iFolder)); + return GraficoFileConventions.forElement(elemFolder, elem); + } + + public static File forElement(File elemFolder, EObject elem) { + return new File(elemFolder, elem.getClass().getSimpleName() + "_" + ((IIdentifier) elem).getId() + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * Generate a proper name for directory creation + * + * @param folder + * @return + */ + public static String getNameFor(IFolder folder) { + return folder.getType() == FolderType.USER ? folder.getId().toString() : folder.getType().toString(); + } + +} diff --git a/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/grafico/GraficoModelExporter.java b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/grafico/GraficoModelExporter.java index 3d81acf..a9c8ba8 100644 --- a/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/grafico/GraficoModelExporter.java +++ b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/grafico/GraficoModelExporter.java @@ -36,12 +36,10 @@ import com.archimatetool.editor.model.IArchiveManager; import com.archimatetool.editor.utils.FileUtils; -import com.archimatetool.model.FolderType; import com.archimatetool.model.IArchimateModel; import com.archimatetool.model.IDiagramModelImageProvider; import com.archimatetool.model.IFolder; import com.archimatetool.model.IFolderContainer; -import com.archimatetool.model.IIdentifier; /** @@ -177,7 +175,7 @@ private void createAndSaveResourceForFolder(IFolderContainer folderContainer, Fi allFolders.addAll(folderContainer.getFolders()); for(IFolder tmpFolder : allFolders) { - File tmpFolderFile = new File(folder, getNameFor(tmpFolder)); + File tmpFolderFile = GraficoFileConventions.forFolder(folder, tmpFolder); tmpFolderFile.mkdirs(); createAndSaveResource(new File(tmpFolderFile, IGraficoConstants.FOLDER_XML), tmpFolder); createAndSaveResourceForFolder(tmpFolder, tmpFolderFile); @@ -190,7 +188,7 @@ private void createAndSaveResourceForFolder(IFolderContainer folderContainer, Fi allElements.addAll(((IFolder)folderContainer).getElements()); for(EObject tmpElement : allElements) { createAndSaveResource( - new File(folder, tmpElement.getClass().getSimpleName() + "_" + ((IIdentifier)tmpElement).getId() + ".xml"), //$NON-NLS-1$ //$NON-NLS-2$ + GraficoFileConventions.forElement(folder, tmpElement), tmpElement); } } @@ -198,17 +196,7 @@ private void createAndSaveResourceForFolder(IFolderContainer folderContainer, Fi createAndSaveResource(new File(folder, IGraficoConstants.FOLDER_XML), folderContainer); } } - - /** - * Generate a proper name for directory creation - * - * @param folder - * @return - */ - private String getNameFor(IFolder folder) { - return folder.getType() == FolderType.USER ? folder.getId().toString() : folder.getType().toString(); - } - + /** * Save the model to Resource * diff --git a/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/views/history/HistoryTableViewer.java b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/views/history/HistoryTableViewer.java index d78a761..f6066ec 100644 --- a/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/views/history/HistoryTableViewer.java +++ b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/views/history/HistoryTableViewer.java @@ -5,7 +5,9 @@ */ package org.archicontribs.modelrepository.views.history; +import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; @@ -14,6 +16,7 @@ import org.archicontribs.modelrepository.IModelRepositoryImages; import org.archicontribs.modelrepository.grafico.BranchInfo; import org.archicontribs.modelrepository.grafico.BranchStatus; +import org.archicontribs.modelrepository.grafico.GraficoFileConventions; import org.archicontribs.modelrepository.grafico.IArchiRepository; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.viewers.CellLabelProvider; @@ -30,12 +33,15 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.treewalk.filter.PathFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import com.archimatetool.editor.ui.UIUtils; +import com.archimatetool.model.IArchimateModelObject; +import com.archimatetool.model.IFolder; /** @@ -119,6 +125,15 @@ public void doSetInput(IArchiRepository archiRepo) { // setSelection(new StructuredSelection(element), true); //} } + + private static record HistoryInput(IArchiRepository repo, IArchimateModelObject obj) {} + + public void doSetInput(IArchiRepository selectedRepository, Object selected) { + if (selected instanceof IArchimateModelObject) + setInput(new HistoryInput(selectedRepository, (IArchimateModelObject)selected)); + else + doSetInput(selectedRepository); + } public void setSelectedBranch(BranchInfo branchInfo) { if(branchInfo != null && branchInfo.equals(fSelectedBranch)) { @@ -155,27 +170,47 @@ List getCommits(Object parent) { fLocalCommit = null; fOriginCommit = null; - if(!(parent instanceof IArchiRepository) || fSelectedBranch == null) { + IArchiRepository repo = null; + File elemFile = null; + + if (parent instanceof HistoryInput && ((HistoryInput) parent).obj().eContainer() instanceof IFolder) { + HistoryInput input = (HistoryInput) parent; + repo = input.repo(); + IFolder folder = (IFolder) input.obj().eContainer(); + elemFile = GraficoFileConventions.forElement( + new File(repo.getLocalRepositoryFolder(), "model"), + folder, + input.obj()); + } else if (parent instanceof IArchiRepository) + repo = (IArchiRepository) parent; + + if(fSelectedBranch == null) { return commits; } - IArchiRepository repo = (IArchiRepository)parent; - // Local Repo was deleted - if(!repo.getLocalRepositoryFolder().exists()) { + if(repo == null || !repo.getLocalRepositoryFolder().exists()) { return commits; } try(Repository repository = Git.open(repo.getLocalRepositoryFolder()).getRepository()) { // a RevWalk allows to walk over commits based on some filtering that is defined try(RevWalk revWalk = new RevWalk(repository)) { + if (elemFile != null) { + String elemPath = Path.of(repo.getLocalRepositoryFolder().getAbsolutePath()) + .relativize( + Path.of(elemFile.getAbsolutePath()) + ).toString(); + revWalk.setTreeFilter(PathFilter.create(elemPath)); + } + // Find the local branch ObjectId objectID = repository.resolve(fSelectedBranch.getLocalBranchNameFor()); if(objectID != null) { fLocalCommit = revWalk.parseCommit(objectID); revWalk.markStart(fLocalCommit); } - + // Find the remote branch objectID = repository.resolve(fSelectedBranch.getRemoteBranchNameFor()); if(objectID != null) { diff --git a/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/views/history/HistoryView.java b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/views/history/HistoryView.java index 20856b2..dfda1d9 100644 --- a/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/views/history/HistoryView.java +++ b/org.archicontribs.modelrepository/src/org/archicontribs/modelrepository/views/history/HistoryView.java @@ -5,6 +5,7 @@ */ package org.archicontribs.modelrepository.views.history; +import org.archicontribs.modelrepository.IModelRepositoryImages; import org.archicontribs.modelrepository.ModelRepositoryPlugin; import org.archicontribs.modelrepository.actions.ExtractModelFromCommitAction; import org.archicontribs.modelrepository.actions.ResetToRemoteCommitAction; @@ -19,6 +20,7 @@ import org.eclipse.help.HelpSystem; import org.eclipse.help.IContext; import org.eclipse.help.IContextProvider; +import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; @@ -45,7 +47,9 @@ import org.eclipse.ui.part.IContributedContentsView; import org.eclipse.ui.part.ViewPart; +import com.archimatetool.editor.ui.ArchiLabelProvider; import com.archimatetool.model.IArchimateModel; +import com.archimatetool.model.IArchimateModelObject; /** @@ -73,12 +77,14 @@ public class HistoryView private RestoreCommitAction fActionRestoreCommit; private UndoLastCommitAction fActionUndoLastCommit; private ResetToRemoteCommitAction fActionResetToRemoteCommit; - + private Action fActionToggleObjectFilter; /* - * Selected repository + * Selected repository, model-object and filtering toggle */ private IArchiRepository fSelectedRepository; + private IArchimateModelObject fSelectedModelObject; + private boolean fModelObjectFiltered = false; @Override @@ -195,9 +201,7 @@ private void makeActions() { fActionResetToRemoteCommit = new ResetToRemoteCommitAction(getViewSite().getWorkbenchWindow()); fActionResetToRemoteCommit.setEnabled(false); - // Register the Keybinding for actions -// IHandlerService service = (IHandlerService)getViewSite().getService(IHandlerService.class); -// service.activateHandler(fActionRefresh.getActionDefinitionId(), new ActionHandler(fActionRefresh)); + fActionToggleObjectFilter = new ToggleObjectFilter("Link Selected Object", Action.AS_CHECK_BOX); } /** @@ -219,23 +223,6 @@ public void menuAboutToShow(IMenuManager manager) { getSite().registerContextMenu(menuMgr, getHistoryViewer()); } - - /** - * Make Any Local Bar Menu Actions - */ -// protected void makeLocalMenuActions() { -// IActionBars actionBars = getViewSite().getActionBars(); -// -// // Local menu items go here -// IMenuManager manager = actionBars.getMenuManager(); -// manager.add(new Action("&View Management...") { -// public void run() { -// MessageDialog.openInformation(getViewSite().getShell(), -// "View Management", -// "This is a placeholder for the View Management Dialog"); -// } -// }); -// } /** * Make Local Toolbar items @@ -251,8 +238,9 @@ protected void makeLocalToolBarActions() { manager.add(new Separator()); manager.add(fActionUndoLastCommit); manager.add(fActionResetToRemoteCommit); - manager.add(new Separator()); + manager.add(fActionToggleObjectFilter); + manager.add(new Separator()); } /** @@ -309,39 +297,39 @@ public void setFocus() { } @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if(part == null || part == this || selection == null) { - return; - } - - Object selected = ((IStructuredSelection)selection).getFirstElement(); + public void selectionChanged(IWorkbenchPart iPart, ISelection iSelection) { + + if (iPart == null || iSelection == null) + return; + if (iPart == this) + return; + IArchiRepository selectedRepository = null; + IArchimateModelObject selectedObject = null; + Object selected = ((IStructuredSelection)iSelection).getFirstElement(); + // Repository selected if(selected instanceof IArchiRepository) { selectedRepository = (IArchiRepository)selected; - } + } // Model selected, but is it in a git repo? else { - IArchimateModel model = part.getAdapter(IArchimateModel.class); + IArchimateModel model = iPart.getAdapter(IArchimateModel.class); if(GraficoUtils.isModelInLocalRepository(model)) { selectedRepository = new ArchiRepository(GraficoUtils.getLocalRepositoryFolderForModel(model)); } + + if (selected != null && selected instanceof IArchimateModelObject) + selectedObject = (IArchimateModelObject) selected; } - // Update if selectedRepository is different - if(selectedRepository != null && !selectedRepository.equals(fSelectedRepository)) { - // Store last selected - fSelectedRepository = selectedRepository; - - // Set label text - fRepoLabel.setText(Messages.HistoryView_0 + " " + selectedRepository.getName()); //$NON-NLS-1$ - - // Set History first - getHistoryViewer().doSetInput(selectedRepository); - - // Set Branches + + if (selectedRepository != null && selectedRepository != fSelectedRepository) { + fSelectedRepository = selectedRepository; + + // Set Branches getBranchesViewer().doSetInput(selectedRepository); // Update actions @@ -350,25 +338,51 @@ public void selectionChanged(IWorkbenchPart part, ISelection selection) { fActionUndoLastCommit.setRepository(selectedRepository); fActionResetToRemoteCommit.setRepository(selectedRepository); } + + if (selectedObject != null && selectedObject != fSelectedModelObject) + fSelectedModelObject = selectedObject; + + if (fSelectedRepository != null) // no distinct repo selected yet + setSelectedRepoAndObject(); } - @Override + private void setSelectedRepoAndObject() { + if (fModelObjectFiltered) + getHistoryViewer().doSetInput(fSelectedRepository, fSelectedModelObject); + else + getHistoryViewer().doSetInput(fSelectedRepository); + updateLabel(); + } + + private void updateLabel() { + String objectLabel = ArchiLabelProvider.INSTANCE.getLabelNormalised(fSelectedModelObject); + + String label = Messages.HistoryView_0 + + " " + fSelectedRepository.getName(); + + if (fModelObjectFiltered && objectLabel.length() > 0) + label += " (" + objectLabel+ ")"; //$NON-NLS-1$ + + fRepoLabel.setText(label); + } + + @Override public void repositoryChanged(String eventName, IArchiRepository repository) { if(repository.equals(fSelectedRepository)) { switch(eventName) { case IRepositoryListener.HISTORY_CHANGED: - fRepoLabel.setText(Messages.HistoryView_0 + " " + repository.getName()); //$NON-NLS-1$ + updateLabel(); getHistoryViewer().setInput(repository); break; case IRepositoryListener.REPOSITORY_DELETED: - fRepoLabel.setText(Messages.HistoryView_0); - getHistoryViewer().setInput(""); //$NON-NLS-1$ + updateLabel(); + getHistoryViewer().setInput(""); //$NON-NLS-1$ fSelectedRepository = null; // Reset this break; case IRepositoryListener.REPOSITORY_CHANGED: - fRepoLabel.setText(Messages.HistoryView_0 + " " + repository.getName()); //$NON-NLS-1$ + updateLabel(); break; case IRepositoryListener.BRANCHES_CHANGED: @@ -415,4 +429,18 @@ public IContext getContext(Object target) { public String getSearchExpression(Object target) { return Messages.HistoryView_1; } + + private final class ToggleObjectFilter extends Action { + private ToggleObjectFilter(String text, int style) { + super(text, style); + super.setImageDescriptor(IModelRepositoryImages.ImageFactory.getImageDescriptor(IModelRepositoryImages.ICON_SYNCED)); + } + + @Override + public void run() { + fModelObjectFiltered = this.isChecked(); + setSelectedRepoAndObject(); + } + } + }