Skip to content
Snippets Groups Projects
Commit 1d9c9958 authored by al.schwinn's avatar al.schwinn
Browse files

merged release branch into gsi

parents 386d3f7e 955d5b4a
No related branches found
No related tags found
No related merge requests found
// Copyright 2016 CERN and GSI
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cern.silecs.utils;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.part.FileEditorInput;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import cern.silecs.activator.Activator;
import cern.silecs.control.core.DeployProjectNature;
import cern.silecs.control.core.DesignProjectNature;
import cern.silecs.model.exception.SilecsException;
import cern.silecs.view.console.ConsoleHandler;
import cern.silecs.view.preferences.MainPreferencePage;
public class SilecsUtils {
public static final String CLASS_VERSION_MATCHER = "version";
static public String userName;
static public boolean isWindows = false;
static {
String system = System.getProperty("os.name");
isWindows = system.toLowerCase().contains("win");
userName = System.getProperty("user.name");
}
public static String findInBundle(String resourceToLocate) {
try {
URL fileURL = FileLocator.find(Platform.getBundle(Activator.PLUGIN_ID), new Path(resourceToLocate), null);
fileURL = FileLocator.toFileURL(fileURL);
if(isWindows)
return fileURL.getPath().toString().substring(1);
return fileURL.getPath().toString();
} catch (Exception e1) {
e1.printStackTrace();
}
return null;
}
public static String getSilecsDesignFilePath(String workspacePath, String projectName) {
return workspacePath + "/" + projectName + "/" + getSilecsDesignFilePathRelative(projectName);
}
public static String getSilecsDeployFilePath(String workspacePath, String projectName) {
return workspacePath + "/" + projectName + "/" + getSilecsDeployFilePathRelative(projectName);
}
public static String getSilecsDesignFilePathRelative(String projectName) {
return "/src/" + projectName + "." + SilecsConstants.IEDESIGN_FILE;
}
public static String getSilecsDeployFilePathRelative(String projectName){
return "/src/" + projectName + "." + SilecsConstants.IEDEPLOY_FILE;
}
public static Boolean isSilecsDesign(String filePath)
{
String extension = "";
int i = filePath.lastIndexOf('.');
if (i > 0)
extension = filePath.substring(i+1);
if(extension.equals(SilecsConstants.IEDESIGN_FILE) )
return true;
return false;
}
public static Boolean isSilecsDeploy(String filePath)
{
String extension = "";
int i = filePath.lastIndexOf('.');
if (i > 0)
extension = filePath.substring(i+1);
if(extension.equals(SilecsConstants.IEDEPLOY_FILE) )
return true;
return false;
}
public static IFile getSilecsDesignFile(IProject project) {
return project.getFile(getSilecsDesignFilePathRelative(project.getName()));
}
public static IFile getSilecsDeployFile(IProject project) {
return project.getFile(getSilecsDeployFilePathRelative(project.getName()));
}
public static IFile getSilecsDocument(IProject project) throws Exception
{
if ( project.hasNature(DesignProjectNature.NATURE_ID) )
{
return SilecsUtils.getSilecsDesignFile(project);
}
else if( project.hasNature(DeployProjectNature.NATURE_ID) )
{
return SilecsUtils.getSilecsDeployFile(project);
}
else
throw new Exception("The project: " + project.getName() + " is not a silecs-project");
}
public static String getSilecsVersion(IProject project) throws SilecsException {
String filePath = "";
try
{
if( project.hasNature(DeployProjectNature.NATURE_ID) )
{
filePath = getSilecsDeployFile(project).getRawLocation().makeAbsolute().toOSString();
}
else if( project.hasNature(DesignProjectNature.NATURE_ID) )
{
filePath = getSilecsDesignFile(project).getRawLocation().makeAbsolute().toOSString();
}
else
{
throw new SilecsException("Faild to extract project nature from: " + project.getName());
}
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(filePath);
Node root;
if( project.hasNature(DesignProjectNature.NATURE_ID) )
root = doc.getElementsByTagName("SILECS-Design").item(0);
else
root = doc.getElementsByTagName("SILECS-Deploy").item(0);
return root.getAttributes().getNamedItem("silecs-version").getTextContent();
}
catch(Exception ex)
{
ConsoleHandler.printError("Faild to extract silecs-version from: " + filePath, true);
throw new SilecsException("Faild to extract silecs-version from: " + filePath, ex);
}
}
public static String getSilecsDesignVersion(String filePath) throws SilecsException {
try
{
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(filePath);
Node classNode = doc.getElementsByTagName("SILECS-Class").item(0);
return classNode.getAttributes().getNamedItem(CLASS_VERSION_MATCHER).getNodeValue();
}
catch(Exception ex)
{
ConsoleHandler.printError("Faild to extract class-version from: " + filePath, true);
throw new SilecsException("Faild to extract class-version from: " + filePath, ex);
}
}
public static String getDeployVersion(String filePath) throws SilecsException {
try
{
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(filePath);
Node deployNode = doc.getElementsByTagName("Deploy-Unit").item(0);
return deployNode.getAttributes().getNamedItem(CLASS_VERSION_MATCHER).getNodeValue();
}
catch(Exception ex)
{
ConsoleHandler.printError("Faild to extract deploy-version from: " + filePath, true);
throw new SilecsException("Faild to extract deploy-version from: " + filePath, ex);
}
}
public static void openInEditor(final IFile file)
{
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
page.openEditor(new FileEditorInput(file), desc.getId());
} catch (Exception e) {
ConsoleHandler.printError("Failed to open file:" + file, true);
e.printStackTrace();
}
}
});
}
public static void checkSilecsVersion(IProject project) throws SilecsException
{
String version = getSilecsVersion(project);
if( isSilecsVersionSupported(version) == false )
{
throw new SilecsException("The old silecs version: '" + version + "' is not supported by this silecs-plugin. Please update your SILECS project to a more recent version (right-click --> SILECS Update Project)");
}
}
public static Boolean isSilecsVersionSupported(String version)
{
for(String supportedVersion: SilecsConstants.SUPPORTED_SILECS_MAJOR_VERSIONS)
{
if(version.startsWith(supportedVersion))
return true;
}
return false;
}
public static List<String> readOutAvailableSilecsVersions()
{
List<String> silecsVersions = new ArrayList<String>();
if (MainPreferencePage.isLocalDirectoryUsed())
{
silecsVersions.add("DEV");
return silecsVersions;
}
// We just pick any sub-project
File silecsBaseFolder = new File(MainPreferencePage.getGlobalSilecsDirectory() + "/silecs-model");
for (final File fileEntry : silecsBaseFolder.listFiles())
{
silecsVersions.add(fileEntry.getName());
}
Collections.sort(silecsVersions);
Collections.reverse(silecsVersions);
return silecsVersions;
}
public static IFile extractSilecsFileFromEvent(ExecutionEvent event) throws Exception
{
String parameter = event.getParameter("silecs-eclipse-plugin.commandParameter");
if ( parameter.equals("menubar"))
{
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage activePage = window.getActivePage();
// Get the Selection from the active WorkbenchPage page
ISelection selection = activePage.getSelection();
if(selection instanceof ITreeSelection) // Event was triggered by right-click on project
{
TreeSelection treeSelection = (TreeSelection) selection;
TreePath[] treePaths = treeSelection.getPaths();
TreePath treePath = treePaths[0];
// The first segment should be a IProject
Object firstSegmentObj = treePath.getFirstSegment();
IProject theProject = (IProject) ((IAdaptable)firstSegmentObj).getAdapter(IProject.class);
if( theProject == null )
{
ConsoleHandler.printError("Failed to find the right project", true);
throw new ExecutionException("Failed to find the right project");
}
return getSilecsDocument(theProject);
}
}
if (parameter.equals("toolbar"))
{
// The default: the toolbar button was pressed
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor == null)
{
ConsoleHandler.printError("Failed to find active SILECS editor", true);
throw new Exception("Failed to find active SILECS editor");
}
return ((IFileEditorInput) editor.getEditorInput()).getFile();
}
String message = new String("Failed to find correct silecs-project/file - command: '" + event.getCommand().getName() + "' send with parameter: '" + parameter + "'.");
ConsoleHandler.printError(message, true);
throw new Exception(message);
}
}
// Copyright 2016 CERN and GSI
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cern.silecs.view;
import java.net.URL;
import java.net.URLClassLoader;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.IWorkbenchConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.eclipse.ui.ide.IDE;
import cern.silecs.utils.OSExecute;
import cern.silecs.utils.SilecsConstants;
import cern.silecs.utils.XmlUtils;
import cern.silecs.view.console.ConsoleHandler;
/**
* In this class a lot of initialization takes place because this is the point when workbench is already created.
*/
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
private static final String PERSPECTIVE_ID = "silecs.eclipse.plugin.perspective"; //$NON-NLS-1$
@Override
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
return new ApplicationWorkbenchWindowAdvisor(configurer);
}
@Override
public String getInitialWindowPerspectiveId() {
return PERSPECTIVE_ID;
}
@Override
public void initialize(IWorkbenchConfigurer configurer) {
super.initialize(configurer);
configurer.setSaveAndRestore(true);
PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, false);
IDE.registerAdapters();
}
@Override
public IAdaptable getDefaultPageInput() {
return ResourcesPlugin.getWorkspace().getRoot();
}
}
// Copyright 2016 CERN and GSI
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cern.silecs.view;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.eclipse.ui.internal.dialogs.WorkbenchWizardElement;
import org.eclipse.ui.internal.wizards.AbstractExtensionWizardRegistry;
import org.eclipse.ui.wizards.IWizardCategory;
import org.eclipse.ui.wizards.IWizardDescriptor;
import cern.silecs.utils.SilecsConstants;
@SuppressWarnings("restriction")
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
super(configurer);
}
@Override
public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
return new ApplicationActionBarAdvisor(configurer);
}
@Override
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(700, 500));
configurer.setShowCoolBar(true);
configurer.setShowStatusLine(true);
configurer.setTitle(SilecsConstants.SILECS_NAME); //$NON-NLS-1$
configurer.setShowProgressIndicator(true);
}
@Override
public void postWindowOpen() {
super.postWindowOpen();
addChangedEditorListener();
// removing unnecessary wizards from new and import menu.
AbstractExtensionWizardRegistry wizardRegistry = (AbstractExtensionWizardRegistry) PlatformUI.getWorkbench()
.getNewWizardRegistry();
IWizardCategory[] categories = PlatformUI.getWorkbench().getNewWizardRegistry().getRootCategory()
.getCategories();
for (IWizardDescriptor wizard : getAllWizards(categories)) {
if (wizard.getCategory().getId().matches("org.eclipse.ui.Basic")) {
WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
new Object[] { wizardElement });
} else if (wizard.getCategory().getId().matches("org.eclipse.wst.xml.examples")) {
WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
new Object[] { wizardElement });
} else if (wizard.getCategory().getId().matches("org.eclipse.wst.XMLCategory")) {
WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
new Object[] { wizardElement });
} else if (wizard.getCategory().getId().matches("org.eclipse.cdt.ui.newCWizards")) {
WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
new Object[] { wizardElement });
}
}
wizardRegistry = (AbstractExtensionWizardRegistry) PlatformUI.getWorkbench().getImportWizardRegistry();
categories = PlatformUI.getWorkbench().getImportWizardRegistry().getRootCategory().getCategories();
for (IWizardDescriptor wizard : getAllWizards(categories)) {
if (wizard.getCategory().getId().matches("org.eclipse.cdt.ui.importWizardCategory")) {
WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
new Object[] { wizardElement });
} else if (wizard.getCategory().getId().matches("org.eclipse.debug.ui")) {
WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
new Object[] { wizardElement });
} else if (wizard.getCategory().getId().matches("org.eclipse.wst.XMLCategory")) {
WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
new Object[] { wizardElement });
} else if (wizard.getCategory().getId().matches("org.eclipse.team.ui.importWizards")) {
WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
new Object[] { wizardElement });
}
}
}
private IWizardDescriptor[] getAllWizards(IWizardCategory[] categories) {
List<IWizardDescriptor> results = new ArrayList<IWizardDescriptor>();
for (IWizardCategory wizardCategory : categories) {
results.addAll(Arrays.asList(wizardCategory.getWizards()));
results.addAll(Arrays.asList(getAllWizards(wizardCategory.getCategories())));
}
return results.toArray(new IWizardDescriptor[0]);
}
private void addChangedEditorListener() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
page.addPartListener(new IPartListener() {
@Override
public void partOpened(IWorkbenchPart part) {
setApplicationTitle();
}
@Override
public void partDeactivated(IWorkbenchPart part) {
setApplicationTitle();
}
@Override
public void partClosed(IWorkbenchPart part) {
setApplicationTitle();
}
@Override
public void partBroughtToTop(IWorkbenchPart part) {
setApplicationTitle();
}
@Override
public void partActivated(IWorkbenchPart part) {
setApplicationTitle();
}
private void setApplicationTitle() {
// IEditorPart editorPart = page.getActiveEditor();
// IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
//
// if (editorPart != null) {
// IFileEditorInput editorInput = (IFileEditorInput) editorPart.getEditorInput();
// IFile file = editorInput.getFile();
//
// configurer.setTitle(file.getFullPath() + " - " + SilecsConstants.SILECS_NAME + " - "
// + ResourcesPlugin.getWorkspace());
// } else {
// configurer.setTitle(SilecsConstants.SILECS_NAME + " - " + ResourcesPlugin.getWorkspace() );
// }
}
});
}
}
// Copyright 2016 CERN and GSI
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cern.silecs.view.explorer;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.navigator.ICommonActionConstants;
import cern.silecs.control.core.DeployProjectNature;
import cern.silecs.control.core.DesignProjectNature;
import cern.silecs.utils.SilecsUtils;
/**
* This class is a subclass of CommonNavigator that provide changes concerning expanding tree.
*
* @see CommonNavigator
*/
public class SilecsProjectExplorer extends CommonNavigator {
public static final String VIEW_ID = "cern.silecs.view.explorer";
@Override
public void createPartControl(Composite aParent) {
super.createPartControl(aParent);
CommonViewer viewer = getCommonViewer();
IActionBars bars = getViewSite().getActionBars();
final IStatusLineManager lineManager = bars.getStatusLineManager();
final ILabelProvider labelProvider = (ILabelProvider) viewer.getLabelProvider();
viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection aSelection = event.getSelection();
if (aSelection != null && !aSelection.isEmpty() && aSelection instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) aSelection;
IResource file = null;
if (selection.size() == 1 && selection.getFirstElement() instanceof IProject) {
IProject project = (IProject) selection.getFirstElement();
try {
if (project.hasNature(DesignProjectNature.NATURE_ID)) {
file = SilecsUtils.getSilecsDesignFile(project);
} else if (project.hasNature(DeployProjectNature.NATURE_ID)) {
file = SilecsUtils.getSilecsDeployFile(project);
}
} catch (Exception e) {
e.printStackTrace();
}
} else if(selection.size() == 1 && selection.getFirstElement() instanceof IFile) {
file = (IFile) selection.getFirstElement();
}
if(file != null) {
Image img = null;
img = labelProvider.getImage(((IStructuredSelection) aSelection).getFirstElement());
long modificationTime = file.getLocalTimeStamp() / 1000;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY HH:mm:ss");
LocalDateTime dateAndTime = LocalDateTime.ofEpochSecond(modificationTime, 0, ZoneOffset.ofHours(2));
lineManager.setMessage(img,"Last modfication: " + formatter.format(dateAndTime) + " : " + file.getFullPath());
}
}
}
});
}
/**
* This method is responsible for expanding the project tree from the root to the silecs file(*.silecsdesign or
* *.silecsdeploy)
*/
@Override
protected void handleDoubleClick(DoubleClickEvent anEvent) {
IStructuredSelection selection = (IStructuredSelection) anEvent.getSelection();
Object element = selection.getFirstElement();
if (element instanceof IProject && !((IProject) element).isOpen()) {
try {
((IProject) element).open(new NullProgressMonitor());
} catch (CoreException e) {
e.printStackTrace();
}
return;
} else if (element instanceof IProject && ((IProject) element).isOpen()) {
List<IProject> projectList = new ArrayList<IProject>();
projectList.add((IProject) element);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
expandHelper(root, projectList);
return;
}
super.handleDoubleClick(anEvent);
}
/**
* This method expands elements in the tree. Since the tool does not have knowledge about project structure it must
* be done recursively.
*
* @param root {@link WorkspaceRoot}
* @param projects List of projects that need to be expanded
*/
public void expandHelper(IWorkspaceRoot root, List<IProject> projects) {
for (IProject project : projects) {
if (project.isOpen()) {
try {
IFile file = null;
if (project.hasNature(DeployProjectNature.NATURE_ID)) {
file = SilecsUtils.getSilecsDeployFile(project);
} else if (project.hasNature(DesignProjectNature.NATURE_ID)) {
file = SilecsUtils.getSilecsDesignFile(project);
}
if (file == null)
continue;
IContainer parent = file.getParent();
List<Object> toExpand = new ArrayList<>();
do {
toExpand.add(0, parent);
} while ((parent = parent.getParent()) != root);
boolean expand = !getCommonViewer().getExpandedState(project);
for(Object o: toExpand )
expand(o, expand);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
/**
* Expands single element in the viewer
*
* @param element
* @return true if expanded
*/
private boolean expand(Object element, boolean expand) {
IAction openHandler = getViewSite().getActionBars().getGlobalActionHandler(ICommonActionConstants.OPEN);
if (openHandler == null) {
TreeViewer viewer = getCommonViewer();
if (viewer.isExpandable(element)) {
viewer.setExpandedState(element, expand);
return true;
}
}
return false;
}
}
/snap7-full* snap7-full/
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment